Skip to content

Commit

Permalink
Merge branch 'master' into NAS-131036
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanY147 committed Sep 23, 2024
2 parents 4eaa26b + 8e5e6c9 commit 2e6c63e
Show file tree
Hide file tree
Showing 279 changed files with 6,243 additions and 2,656 deletions.
21 changes: 17 additions & 4 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ const { compilerOptions } = require('./tsconfig');
// Deliberately set to not UTC.
process.env.TZ = 'Europe/Kiev';

const esmPatterns = [
'.*\\.mjs$',
'is-cidr',
'ip-regex',
'cidr-regex',
'lodash-es',
'internmap',
'd3',
'delaunator',
'cheerio',
'robust-predicates',
];

module.exports = {
preset: 'jest-preset-angular',
globalSetup: 'jest-preset-angular/global-setup',
Expand All @@ -13,9 +26,9 @@ module.exports = {
coverageReporters: ['html', 'json'],
coverageDirectory: 'coverage/webui',
moduleDirectories: ['node_modules', 'src'],
moduleNameMapper: {
...pathsToModuleNameMapper(compilerOptions.paths || {}),
'^lodash-es$': 'lodash',
},
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths || {}),
transformIgnorePatterns: [
`node_modules/(?!(${esmPatterns.join('|')}))`
],
clearMocks: true,
};
117 changes: 58 additions & 59 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,48 @@
"bugs": {
"url": "https://jira.ixsystems.com"
},
"engines" : {
"node" : ">=18.19.1"
"engines": {
"node": ">=18.19.1"
},
"private": true,
"dependencies": {
"@angular-devkit/core": "^18.1.3",
"@angular-eslint/builder": "~18.2.0",
"@angular-eslint/eslint-plugin": "~18.2.0",
"@angular-eslint/eslint-plugin-template": "~18.2.0",
"@angular-eslint/template-parser": "~18.2.0",
"@angular/animations": "^18.1.3",
"@angular/build": "^18.1.3",
"@angular/cdk": "^18.1.3",
"@angular/cli": "^18.1.3",
"@angular/common": "^18.1.3",
"@angular/compiler": "^18.1.3",
"@angular/compiler-cli": "^18.1.3",
"@angular/core": "^18.1.3",
"@angular/forms": "^18.1.3",
"@angular/material": "^18.1.3",
"@angular/platform-browser": "^18.1.3",
"@angular/platform-browser-dynamic": "^18.1.3",
"@angular/router": "^18.1.3",
"@angular-devkit/core": "^18.2.4",
"@angular-eslint/builder": "~18.3.1",
"@angular-eslint/eslint-plugin": "~18.3.1",
"@angular-eslint/eslint-plugin-template": "~18.3.1",
"@angular-eslint/template-parser": "~18.3.1",
"@angular/animations": "^18.2.4",
"@angular/build": "^18.2.4",
"@angular/cdk": "^18.2.4",
"@angular/cli": "^18.2.4",
"@angular/common": "^18.2.4",
"@angular/compiler": "^18.2.4",
"@angular/compiler-cli": "^18.2.4",
"@angular/core": "^18.2.4",
"@angular/forms": "^18.2.4",
"@angular/material": "^18.2.4",
"@angular/platform-browser": "^18.2.4",
"@angular/platform-browser-dynamic": "^18.2.4",
"@angular/router": "^18.2.4",
"@biesbjerg/ngx-translate-extract-marker": "~1.0.0",
"@bugsplat/angular-tree-component": "~18.0.0",
"@codemirror/autocomplete": "~6.13.0",
"@codemirror/autocomplete": "~6.18.1",
"@codemirror/lang-json": "~6.0.1",
"@codemirror/lang-yaml": "~6.0.0",
"@codemirror/lang-yaml": "~6.1.1",
"@codemirror/language": "~6.10.1",
"@codemirror/lint": "~6.5.0",
"@codemirror/lint": "~6.8.1",
"@codemirror/state": "~6.4.1",
"@codemirror/theme-one-dark": "~6.1.2",
"@codemirror/view": "~6.24.1",
"@commitlint/cli": "~19.4.1",
"@codemirror/view": "~6.33.0",
"@commitlint/cli": "~19.5.0",
"@ctrl/tinycolor": "~4.1.0",
"@inquirer/prompts": "^5.3.8",
"@inquirer/prompts": "^6.0.1",
"@lezer/common": "~1.2.1",
"@lezer/generator": "~1.7.1",
"@lezer/lr": "~1.4.2",
"@material-design-icons/font": "~0.14.13",
"@mdi/font": "~7.4.47",
"@messageformat/core": "~3.3.0",
"@ngneat/reactive-forms": "~5.0.2",
"@ngneat/spectator": "~19.0.0",
"@ngneat/until-destroy": "~10.0.0",
Expand All @@ -97,15 +98,14 @@
"@sentry/utils": "~7.42.0",
"@shopify/eslint-plugin": "~42.1.0",
"@types/cheerio": "~0.22.35",
"@types/d3": "~5.16.0",
"@types/dygraphs": "^2.1.2",
"@types/d3": "~7.4.3",
"@types/dygraphs": "^2.1.10",
"@types/figlet": "~1.5.5",
"@types/fontfaceobserver": "^0.0.6",
"@types/jest": "~29.5.0",
"@types/fontfaceobserver": "^2.1.3",
"@types/jest": "~29.5.13",
"@types/jest-when": "^3.5.5",
"@types/js-yaml": "~4.0.8",
"@types/lodash-es": "~4.17.12",
"@types/marked": "^4.3.0",
"@types/mime-types": "~2.1.1",
"@types/node": "^18.19.1",
"@types/randomcolor": "~0.5.9",
Expand All @@ -116,18 +116,18 @@
"@xterm/xterm": "~5.5.0",
"angular-resize-event": "^3.2.0",
"angular2-uuid": "~1.1.1",
"chart.js": "~4.4.3",
"chart.js": "~4.4.4",
"chartjs-adapter-date-fns": "~3.0.0",
"cheerio": "~1.0.0-rc.12",
"cheerio": "~1.0.0",
"codemirror": "~6.0.1",
"commander": "~12.1.0",
"commitlint-config-jira": "~1.6.4",
"commitlint-plugin-jira-rules": "~1.6.4",
"core-js": "~3.6.4",
"cron-parser": "~4.9.0",
"croner": "~4.2.3",
"cronstrue": "~2.27.0",
"d3": "~5.16.0",
"croner": "~8.1.1",
"cronstrue": "~2.50.0",
"d3": "~7.9.0",
"date-fns": "~2.28.0",
"date-fns-tz": "~1.3.8",
"dygraphs": "~2.2.1",
Expand All @@ -138,62 +138,61 @@
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-angular-file-naming": "~1.0.2",
"eslint-plugin-angular-test-ids": "~1.0.6",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "~27.6.2",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-jest": "~28.8.3",
"eslint-plugin-rxjs": "^5.0.3",
"eslint-plugin-rxjs-angular": "^2.0.1",
"eslint-plugin-sonarjs": "~0.17.0",
"eslint-plugin-unicorn": "^43.0.1",
"eslint-plugin-unused-imports": "^2.0.0",
"eslint-plugin-sonarjs": "~0.25.1",
"eslint-plugin-unicorn": "^55.0.0",
"eslint-plugin-unused-imports": "^4.1.4",
"figlet": "~1.7.0",
"fontfaceobserver": "^2.3.0",
"fuse.js": "~7.0.0",
"html2canvas": "~1.4.1",
"husky": "^9.1.4",
"husky": "^9.1.6",
"immer": "~10.1.1",
"ip-regex": "~4.3.0",
"is-cidr": "~3.1.1",
"ip-regex": "~5.0.0",
"is-cidr": "~5.1.0",
"jdenticon": "~3.3.0",
"jest": "~29.7.0",
"jest-canvas-mock": "^2.5.0",
"jest-fail-on-console": "~3.3.0",
"jest-preset-angular": "~14.2.2",
"jest-when": "~3.5.1",
"jest-preset-angular": "~14.2.4",
"jest-when": "~3.6.0",
"jira-prepare-commit-msg": "^1.6.1",
"js-yaml": "~4.1.0",
"lint-staged": "^15.2.8",
"lint-staged": "^15.2.10",
"lodash-es": "~4.17.21",
"marked": "^4.3.0",
"marked": "^12.0.2",
"markuplint": "~2.9.0",
"markuplint-angular-parser": "~1.1.3",
"messageformat": "~2.3.0",
"messageformat-parser": "~4.1.3",
"mime-types": "~2.1.35",
"ng-gallery": "~8.0.4",
"ng-gallery": "~11.0.0",
"ng-lazyload-image": "~9.1.3",
"ng-mocks": "~14.13.0",
"ng-mocks": "~14.13.1",
"ng-qrcode": "~18.0.0",
"ng2-charts": "~6.0.1",
"ng2-fittext": "~1.4.3",
"ng2-fittext": "~2.0.0",
"ngx-drag-drop": "~18.0.2",
"ngx-img-fallback": "^2.0.0",
"ngx-markdown": "~16.0.0",
"ngx-img-fallback": "^3.0.0",
"ngx-markdown": "~18.0.0",
"ngx-popperjs": "^16.0.1",
"ngx-skeleton-loader": "~5.0.0",
"ngx-translate-messageformat-compiler": "~5.0.1",
"ngx-translate-messageformat-compiler": "~7.0.0",
"ngx-webstorage": "~18.0.0",
"randomcolor": "~0.6.2",
"rxjs": "~7.8.1",
"stylelint": "^14.9.1",
"stylelint-config-sass-guidelines": "~9.0.1",
"stylelint-config-standard": "^26.0.0",
"text-security": "~3.2.1",
"ts-jest": "~29.1.0",
"ts-jest": "~29.2.5",
"tsconfig-paths": "~4.2.0",
"tsx": "~4.19.0",
"typescript": "~5.4.5",
"tsx": "~4.19.1",
"typescript": "~5.5.4",
"utility-types": "~3.11.0",
"zone.js": "~0.14.4"
"zone.js": "~0.14.10"
},
"lint-staged": {
"*.{ts,html}": [
Expand Down
8 changes: 3 additions & 5 deletions scripts/validate_translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ fs.readdir(translationDir, function (err, files) {
const messages = JSON.parse(fs.readFileSync(translationDir + file, { encoding: 'utf-8' }));

// Validate line by line because it gives better error messages
let line = 2; // First line is opening bracket
Object.entries(messages).forEach(([key, translation]) => {
try {
parse(key);
parse(translation);
line++;
} catch (error) {
hadErrors = true;

if (error.location) {
console.error(`${language}.json, line ${error.location.start.line}: ${error.message}`);
} else {
console.error(`${language}.json: ${error.message}`);
}
console.error(`${language}.json, line ${line}: ${error.message}`);
}
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/app/core/classes/icu-missing-translation-handler.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import MessageFormat from '@messageformat/core';
import { MissingTranslationHandler, MissingTranslationHandlerParams } from '@ngx-translate/core';
import MessageFormat from 'messageformat';

/**
* Messages in ICU format only get compiled when they are loaded from json file.
* If for whatever reason message is absent from a json file, we don't want to show broken strings in the UI.
* This will assume key is in ICU format and compile on the fly.
*/
export class IcuMissingTranslationHandler implements MissingTranslationHandler {
private messageFormat = new MessageFormat();
private messageFormat = new MessageFormat('en');

handle(params: MissingTranslationHandlerParams): string {
try {
const compiled = this.messageFormat.compile(params.key, 'en');
const compiled = this.messageFormat.compile(params.key);
if (!compiled || !params.interpolateParams) {
return params.key;
}
return compiled(params.interpolateParams);
return compiled(params.interpolateParams as Record<string, unknown> | unknown[]);
} catch (error: unknown) {
console.error(error);
return params.key;
Expand Down
79 changes: 79 additions & 0 deletions src/app/core/testing/classes/mock-global-store.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {
Injectable,
Type,
ExistingProvider,
FactoryProvider,
forwardRef,
} from '@angular/core';
import { Observable, of } from 'rxjs';
import { MockGlobalStoreResponses } from 'app/core/testing/interfaces/mock-global-store-responses.interface';
import {
ApiCallAndSubscribeMethod,
ApiCallAndSubscribeResponse,
} from 'app/interfaces/api/api-call-and-subscribe-directory.interface';
import {
ApiCallMethod,
ApiCallResponse,
} from 'app/interfaces/api/api-call-directory.interface';
import { ApiEventMethod, ApiEventTyped } from 'app/interfaces/api-message.interface';
import {
GlobalStoreMembers,
} from 'app/services/global-store/global-store.service';

export function mockGlobalStore<
M1 extends ApiCallMethod,
M2 extends ApiEventMethod,
M3 extends ApiCallAndSubscribeMethod,
>(
stores: [
store: Type<GlobalStoreMembers<M1, M2, M3>>,
mockResponses?: MockGlobalStoreResponses<M1, M2, M3>,
][],
): (FactoryProvider | ExistingProvider)[] {
return stores.map((store) => {
const mockStoreService = new (mockGlobalStoreService(store[1]))();
return [
{
provide: store[0],
useFactory: () => mockStoreService,
},
{
provide: mockStoreService,
useExisting: forwardRef(() => store[0]),
},
];
}).flat();
}

function mockGlobalStoreService<
M1 extends ApiCallMethod,
M2 extends ApiEventMethod,
M3 extends ApiCallAndSubscribeMethod,
>(
mockResponses?: MockGlobalStoreResponses<M1, M2, M3>,
): Type<GlobalStoreMembers<M1, M2, M3>> {
@Injectable({ providedIn: 'root' })
class MockGlobalStore implements GlobalStoreMembers<M1, M2, M3> {
get call(): Observable<ApiCallResponse<M1>> {
return this.getResponse(mockResponses?.call);
}

get subscribe(): Observable<ApiEventTyped<M2>> {
return this.getResponse(mockResponses?.subscribe);
}

get callAndSubscribe(): Observable<ApiCallAndSubscribeResponse<M3>[]> {
return this.getResponse(mockResponses?.callAndSubscribe);
}

invalidate(): void {}

private getResponse<R>(mockResponse: R): Observable<R> {
if (mockResponse === undefined) {
throw Error('Unmocked global store response');
}
return of(mockResponse);
}
}
return MockGlobalStore;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
ApiCallAndSubscribeMethod,
ApiCallAndSubscribeResponse,
} from 'app/interfaces/api/api-call-and-subscribe-directory.interface';
import {
ApiCallMethod,
ApiCallResponse,
} from 'app/interfaces/api/api-call-directory.interface';
import {
ApiEventMethod,
ApiEventTyped,
} from 'app/interfaces/api-message.interface';

export interface MockGlobalStoreResponses<
M1 extends ApiCallMethod,
M2 extends ApiEventMethod,
M3 extends ApiCallAndSubscribeMethod,
> {
call?: ApiCallResponse<M1>;
subscribe?: ApiEventTyped<M2>;
callAndSubscribe?: ApiCallAndSubscribeResponse<M3>[];
}
Loading

0 comments on commit 2e6c63e

Please sign in to comment.