Skip to content

Commit d380713

Browse files
committed
fix tests
1 parent ff5263b commit d380713

File tree

8 files changed

+120
-47
lines changed

8 files changed

+120
-47
lines changed

projects/lib/jest.config.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@ module.exports = {
77
coverageDirectory: path.resolve(__dirname, '../../coverage/lib'),
88
coverageThreshold: {
99
global: {
10-
branches: 67,
10+
branches: 90,
1111
functions: 95,
12-
lines: 91,
13-
statements: -16,
12+
lines: 95,
13+
statements: -3,
1414
},
1515
},
1616
moduleNameMapper: {
17-
'^@platform-mesh/portal-ui-lib$': '<rootDir>/projects/lib/public-api.ts',
18-
'^@platform-mesh/portal-ui-lib/services$': '<rootDir>/projects/lib/services/public-api.ts',
19-
'^@platform-mesh/portal-ui-lib/utils$': '<rootDir>/projects/lib/utils/public-api.ts',
20-
'^@platform-mesh/portal-ui-lib/(.*)': '<rootDir>/projects/lib/$1',
17+
'^@platform-mesh/portal-ui-lib$': path.resolve(
18+
__dirname,
19+
'./public-api.ts',
20+
),
21+
'^@platform-mesh/portal-ui-lib/services$': path.resolve(
22+
__dirname,
23+
'./services/public-api.ts',
24+
),
25+
'^@platform-mesh/portal-ui-lib/utils$': path.resolve(
26+
__dirname,
27+
'./utils/public-api.ts',
28+
),
29+
'^@platform-mesh/portal-ui-lib/(.*)': path.resolve(__dirname, './$1'),
2130
},
2231
};

projects/lib/ng-package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
"dest": "../../dist",
44
"lib": {
55
"entryFile": "./public-api.ts"
6-
},
7-
"allowedNonPeerDependencies": [
8-
"@openmfp/portal-ui-lib"
9-
]
6+
}
107
}

projects/lib/portal-options/public-api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ export * from './services/luigi-extended-global-context-config.service';
44
export * from './services/node-change-hook-config.service';
55
export * from './services/node-context-processing.service';
66
export * from './services/user-profile-config.service';
7-
export * from './services/user-profile-config.service'

projects/lib/portal-options/services/crd-gateway-kcp-patch-resolver.service.spec.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { TestBed } from '@angular/core/testing';
2-
import {
3-
EnvConfigService
4-
} from '@openmfp/portal-ui-lib';
5-
import { GatewayService } from '@platform-mesh/portal-ui-lib/services/resource';
61
import { kcpRootOrgsPath } from '../models/constants';
72
import { PortalLuigiNode } from '../models/luigi-node';
83
import { CrdGatewayKcpPatchResolver } from './crd-gateway-kcp-patch-resolver.service';
4+
import { TestBed } from '@angular/core/testing';
5+
import { EnvConfigService } from '@openmfp/portal-ui-lib';
6+
import { GatewayService } from '@platform-mesh/portal-ui-lib/services/resource';
97

108
describe('CrdGatewayKcpPatchResolver', () => {
119
let resolver: CrdGatewayKcpPatchResolver;
@@ -15,7 +13,7 @@ describe('CrdGatewayKcpPatchResolver', () => {
1513
beforeEach(() => {
1614
gatewayServiceMock = { updateCrdGatewayUrlWithEntityPath: jest.fn() };
1715
envConfigServiceMock = {
18-
getEnvConfig: jest.fn().mockResolvedValue({ organization: 'org1' }),
16+
getEnvConfig: jest.fn().mockResolvedValue({ idpName: 'org1' }),
1917
} as any;
2018

2119
TestBed.configureTestingModule({
@@ -88,40 +86,56 @@ describe('CrdGatewayKcpPatchResolver', () => {
8886

8987
describe('resolveCrdGatewayKcpPathForNextAccountEntity', () => {
9088
it('should return early if kind is not Account', async () => {
91-
const nextNode: PortalLuigiNode = { context: {}, parent: undefined } as any;
89+
const nextNode: PortalLuigiNode = {
90+
context: {},
91+
parent: undefined,
92+
} as any;
9293

9394
await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
9495
'leafAcc',
9596
'Project',
9697
nextNode,
9798
);
9899

99-
expect(gatewayServiceMock.updateCrdGatewayUrlWithEntityPath).not.toHaveBeenCalled();
100+
expect(
101+
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
102+
).not.toHaveBeenCalled();
100103
expect(envConfigServiceMock.getEnvConfig).not.toHaveBeenCalled();
101104
});
102105

103106
it('should return early if entityId is empty', async () => {
104-
const nextNode: PortalLuigiNode = { context: {}, parent: undefined } as any;
107+
const nextNode: PortalLuigiNode = {
108+
context: {},
109+
parent: undefined,
110+
} as any;
105111

106112
await resolver.resolveCrdGatewayKcpPathForNextAccountEntity(
107113
'',
108114
'Account',
109115
nextNode,
110116
);
111117

112-
expect(gatewayServiceMock.updateCrdGatewayUrlWithEntityPath).not.toHaveBeenCalled();
118+
expect(
119+
gatewayServiceMock.updateCrdGatewayUrlWithEntityPath,
120+
).not.toHaveBeenCalled();
113121
expect(envConfigServiceMock.getEnvConfig).not.toHaveBeenCalled();
114122
});
115123

116124
it('should aggregate parent Account entities and append entityId', async () => {
117125
const nextNode: PortalLuigiNode = {
118126
context: {},
119127
parent: {
120-
context: { entity: { metadata: { name: 'acc2' }, __typename: 'Account' } },
128+
context: {
129+
entity: { metadata: { name: 'acc2' }, __typename: 'Account' },
130+
},
121131
parent: {
122-
context: { entity: { metadata: { name: 'team1' }, __typename: 'Team' } },
132+
context: {
133+
entity: { metadata: { name: 'team1' }, __typename: 'Team' },
134+
},
123135
parent: {
124-
context: { entity: { metadata: { name: 'acc1' }, __typename: 'Account' } },
136+
context: {
137+
entity: { metadata: { name: 'acc1' }, __typename: 'Account' },
138+
},
125139
parent: undefined,
126140
},
127141
},
@@ -144,7 +158,9 @@ describe('CrdGatewayKcpPatchResolver', () => {
144158
const nextNode: PortalLuigiNode = {
145159
context: { kcpPath: 'overridePath' },
146160
parent: {
147-
context: { entity: { metadata: { name: 'accParent' }, __typename: 'Account' } },
161+
context: {
162+
entity: { metadata: { name: 'accParent' }, __typename: 'Account' },
163+
},
148164
parent: undefined,
149165
},
150166
} as any;

projects/lib/portal-options/services/luigi-extended-global-context-config.service.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { LuigiExtendedGlobalContextConfigServiceImpl } from './luigi-extended-global-context-config.service';
12
import { TestBed } from '@angular/core/testing';
23
import {
34
AuthService,
@@ -6,7 +7,6 @@ import {
67
} from '@openmfp/portal-ui-lib';
78
import { ResourceService } from '@platform-mesh/portal-ui-lib/services';
89
import { of, throwError } from 'rxjs';
9-
import { LuigiExtendedGlobalContextConfigServiceImpl } from './luigi-extended-global-context-config.service';
1010

1111
describe('LuigiExtendedGlobalContextConfigServiceImpl', () => {
1212
let service: LuigiExtendedGlobalContextConfigServiceImpl;
@@ -62,7 +62,7 @@ describe('LuigiExtendedGlobalContextConfigServiceImpl', () => {
6262
},
6363
} as any;
6464
const mockEnvConfig = {
65-
organization: 'test-org',
65+
idpName: 'test-org',
6666
} as any;
6767
const mockResource = {
6868
metadata: {
@@ -103,7 +103,7 @@ describe('LuigiExtendedGlobalContextConfigServiceImpl', () => {
103103
},
104104
} as any;
105105
const mockEnvConfig = {
106-
organization: 'test-org',
106+
idpName: 'test-org',
107107
} as any;
108108
const mockResource = {
109109
metadata: {},
@@ -135,7 +135,7 @@ describe('LuigiExtendedGlobalContextConfigServiceImpl', () => {
135135
},
136136
} as any;
137137
const mockEnvConfig = {
138-
organization: 'test-org',
138+
idpName: 'test-org',
139139
} as any;
140140
const mockToken = 'mock-token';
141141

projects/wc/jest.config.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ module.exports = {
55
roots: [__dirname],
66
testMatch: ['**/*.spec.ts'],
77
coverageDirectory: path.resolve(__dirname, '../../coverage/wc'),
8-
collectCoverageFrom: [
9-
'!<rootDir>/projects/wc/**/*.spec.ts',
10-
],
8+
collectCoverageFrom: ['!<rootDir>/projects/wc/**/*.spec.ts'],
119
coveragePathIgnorePatterns: [
1210
'<rootDir>/projects/lib/',
1311
'<rootDir>/projects/wc/src/main.ts',
@@ -19,16 +17,25 @@ module.exports = {
1917
coverageThreshold: {
2018
global: {
2119
branches: 85,
22-
functions: 80,
23-
lines: 94,
24-
statements: -8,
20+
functions: 95,
21+
lines: 95,
22+
statements: -5,
2523
},
2624
},
2725
moduleNameMapper: {
2826
'^lodash-es(.*)': 'lodash',
29-
'^@platform-mesh/portal-ui-lib$': '<rootDir>/projects/lib/public-api.ts',
30-
'^@platform-mesh/portal-ui-lib/services$': '<rootDir>/projects/lib/services/public-api.ts',
31-
'^@platform-mesh/portal-ui-lib/utils$': '<rootDir>/projects/lib/utils/public-api.ts',
32-
'^@platform-mesh/portal-ui-lib/(.*)': '<rootDir>/projects/lib/$1',
27+
'^@platform-mesh/portal-ui-lib$': path.resolve(
28+
__dirname,
29+
'../lib/public-api.ts',
30+
),
31+
'^@platform-mesh/portal-ui-lib/services$': path.resolve(
32+
__dirname,
33+
'../lib/services/public-api.ts',
34+
),
35+
'^@platform-mesh/portal-ui-lib/utils$': path.resolve(
36+
__dirname,
37+
'../lib/utils/public-api.ts',
38+
),
39+
'^@platform-mesh/portal-ui-lib/(.*)': path.resolve(__dirname, '../lib/$1'),
3340
},
3441
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { WelcomeComponent } from './welcome.component';
2+
import { signal } from '@angular/core';
3+
import { TestBed } from '@angular/core/testing';
4+
import { I18nService } from '@openmfp/portal-ui-lib';
5+
6+
describe('WelcomeComponent', () => {
7+
let component: WelcomeComponent;
8+
let i18nService: jest.Mocked<I18nService>;
9+
10+
beforeEach(async () => {
11+
i18nService = {
12+
fetchTranslationFile: jest.fn(),
13+
translationTable: { hello: 'world' },
14+
} as unknown as jest.Mocked<I18nService>;
15+
16+
await TestBed.configureTestingModule({
17+
imports: [WelcomeComponent],
18+
providers: [{ provide: I18nService, useValue: i18nService }],
19+
}).compileComponents();
20+
21+
const fixture = TestBed.createComponent(WelcomeComponent);
22+
component = fixture.componentInstance;
23+
});
24+
25+
it('should create', () => {
26+
expect(component).toBeTruthy();
27+
});
28+
29+
it('should set enhancedContext on init', async () => {
30+
component.context = signal({
31+
key: 'value',
32+
}) as any;
33+
i18nService.fetchTranslationFile.mockResolvedValue({ hello: 'world' });
34+
35+
await component.ngOnInit();
36+
37+
expect(i18nService.fetchTranslationFile).toHaveBeenCalledWith('en');
38+
expect(component.enhancedContext()).toEqual({
39+
key: 'value',
40+
translationTable: { hello: 'world' },
41+
});
42+
});
43+
});

projects/wc/src/app/initializers/luigi-wc-initializer.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import {
2+
DetailViewComponent,
3+
ListViewComponent,
4+
OrganizationManagementComponent,
5+
WelcomeComponent,
6+
} from '../components';
7+
import * as wc from '../utils/wc';
8+
import { provideLuigiWebComponents } from './luigi-wc-initializer';
19
import { ApplicationInitStatus } from '@angular/core';
210
import { TestBed } from '@angular/core/testing';
311

4-
import { DetailViewComponent } from '../components/generic-ui/detail-view/detail-view.component';
5-
import { ListViewComponent } from '../components/generic-ui/list-view/list-view.component';
6-
import { provideLuigiWebComponents } from './luigi-wc-initializer';
7-
8-
import { OrganizationManagementComponent } from '../components/organization-management/organization-management.component';
9-
import * as wc from '../utils/wc';
10-
1112
describe('provideLuigiWebComponents', () => {
1213
beforeEach(() => {
1314
TestBed.resetTestingModule();
@@ -28,6 +29,7 @@ describe('provideLuigiWebComponents', () => {
2829
'generic-list-view': ListViewComponent,
2930
'generic-detail-view': DetailViewComponent,
3031
'organization-management': OrganizationManagementComponent,
32+
'welcome-view': WelcomeComponent,
3133
} as Record<string, any>;
3234

3335
// Validate first arg equals the components map

0 commit comments

Comments
 (0)