Skip to content

Commit c5f3fae

Browse files
authored
feat: luigi static settings config api (#2)
* feat: extract luigi static settings configuration api
1 parent dc713da commit c5f3fae

16 files changed

+209
-93
lines changed

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module.exports = {
22
preset: 'jest-preset-angular',
33
testRunner: 'jest-jasmine2',
4+
moduleNameMapper: {
5+
'^lodash-es(.*)': 'lodash',
6+
},
47
collectCoverage: true,
58
coveragePathIgnorePatterns: ['/node_modules/', '/integration-tests/'],
69
};

package-lock.json

Lines changed: 37 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
"@angular/platform-browser-dynamic": "^17.3.0",
2626
"@angular/router": "^17.3.0",
2727
"@luigi-project/plugin-auth-oauth2": "2.7.5",
28+
"@luigi-project/client": "2.14.1",
29+
"@luigi-project/client-support-angular": "2.14.1",
2830
"rxjs": "~7.8.0",
2931
"tslib": "^2.3.0",
3032
"zone.js": "~0.14.3"
@@ -40,6 +42,8 @@
4042
"@angular/cli": "^17.3.8",
4143
"@angular/compiler-cli": "^17.3.0",
4244
"@briebug/jest-schematic": "^6.0.0",
45+
"@luigi-project/client": "2.14.1",
46+
"@luigi-project/client-support-angular": "2.14.1",
4347
"@openmfp/config-prettier": "0.5.0",
4448
"@openmfp/eslint-config-typescript": "0.6.0",
4549
"@types/jest": "29.5.12",

src/lib/callback/callback.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Component, ViewEncapsulation } from '@angular/core';
22
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
3-
// @ts-ignore
43
import * as url from 'url';
54
import { AuthService } from '../services';
65

src/lib/injection-tokens.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const LUIGI_STATIC_SETTINGS_CONFIG_SERVICE_INJECTION_TOKEN =
2+
'OPENMFP_LUIGI_STATIC_SETTINGS_CONFIG_SERVICE';

src/lib/portal.module.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
import { NgModule } from '@angular/core';
1+
import { NgModule, Type } from '@angular/core';
22
import { HttpClientModule } from '@angular/common/http';
33
import { BrowserModule } from '@angular/platform-browser';
44
import { RouterOutlet } from '@angular/router';
5+
import { LUIGI_STATIC_SETTINGS_CONFIG_SERVICE_INJECTION_TOKEN } from './injection-tokens';
56
import { LogoutComponent } from './logout/logout.component';
67
import { LuigiComponent } from './luigi/luigi.component';
78
import { CallbackComponent } from './callback/callback.component';
89
import { PortalRoutingModule } from './portal-routing.module';
910
import { PortalComponent } from './portal.component';
11+
import {
12+
StaticSettingsConfigService,
13+
StaticSettingsConfigServiceImpl,
14+
} from './services/luigi-config/static-settings-config.service';
15+
16+
export interface PortalModuleOptions {
17+
/** Service containing and providing the luigi settings configuration **/
18+
staticSettingsConfigService?: Type<StaticSettingsConfigService>;
19+
}
1020

1121
@NgModule({
1222
declarations: [
@@ -15,8 +25,41 @@ import { PortalComponent } from './portal.component';
1525
CallbackComponent,
1626
LogoutComponent,
1727
],
28+
providers: [
29+
{
30+
provide: LUIGI_STATIC_SETTINGS_CONFIG_SERVICE_INJECTION_TOKEN,
31+
useClass: StaticSettingsConfigServiceImpl,
32+
},
33+
],
1834
imports: [PortalRoutingModule, BrowserModule, RouterOutlet, HttpClientModule],
1935
exports: [PortalComponent],
2036
bootstrap: [PortalComponent],
2137
})
22-
export class PortalModule {}
38+
export class PortalModule {
39+
static create(options: PortalModuleOptions): NgModule {
40+
return {
41+
declarations: [
42+
LuigiComponent,
43+
PortalComponent,
44+
CallbackComponent,
45+
LogoutComponent,
46+
],
47+
providers: [
48+
{
49+
provide: LUIGI_STATIC_SETTINGS_CONFIG_SERVICE_INJECTION_TOKEN,
50+
useClass:
51+
options.staticSettingsConfigService ||
52+
StaticSettingsConfigServiceImpl,
53+
},
54+
],
55+
imports: [
56+
PortalRoutingModule,
57+
BrowserModule,
58+
RouterOutlet,
59+
HttpClientModule,
60+
],
61+
exports: [PortalComponent],
62+
bootstrap: [PortalComponent],
63+
};
64+
}
65+
}

src/lib/services/i18n.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export class I18nService {
6767
let result = this.getInternalTranslation(key, interpolations, locale);
6868
// fallback language
6969
if (!result) {
70-
// @ts-ignore
7170
if (
7271
this.translationTable &&
7372
!this.translationTable[this.fallbackLanguage]
@@ -153,7 +152,6 @@ export class I18nService {
153152
*/
154153
addTranslationFile(locale: string, data: Record<string, string>) {
155154
if (data && locale) {
156-
// @ts-ignore
157155
this.translationTable[locale] = data;
158156
}
159157
}

src/lib/services/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './auth.service';
22
export * from './luigi-core.service';
3+
export * from './luigi-config/luigi-config.service';

src/lib/services/luigi-config/auth-config.service.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { AuthConfigService } from './auth-config.service';
22
import { AuthService } from '../auth.service';
33
import { StorageService } from '../storage.service';
44
import { LuigiCoreService } from '../luigi-core.service';
5-
// @ts-ignore
65
import oAuth2 from '@luigi-project/plugin-auth-oauth2';
76

87
jest.mock('@luigi-project/plugin-auth-oauth2');

src/lib/services/luigi-config/auth-config.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Injectable } from '@angular/core';
22
import { AuthService } from '../auth.service';
3-
// @ts-ignore
43
import oAuth2 from '@luigi-project/plugin-auth-oauth2';
54
import { LuigiCoreService } from '../luigi-core.service';
65
import { StorageService } from '../storage.service';

src/lib/services/luigi-config/luigi-config.service.spec.ts

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { LuigiConfigService } from './luigi-config.service';
22
import { EnvConfigService } from '../env-config.service';
33
import { AuthConfigService } from './auth-config.service';
44
import { ClientEnvironment } from '../../model/env';
5+
import { StaticSettingsConfigService } from './static-settings-config.service';
56

67
describe('LuigiConfigService', () => {
78
let service: LuigiConfigService;
89
let envConfigServiceMock: jest.Mocked<EnvConfigService>;
910
let authConfigServiceMock: jest.Mocked<AuthConfigService>;
11+
let staticSettingsConfigServiceMock: jest.Mocked<StaticSettingsConfigService>;
1012

1113
beforeEach(() => {
1214
envConfigServiceMock = {
@@ -17,9 +19,14 @@ describe('LuigiConfigService', () => {
1719
getAuthConfig: jest.fn(),
1820
} as any;
1921

22+
staticSettingsConfigServiceMock = {
23+
getInitialStaticSettingsConfig: jest.fn(),
24+
} as any;
25+
2026
service = new LuigiConfigService(
2127
envConfigServiceMock,
22-
authConfigServiceMock
28+
authConfigServiceMock,
29+
staticSettingsConfigServiceMock
2330
);
2431
});
2532

@@ -38,12 +45,22 @@ describe('LuigiConfigService', () => {
3845
use: 'oAuth2AuthCode',
3946
} as any;
4047

48+
const mockStaticSettings = {
49+
filed: 'filed',
50+
};
51+
4152
envConfigServiceMock.getEnvConfig.mockResolvedValue(mockEnvConfig);
4253
authConfigServiceMock.getAuthConfig.mockReturnValue(mockAuthConfig);
54+
staticSettingsConfigServiceMock.getInitialStaticSettingsConfig.mockReturnValue(
55+
mockStaticSettings
56+
);
4357

4458
const config = await service.getLuigiConfiguration();
4559

4660
expect(envConfigServiceMock.getEnvConfig).toHaveBeenCalled();
61+
expect(
62+
staticSettingsConfigServiceMock.getInitialStaticSettingsConfig
63+
).toHaveBeenCalled();
4764
expect(authConfigServiceMock.getAuthConfig).toHaveBeenCalledWith(
4865
mockEnvConfig.oauthServerUrl,
4966
mockEnvConfig.clientId
@@ -52,7 +69,7 @@ describe('LuigiConfigService', () => {
5269
expect(config).toEqual({
5370
auth: mockAuthConfig,
5471
routing: expect.any(Object),
55-
settings: expect.any(Object),
72+
settings: mockStaticSettings,
5673
});
5774

5875
// Check routing config
@@ -63,56 +80,6 @@ describe('LuigiConfigService', () => {
6380
skipRoutingForUrlPatterns: [/.*/],
6481
pageNotFoundHandler: expect.any(Function),
6582
});
66-
67-
// Check settings config
68-
expect(config.settings).toEqual({
69-
header: {
70-
title: 'OpenMFP Portal',
71-
logo: expect.any(String),
72-
favicon: expect.any(String),
73-
},
74-
experimental: {
75-
btpToolLayout: true,
76-
},
77-
btpToolLayout: true,
78-
responsiveNavigation: 'Fiori3',
79-
featureToggles: {
80-
queryStringParam: 'ft',
81-
},
82-
appLoadingIndicator: {
83-
hideAutomatically: true,
84-
},
85-
});
86-
});
87-
});
88-
89-
describe('getStaticSettingsConfig', () => {
90-
it('should return the correct static settings', () => {
91-
const settings = (service as any).getStaticSettingsConfig();
92-
93-
expect(settings).toEqual({
94-
header: {
95-
title: 'OpenMFP Portal',
96-
logo: expect.any(String),
97-
favicon: expect.any(String),
98-
},
99-
experimental: {
100-
btpToolLayout: true,
101-
},
102-
btpToolLayout: true,
103-
responsiveNavigation: 'Fiori3',
104-
featureToggles: {
105-
queryStringParam: 'ft',
106-
},
107-
appLoadingIndicator: {
108-
hideAutomatically: true,
109-
},
110-
});
111-
112-
// Check that logo and favicon are blank images
113-
const blankImg = 'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAAC';
114-
expect(settings.header.logo).toBe(blankImg);
115-
expect(settings.header.favicon).toBe(blankImg);
11683
});
11784
});
11885

src/lib/services/luigi-config/luigi-config.service.ts

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import { Injectable } from '@angular/core';
1+
import { Inject, Injectable } from '@angular/core';
2+
import { LUIGI_STATIC_SETTINGS_CONFIG_SERVICE_INJECTION_TOKEN } from '../../injection-tokens';
23
import { ClientEnvironment } from '../../model/env';
34
import { AuthConfigService } from './auth-config.service';
45
import { EnvConfigService } from '../env-config.service';
6+
import { StaticSettingsConfigService } from './static-settings-config.service';
57

68
@Injectable({
79
providedIn: 'root',
810
})
911
export class LuigiConfigService {
1012
constructor(
1113
private envConfigService: EnvConfigService,
12-
private authConfigService: AuthConfigService
14+
private authConfigService: AuthConfigService,
15+
@Inject(LUIGI_STATIC_SETTINGS_CONFIG_SERVICE_INJECTION_TOKEN)
16+
private staticSettingsConfigService: StaticSettingsConfigService
1317
) {}
1418

1519
public async getLuigiConfiguration() {
@@ -21,30 +25,8 @@ export class LuigiConfigService {
2125
envConfig.clientId
2226
),
2327
routing: this.getRoutingConfig() as any,
24-
settings: this.getStaticSettingsConfig(),
25-
};
26-
}
27-
28-
private getStaticSettingsConfig() {
29-
const blankImg = 'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAAC';
30-
31-
return {
32-
header: {
33-
title: 'OpenMFP Portal',
34-
logo: blankImg,
35-
favicon: blankImg,
36-
},
37-
experimental: {
38-
btpToolLayout: true,
39-
},
40-
btpToolLayout: true,
41-
responsiveNavigation: 'Fiori3',
42-
featureToggles: {
43-
queryStringParam: 'ft',
44-
},
45-
appLoadingIndicator: {
46-
hideAutomatically: true,
47-
},
28+
settings:
29+
this.staticSettingsConfigService.getInitialStaticSettingsConfig(),
4830
};
4931
}
5032

0 commit comments

Comments
 (0)