|
| 1 | +import { DataGenerator } from '../js/testUtils'; |
| 2 | +import { ViewBasedJSONModel } from '../../js/core/viewbasedjsonmodel'; |
| 3 | +import { ArrayUtils } from '../../js/utils'; |
| 4 | + |
| 5 | +describe('Test multi index array utilities', () => { |
| 6 | + const testData = DataGenerator.multiIndexCol( |
| 7 | + { |
| 8 | + data: [ |
| 9 | + { |
| 10 | + name: "('year', '')", |
| 11 | + type: 'number', |
| 12 | + data: [2013, 2013, 2014, 2014], |
| 13 | + }, |
| 14 | + { name: "('visit', '')", type: 'number', data: [1, 2, 1, 2] }, |
| 15 | + { |
| 16 | + name: "('Bob', 'HR')", |
| 17 | + type: 'number', |
| 18 | + data: [41.0, 28.0, 42.0, 37.0], |
| 19 | + }, |
| 20 | + { |
| 21 | + name: "('Bob', 'Temp')", |
| 22 | + type: 'number', |
| 23 | + data: [37.1, 35.2, 37.3, 39.2], |
| 24 | + }, |
| 25 | + { |
| 26 | + name: "('Guido', 'HR')", |
| 27 | + type: 'number', |
| 28 | + data: [50.0, 35.0, 42.0, 31.0], |
| 29 | + }, |
| 30 | + { |
| 31 | + name: "('Guido', 'Temp')", |
| 32 | + type: 'number', |
| 33 | + data: [37.7, 37.1, 37.4, 35.1], |
| 34 | + }, |
| 35 | + { |
| 36 | + name: "('Sue', 'HR')", |
| 37 | + type: 'number', |
| 38 | + data: [23.0, 48.0, 44.0, 34.0], |
| 39 | + }, |
| 40 | + { |
| 41 | + name: "('Sue', 'Temp')", |
| 42 | + type: 'number', |
| 43 | + data: [37.5, 37.1, 37.5, 39.0], |
| 44 | + }, |
| 45 | + { name: "('ipydguuid', '')", type: 'number', data: [0, 1, 2, 3] }, |
| 46 | + ], |
| 47 | + length: 4, |
| 48 | + primaryKeyData: ["('year', '')", "('visit', '')", "('ipydguuid', '')"], |
| 49 | + }, |
| 50 | + "('ipydguuid', '')", |
| 51 | + ); |
| 52 | + |
| 53 | + // Creating a model |
| 54 | + const testModel = new ViewBasedJSONModel(testData.data); |
| 55 | + // Generating an array with location of nested level headers |
| 56 | + const mutltiIndexArrayLocations = |
| 57 | + ArrayUtils.generateMultiIndexArrayLocations(testModel); |
| 58 | + |
| 59 | + test('Test .generateMultiIndexArrayLocations()', async () => { |
| 60 | + expect(mutltiIndexArrayLocations).toEqual([2, 3, 4, 5, 6, 7]); |
| 61 | + }); |
| 62 | + |
| 63 | + // Generating an array with location of nested level headers |
| 64 | + const nestedColumnDataGridIndices = ArrayUtils.generateColMergedCellLocations( |
| 65 | + testModel, |
| 66 | + mutltiIndexArrayLocations, |
| 67 | + ); |
| 68 | + |
| 69 | + test('Test .generateColMergedCellLocations()', async () => { |
| 70 | + expect(nestedColumnDataGridIndices).toEqual([ |
| 71 | + [ |
| 72 | + [ |
| 73 | + [0, 0], |
| 74 | + [0, 1], |
| 75 | + ], |
| 76 | + [ |
| 77 | + [0, 2], |
| 78 | + [0, 3], |
| 79 | + ], |
| 80 | + [ |
| 81 | + [0, 4], |
| 82 | + [0, 5], |
| 83 | + ], |
| 84 | + ], |
| 85 | + [[[1, 0]], [[1, 1]], [[1, 2]], [[1, 3]], [[1, 4]], [[1, 5]]], |
| 86 | + ]); |
| 87 | + }); |
| 88 | + |
| 89 | + test('Test .validateMergingHierarchy() for nested columns', async () => { |
| 90 | + expect( |
| 91 | + ArrayUtils.validateMergingHierarchy(nestedColumnDataGridIndices), |
| 92 | + ).toBe(true); |
| 93 | + }); |
| 94 | + |
| 95 | + test('Test .generateColumnCellGroups()', async () => { |
| 96 | + const expected = [ |
| 97 | + { r1: 0, c1: 0, r2: 0, c2: 1 }, |
| 98 | + { r1: 0, c1: 2, r2: 0, c2: 3 }, |
| 99 | + { r1: 0, c1: 4, r2: 0, c2: 5 }, |
| 100 | + ]; |
| 101 | + |
| 102 | + const actual = ArrayUtils.generateColumnCellGroups( |
| 103 | + nestedColumnDataGridIndices, |
| 104 | + ); |
| 105 | + expect(actual).toEqual(expected); |
| 106 | + }); |
| 107 | +}); |
0 commit comments