Welcome to mirror list, hosted at ThFree Co, Russian Federation.

table_utility_spec.js « utils « lib « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0ceccbe4c745e704d7223925009c6d0360abb8fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { DEFAULT_TH_CLASSES } from '~/lib/utils/constants';
import * as tableUtils from '~/lib/utils/table_utility';

describe('table_utility', () => {
  describe('thWidthClass', () => {
    it('returns the width class including default table header classes', () => {
      const width = 50;
      expect(tableUtils.thWidthClass(width)).toBe(`gl-w-${width}p ${DEFAULT_TH_CLASSES}`);
    });
  });

  describe('sortObjectToString', () => {
    it('returns the expected sorting string ending in "DESC" when sortDesc is true', () => {
      expect(tableUtils.sortObjectToString({ sortBy: 'mergedAt', sortDesc: true })).toBe(
        'MERGED_AT_DESC',
      );
    });

    it('returns the expected sorting string ending in "ASC" when sortDesc is false', () => {
      expect(tableUtils.sortObjectToString({ sortBy: 'mergedAt', sortDesc: false })).toBe(
        'MERGED_AT_ASC',
      );
    });
  });

  describe('sortStringToObject', () => {
    it.each`
      sortBy        | sortDesc | sortString
      ${'mergedAt'} | ${true}  | ${'MERGED_AT_DESC'}
      ${'mergedAt'} | ${false} | ${'MERGED_AT_ASC'}
      ${'severity'} | ${true}  | ${'SEVERITY_DESC'}
      ${'severity'} | ${false} | ${'SEVERITY_ASC'}
      ${null}       | ${null}  | ${'SEVERITY'}
      ${null}       | ${null}  | ${''}
    `(
      'returns the expected sort object when the sort string is "$sortString"',
      ({ sortBy, sortDesc, sortString }) => {
        expect(tableUtils.sortStringToObject(sortString)).toStrictEqual({ sortBy, sortDesc });
      },
    );
  });
});