summaryrefslogtreecommitdiff
path: root/spec/frontend/boards/boards_util_spec.js
blob: d45b6e35a45f77cea284a9adf7625a916e925ac8 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { formatIssueInput, filterVariables } from '~/boards/boards_util';

describe('formatIssueInput', () => {
  it('correctly merges boardConfig into the issue', () => {
    const boardConfig = {
      labels: [
        {
          type: 'GroupLabel',
          id: 44,
        },
      ],
      assigneeId: '55',
      milestoneId: 66,
      weight: 1,
    };

    const issueInput = {
      labelIds: ['gid://gitlab/GroupLabel/5'],
      projectPath: 'gitlab-org/gitlab-test',
      id: 'gid://gitlab/Issue/11',
    };

    const result = formatIssueInput(issueInput, boardConfig);
    expect(result).toEqual({
      projectPath: 'gitlab-org/gitlab-test',
      id: 'gid://gitlab/Issue/11',
      labelIds: ['gid://gitlab/GroupLabel/5', 'gid://gitlab/GroupLabel/44'],
      assigneeIds: ['gid://gitlab/User/55'],
      milestoneId: 'gid://gitlab/Milestone/66',
    });
  });
});

describe('filterVariables', () => {
  it.each([
    [
      'correctly processes array filter values',
      {
        filters: {
          'not[filterA]': ['val1', 'val2'],
        },
        expected: {
          not: {
            filterA: ['val1', 'val2'],
          },
        },
      },
    ],
    [
      "renames a filter if 'remap' method is available",
      {
        filters: {
          filterD: 'some value',
        },
        expected: {
          filterA: 'some value',
          not: {},
        },
      },
    ],
    [
      'correctly processes a negated filter that supports negation',
      {
        filters: {
          'not[filterA]': 'some value 1',
          'not[filterB]': 'some value 2',
        },
        expected: {
          not: {
            filterA: 'some value 1',
          },
        },
      },
    ],
    [
      'correctly removes an unsupported filter depending on issuableType',
      {
        issuableType: 'epic',
        filters: {
          filterA: 'some value 1',
          filterE: 'some value 2',
        },
        expected: {
          filterE: 'some value 2',
          not: {},
        },
      },
    ],
    [
      'applies a transform when the filter value needs to be modified',
      {
        filters: {
          filterC: 'abc',
          'not[filterC]': 'def',
        },
        expected: {
          filterC: 'ABC',
          not: {
            filterC: 'DEF',
          },
        },
      },
    ],
  ])('%s', (_, { filters, issuableType = 'issue', expected }) => {
    const result = filterVariables({
      filters,
      issuableType,
      filterInfo: {
        filterA: {
          negatedSupport: true,
        },
        filterB: {
          negatedSupport: false,
        },
        filterC: {
          negatedSupport: true,
          transform: (val) => val.toUpperCase(),
        },
        filterD: {
          remap: () => 'filterA',
        },
        filterE: {
          negatedSupport: true,
        },
      },
      filterFields: {
        issue: ['filterA', 'filterB', 'filterC', 'filterD'],
        epic: ['filterE'],
      },
    });

    expect(result).toEqual(expected);
  });
});