|
1 | 1 | /******************************************************************************** |
2 | | - * Copyright (c) 2023 Contributors to the Eclipse Foundation |
| 2 | + * Copyright (c) 2023, 2025 Contributors to the Eclipse Foundation |
3 | 3 | * |
4 | 4 | * See the NOTICE file(s) distributed with this work for additional |
5 | 5 | * information regarding copyright ownership. |
|
17 | 17 | * SPDX-License-Identifier: Apache-2.0 |
18 | 18 | ********************************************************************************/ |
19 | 19 |
|
20 | | -import { TestBed } from '@angular/core/testing'; |
| 20 | + |
| 21 | +import { SemanticDataModelInCamelCase } from '@page/parts/model/parts.model'; |
21 | 22 | import { Pagination } from '@core/model/pagination.model'; |
22 | | -import { MainAspectType } from '@page/parts/model/mainAspectType.enum'; |
23 | | -import { SemanticDataModel } from '@page/parts/model/parts.model'; |
24 | | -import { PartsAssembler } from '@shared/assembler/parts.assembler'; |
25 | 23 | import { FormatPaginationSemanticDataModelToCamelCasePipe } from '@shared/pipes/format-pagination-semantic-data-model-to-camelcase.pipe'; |
26 | | -import { MOCK_part_1, MOCK_part_2 } from '../../../mocks/services/parts-mock/partsAsPlanned/partsAsPlanned.test.model'; |
27 | 24 |
|
28 | 25 | describe('FormatPaginationSemanticDataModelToCamelCasePipe', () => { |
29 | | - let formatPaginationSemanticDataModelToCamelCasePipe: FormatPaginationSemanticDataModelToCamelCasePipe; |
| 26 | + let pipe: FormatPaginationSemanticDataModelToCamelCasePipe; |
30 | 27 |
|
31 | 28 | beforeEach(() => { |
32 | | - TestBed.configureTestingModule({ |
33 | | - providers: [ |
34 | | - FormatPaginationSemanticDataModelToCamelCasePipe, |
| 29 | + pipe = new FormatPaginationSemanticDataModelToCamelCasePipe(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should create an instance', () => { |
| 33 | + expect(pipe).toBeTruthy(); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should transform all known semanticDataModel values to camel case', () => { |
| 37 | + const input: Pagination<any> = { |
| 38 | + content: [ |
| 39 | + { semanticDataModel: 'batch' }, |
| 40 | + { semanticDataModel: 'SerialPart' }, |
| 41 | + { semanticDataModel: 'partAsPlanned' }, |
| 42 | + { semanticDataModel: 'JUSTINSEQUENCE' } |
35 | 43 | ], |
36 | | - }); |
37 | | - formatPaginationSemanticDataModelToCamelCasePipe = TestBed.inject(FormatPaginationSemanticDataModelToCamelCasePipe); |
| 44 | + page: 0, |
| 45 | + pageCount: 1, |
| 46 | + pageSize: 10, |
| 47 | + totalItems: 4 |
| 48 | + }; |
| 49 | + |
| 50 | + const result = pipe.transform(input); |
| 51 | + |
| 52 | + expect(result.content[0].semanticDataModel).toBe(SemanticDataModelInCamelCase.BATCH); |
| 53 | + expect(result.content[1].semanticDataModel).toBe(SemanticDataModelInCamelCase.SERIALPART); |
| 54 | + expect(result.content[2].semanticDataModel).toBe(SemanticDataModelInCamelCase.PARTASPLANNED); |
| 55 | + expect(result.content[3].semanticDataModel).toBe(SemanticDataModelInCamelCase.JUSTINSEQUENCE); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should convert unknown semanticDataModel values to UNKNOWN', () => { |
| 59 | + const input: Pagination<any> = { |
| 60 | + content: [{ semanticDataModel: 'undefinedModel' }], |
| 61 | + page: 1, |
| 62 | + pageCount: 1, |
| 63 | + pageSize: 5, |
| 64 | + totalItems: 1 |
| 65 | + }; |
| 66 | + |
| 67 | + const result = pipe.transform(input); |
| 68 | + |
| 69 | + expect(result.content[0].semanticDataModel).toBe(SemanticDataModelInCamelCase.UNKNOWN); |
| 70 | + }); |
| 71 | + |
| 72 | + it('should preserve non-semanticDataModel properties', () => { |
| 73 | + const input: Pagination<any> = { |
| 74 | + content: [{ semanticDataModel: 'batch', id: '123', name: 'TestPart' }], |
| 75 | + page: 0, |
| 76 | + pageCount: 1, |
| 77 | + pageSize: 1, |
| 78 | + totalItems: 1 |
| 79 | + }; |
| 80 | + |
| 81 | + const result = pipe.transform(input); |
| 82 | + |
| 83 | + expect(result.content[0].id).toBe('123'); |
| 84 | + expect(result.content[0].name).toBe('TestPart'); |
| 85 | + expect(result.content[0].semanticDataModel).toBe(SemanticDataModelInCamelCase.BATCH); |
38 | 86 | }); |
39 | 87 |
|
40 | | - [ |
41 | | - { |
42 | | - option: SemanticDataModel.BATCH, |
43 | | - expected: 'Batch', |
44 | | - }, |
45 | | - { |
46 | | - option: SemanticDataModel.SERIALPART, |
47 | | - expected: 'SerialPart', |
48 | | - }, |
49 | | - { |
50 | | - option: SemanticDataModel.PARTASPLANNED, |
51 | | - expected: 'PartAsPlanned', |
52 | | - }, |
53 | | - ].forEach(object => { |
54 | | - |
55 | | - it(`should transform semanticDataModel from ${ object.option } to ${ object.expected }`, function() { |
56 | | - |
57 | | - let partList = [ PartsAssembler.assemblePart(MOCK_part_1, MainAspectType.AS_BUILT), PartsAssembler.assemblePart(MOCK_part_2, MainAspectType.AS_BUILT) ]; |
58 | | - |
59 | | - let paginationData: Pagination<any> = { |
60 | | - page: 0, |
61 | | - pageCount: 1, |
62 | | - pageSize: 50, |
63 | | - totalItems: 1, |
64 | | - content: partList, |
65 | | - }; |
66 | | - |
67 | | - paginationData.content.forEach(part => { |
68 | | - part.semanticDataModel = object.option; |
69 | | - }); |
70 | | - |
71 | | - partList.map(part => { |
72 | | - expect(part.semanticDataModel).toEqual(object.option); |
73 | | - }); |
74 | | - |
75 | | - |
76 | | - let transformedPartData = formatPaginationSemanticDataModelToCamelCasePipe.transform(paginationData); |
77 | | - |
78 | | - transformedPartData.content.map(part => { |
79 | | - expect(part.semanticDataModel).toEqual(object.expected); |
80 | | - }); |
81 | | - |
82 | | - }); |
| 88 | + it('should return unchanged pagination metadata', () => { |
| 89 | + const input: Pagination<any> = { |
| 90 | + content: [{ semanticDataModel: 'serialpart' }], |
| 91 | + page: 2, |
| 92 | + pageCount: 5, |
| 93 | + pageSize: 10, |
| 94 | + totalItems: 50 |
| 95 | + }; |
| 96 | + |
| 97 | + const result = pipe.transform(input); |
| 98 | + |
| 99 | + expect(result.page).toBe(2); |
| 100 | + expect(result.pageCount).toBe(5); |
| 101 | + expect(result.pageSize).toBe(10); |
| 102 | + expect(result.totalItems).toBe(50); |
| 103 | + }); |
| 104 | + |
| 105 | + it('should handle empty content arrays gracefully', () => { |
| 106 | + const input: Pagination<any> = { |
| 107 | + content: [], |
| 108 | + page: 0, |
| 109 | + pageCount: 0, |
| 110 | + pageSize: 10, |
| 111 | + totalItems: 0 |
| 112 | + }; |
| 113 | + |
| 114 | + const result = pipe.transform(input); |
| 115 | + expect(result.content).toEqual([]); |
83 | 116 | }); |
84 | 117 | }); |
0 commit comments