blob: fd04806edd3e9599feacce93bc25d3a0cb8a0fb4 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {assert} from 'chai';
6import {valuesForField, valueForField, fieldDefsWithGroup, fieldValueMapKey,
7 fieldDefsWithoutGroup, HARDCODED_FIELD_GROUPS} from './metadata-helpers.js';
8
9const fieldDefs = [
10 {
11 fieldRef: {
12 fieldName: 'Ignore',
13 fieldId: 1,
14 },
15 },
16 {
17 fieldRef: {
18 fieldName: 'DesignDoc',
19 fieldId: 2,
20 },
21 },
22];
23const fieldGroups = HARDCODED_FIELD_GROUPS;
24
25const fieldValueMap = new Map([
26 ['field', ['one', 'two', 'three']],
27 ['field-two phase', ['four']],
28 ['field-three', ['five']],
29]);
30
31describe('metadata-helpers', () => {
32 it('valuesForField', () => {
33 assert.deepEqual(valuesForField(fieldValueMap, 'Field-None'), []);
34 assert.deepEqual(valuesForField(fieldValueMap, 'Field'),
35 ['one', 'two', 'three']);
36 assert.deepEqual(valuesForField(fieldValueMap, 'Field-Two', 'Phase'),
37 ['four']);
38 assert.deepEqual(valuesForField(fieldValueMap, 'Field-Three'), ['five']);
39 });
40
41 it('valueForField', () => {
42 assert.equal(valueForField(fieldValueMap, 'Field-None'),
43 undefined);
44 assert.equal(valueForField(fieldValueMap, 'Field-Two', 'Phase'), 'four');
45 assert.equal(valueForField(fieldValueMap, 'Field-Three'), 'five');
46 });
47
48 it('fieldValueMapKey', () => {
49 assert.equal(fieldValueMapKey('test', 'two'), 'test two');
50
51 assert.equal(fieldValueMapKey('noPhase'), 'nophase');
52 });
53
54 it('fieldDefsWithoutGroup ignores non applicable types', () => {
55 assert.deepEqual(fieldDefsWithoutGroup(
56 fieldDefs, fieldGroups, 'ungrouped-type'), fieldDefs);
57 });
58
59 it('fieldDefsWithoutGroup filters grouped fields', () => {
60 assert.deepEqual(fieldDefsWithoutGroup(
61 fieldDefs, fieldGroups, 'flt-launch'), [
62 {
63 fieldRef: {
64 fieldName: 'Ignore',
65 fieldId: 1,
66 },
67 },
68 ]);
69 });
70
71 it('fieldDefsWithGroup filters by type', () => {
72 const filteredGroupsList = [{
73 groupName: 'Docs',
74 fieldDefs: [
75 {
76 fieldRef: {
77 fieldName: 'DesignDoc',
78 fieldId: 2,
79 },
80 },
81 ],
82 }];
83
84 assert.deepEqual(
85 fieldDefsWithGroup(fieldDefs, fieldGroups, 'Not-FLT-Launch'), []);
86
87 assert.deepEqual(fieldDefsWithGroup(fieldDefs, fieldGroups, 'flt-launch'),
88 filteredGroupsList);
89
90 assert.deepEqual(fieldDefsWithGroup(fieldDefs, fieldGroups, 'FLT-LAUNCH'),
91 filteredGroupsList);
92 });
93});