add common method for getting max allowed instances of vfModule + UT
[vid.git] / vid-webpack-master / src / app / shared / utils / util.spec.ts
1 import {Utils} from "./utils";
2 import each from "jest-each";
3
4
5 describe('Util', () => {
6
7   test('hasContents should return false if object is undefined or null or empty', () => {
8     expect(Utils.hasContents(undefined)).toBeFalsy();
9     expect(Utils.hasContents(null)).toBeFalsy();
10     expect(Utils.hasContents("")).toBeFalsy();
11   });
12
13   test('hasContents should return true if object is not undefined and not null and not empty', () => {
14     expect(Utils.hasContents("someValue")).toBeTruthy();
15   });
16
17   const instantiationTypesDataProvider = [
18     ['Macro', false ],
19     ['ALaCarte', true ],
20     ['ClientConfig', true],
21     ['dont know', true]
22   ];
23   each(instantiationTypesDataProvider).test('instantiationType %s isALaCarte shall be %s', (instantiationType, expected ) => {
24     expect(Utils.isALaCarte(instantiationType)).toEqual(expected);
25   });
26
27   each([
28     ["empty properties, empty flags",{}, {}, 1],
29     ["null properties, undefined flags",null, undefined, 1],
30     ["max_instances 3, flag is on", {max_instances:3}, {FLAG_2002_UNLIMITED_MAX: true}, 3],
31     ["max_instances 3, flag is off", {max_instances:3}, {FLAG_2002_UNLIMITED_MAX: false}, 3],
32     ["null properties, flag is on", null, {FLAG_2002_UNLIMITED_MAX: true}, null],
33     ["null properties, flag is off", null, {FLAG_2002_UNLIMITED_MAX: false}, 1],
34     ["undefined properties, flag is off", undefined, {FLAG_2002_UNLIMITED_MAX: false}, 1],
35   ]).test('getMaxFirstLevel %s', (desc, properties, flags, expected) => {
36     expect(Utils.getMaxFirstLevel(properties, flags)).toEqual(expected);
37   });
38
39   each([
40     ["empty properties, empty flags",{}, {}, 1],
41     ["null properties, undefined flags",null, undefined, 1],
42     ["wrong field, flag is on", {max_instances:3}, {FLAG_2002_UNLIMITED_MAX: true}, null],
43     ["maxCountInstances 3, flag is on", {maxCountInstances:3}, {FLAG_2002_UNLIMITED_MAX: true}, 3],
44     ["maxCountInstances 3, flag is off", {maxCountInstances:3}, {FLAG_2002_UNLIMITED_MAX: true}, 3],
45   ]).test('getMaxFirstLevel %s', (desc, properties, flags, expected) => {
46     expect(Utils.getMaxVfModule(properties, flags)).toEqual(expected);
47   });
48
49
50
51 });