From 10be8b3e3b90d227780c6734039fe7ad82650565 Mon Sep 17 00:00:00 2001 From: Wojciech Duda <69160975+wojd0@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:15:03 +0100 Subject: [PATCH 1/3] AAE-20779 enable material selectors rule --- .eslintrc.js | 4 +++- lib/eslint-angular/main.js | 8 ++++++++ package-lock.json | 11 +++++++++++ package.json | 5 ++++- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 lib/eslint-angular/main.js diff --git a/.eslintrc.js b/.eslintrc.js index e05c7e38997..2e015376801 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -37,11 +37,13 @@ module.exports = { 'eslint-plugin-import', '@angular-eslint/eslint-plugin', '@typescript-eslint', - 'jsdoc' + 'jsdoc', + '@alfresco/eslint-angular' ], rules: { // Uncomment this to enable prettier checks as part of the ESLint // 'prettier/prettier': 'error', + '@alfresco/eslint-angular/no-angular-material-selectors': 'error', 'ban/ban': [ 'error', { name: 'eval', message: 'Calls to eval is not allowed.' }, diff --git a/lib/eslint-angular/main.js b/lib/eslint-angular/main.js new file mode 100644 index 00000000000..7d0207540af --- /dev/null +++ b/lib/eslint-angular/main.js @@ -0,0 +1,8 @@ +require('ts-node').register({ + compilerOptions: { + module: 'commonjs', + target: 'es2019', + }, +}); + +module.exports = require('./index.ts'); diff --git a/package-lock.json b/package-lock.json index 2095b65abc8..533a9649451 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "alfresco-ng2-components", "version": "6.8.0", "license": "Apache-2.0", + "workspaces": [ + "./lib/eslint-angular" + ], "dependencies": { "@angular/animations": "14.1.3", "@angular/cdk": "14.1.2", @@ -158,6 +161,10 @@ "node": ">=6.0.0" } }, + "lib/eslint-angular": { + "version": "6.7.1", + "license": "Apache-2.0" + }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", @@ -167,6 +174,10 @@ "node": ">=0.10.0" } }, + "node_modules/@alfresco/eslint-plugin-eslint-angular": { + "resolved": "lib/eslint-angular", + "link": true + }, "node_modules/@ampproject/remapping": { "version": "2.2.0", "dev": true, diff --git a/package.json b/package.json index 119e8047dbf..ac1139783d3 100644 --- a/package.json +++ b/package.json @@ -234,5 +234,8 @@ "node": ">=6.0.0" }, "module": "./index.js", - "typings": "./index.d.ts" + "typings": "./index.d.ts", + "workspaces": [ + "./lib/eslint-angular" + ] } From 11f91e4b233188c6dccf8b8b5f42d0df52a05580 Mon Sep 17 00:00:00 2001 From: Wojciech Duda <69160975+wojd0@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:20:18 +0200 Subject: [PATCH 2/3] AAE-20779 fixes in units in already covered libs --- .eslintrc.js | 11 +++-- .../content-metadata.component.spec.ts | 4 +- .../user-icon-column.component.spec.ts | 2 +- .../icon-cell/icon-cell.component.spec.ts | 40 ++++++++++--------- .../unsaved-changes-dialog.component.spec.ts | 25 ++++++------ package-lock.json | 1 + 6 files changed, 47 insertions(+), 36 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 2e015376801..ad80b0b2948 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -37,13 +37,11 @@ module.exports = { 'eslint-plugin-import', '@angular-eslint/eslint-plugin', '@typescript-eslint', - 'jsdoc', - '@alfresco/eslint-angular' + 'jsdoc' ], rules: { // Uncomment this to enable prettier checks as part of the ESLint // 'prettier/prettier': 'error', - '@alfresco/eslint-angular/no-angular-material-selectors': 'error', 'ban/ban': [ 'error', { name: 'eval', message: 'Calls to eval is not allowed.' }, @@ -185,6 +183,13 @@ module.exports = { files: ['*.html'], extends: ['plugin:@angular-eslint/template/recommended'], rules: {} + }, + { + files: ['*.spec.ts'], + plugins: ['@alfresco/eslint-angular'], + rules: { + '@alfresco/eslint-angular/no-angular-material-selectors': 'error' + } } ] }; diff --git a/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.spec.ts b/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.spec.ts index 3001fe04373..f226113255d 100644 --- a/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.spec.ts +++ b/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.spec.ts @@ -751,7 +751,7 @@ describe('ContentMetadataComponent', () => { fixture.detectChanges(); await fixture.whenStable(); - const basicPropertiesGroup = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container mat-expansion-panel')); + const basicPropertiesGroup = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container .adf-content-metadata-panel')); expect(basicPropertiesGroup).toBeNull(); }); @@ -764,7 +764,7 @@ describe('ContentMetadataComponent', () => { fixture.detectChanges(); await fixture.whenStable(); - const basicPropertiesGroup = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container mat-expansion-panel')); + const basicPropertiesGroup = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container .adf-content-metadata-panel')); expect(basicPropertiesGroup).toBeDefined(); }); diff --git a/lib/content-services/src/lib/permission-manager/components/user-icon-column/user-icon-column.component.spec.ts b/lib/content-services/src/lib/permission-manager/components/user-icon-column/user-icon-column.component.spec.ts index d89c6f8ec6b..8d895d8574c 100644 --- a/lib/content-services/src/lib/permission-manager/components/user-icon-column/user-icon-column.component.spec.ts +++ b/lib/content-services/src/lib/permission-manager/components/user-icon-column/user-icon-column.component.spec.ts @@ -116,7 +116,7 @@ describe('UserIconColumnComponent', () => { component.selected = true; component.ngOnInit(); fixture.detectChanges(); - expect(element.querySelector('mat-icon[svgIcon="selected"]')).toBeDefined(); + expect(element.querySelector('.adf-people-select-icon[svgIcon="selected"]')).toBeDefined(); expect(component.isSelected).toBe(true); }); }); diff --git a/lib/core/src/lib/datatable/components/icon-cell/icon-cell.component.spec.ts b/lib/core/src/lib/datatable/components/icon-cell/icon-cell.component.spec.ts index aba9070beb1..fcd718de6c9 100644 --- a/lib/core/src/lib/datatable/components/icon-cell/icon-cell.component.spec.ts +++ b/lib/core/src/lib/datatable/components/icon-cell/icon-cell.component.spec.ts @@ -20,20 +20,23 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { IconCellComponent } from './icon-cell.component'; import { ObjectDataTableAdapter } from '../../data/object-datatable-adapter'; import { ObjectDataColumn } from '../../data/object-datacolumn.model'; +import { HarnessLoader } from '@angular/cdk/testing'; +import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; +import { MatIconHarness } from '@angular/material/icon/testing'; describe('IconCellComponent', () => { let component: IconCellComponent; let fixture: ComponentFixture; - const getIconElement = () => fixture.debugElement.nativeElement.querySelector('mat-icon'); - const renderAndCheckResult = (value: any, expectedOccurrence: boolean, expectedIconName?: string) => { + let loader: HarnessLoader; + const renderAndCheckResult = async (value: any, expectedOccurrence: boolean, expectedIconName?: string) => { component.value$.next(value); fixture.detectChanges(); - const iconElement = getIconElement(); + const icon = await loader.getHarnessOrNull(MatIconHarness); - expectedOccurrence ? expect(iconElement).toBeTruthy() : expect(iconElement).toBeFalsy(); + expectedOccurrence ? expect(icon).not.toBeNull() : expect(icon).toBeNull(); if (expectedIconName) { - expect(iconElement.textContent.trim()).toBe(expectedIconName); + expect(await icon?.getName()).toBe(expectedIconName); } }; @@ -44,6 +47,7 @@ describe('IconCellComponent', () => { fixture = TestBed.createComponent(IconCellComponent); component = fixture.componentInstance; + loader = TestbedHarnessEnvironment.loader(fixture); }); describe('Initialization', () => { @@ -80,23 +84,23 @@ describe('IconCellComponent', () => { }); describe('UI', () => { - it('should render icon element in case of non-empty string (icon name validation NOT included)', () => { - renderAndCheckResult('group', true, 'group'); - renderAndCheckResult('groupe', true, 'groupe'); - renderAndCheckResult('0', true, '0'); - renderAndCheckResult('false', true, 'false'); + it('should render icon element in case of non-empty string (icon name validation NOT included)', async () => { + await renderAndCheckResult('group', true, 'group'); + await renderAndCheckResult('groupe', true, 'groupe'); + await renderAndCheckResult('0', true, '0'); + await renderAndCheckResult('false', true, 'false'); }); - it('should NOT render icon element in case of empty string', () => { - renderAndCheckResult('', false); + it('should NOT render icon element in case of empty string', async () => { + await renderAndCheckResult('', false); }); - it('should NOT render icon element in case of type different than string', () => { - renderAndCheckResult(0, false); - renderAndCheckResult({}, false); - renderAndCheckResult(null, false); - renderAndCheckResult(undefined, false); - renderAndCheckResult(NaN, false); + it('should NOT render icon element in case of type different than string', async () => { + await renderAndCheckResult(0, false); + await renderAndCheckResult({}, false); + await renderAndCheckResult(null, false); + await renderAndCheckResult(undefined, false); + await renderAndCheckResult(NaN, false); }); }); }); diff --git a/lib/core/src/lib/dialogs/unsaved-changes-dialog/unsaved-changes-dialog.component.spec.ts b/lib/core/src/lib/dialogs/unsaved-changes-dialog/unsaved-changes-dialog.component.spec.ts index 633442cfffe..23af9fe3776 100644 --- a/lib/core/src/lib/dialogs/unsaved-changes-dialog/unsaved-changes-dialog.component.spec.ts +++ b/lib/core/src/lib/dialogs/unsaved-changes-dialog/unsaved-changes-dialog.component.spec.ts @@ -36,12 +36,10 @@ describe('UnsavedChangesDialog', () => { let closeIconButton: DebugElement; beforeEach(() => { - closeIconButton = fixture.debugElement.query(By.css( - '[data-automation-id="adf-unsaved-changes-dialog-close-button"]' - )); + closeIconButton = fixture.debugElement.query(By.css('[data-automation-id="adf-unsaved-changes-dialog-close-button"]')); }); - it('should have assigned mat-dialog-close with false as result', () => { + it('should have assigned dialog close button with false as result', () => { expect(closeIconButton.injector.get(MatDialogClose).dialogResult).toBeFalse(); }); @@ -51,18 +49,21 @@ describe('UnsavedChangesDialog', () => { }); describe('Cancel button', () => { - it('should have assigned mat-dialog-close with false as result', () => { - expect(fixture.debugElement.query(By.css( - '[data-automation-id="adf-unsaved-changes-dialog-cancel-button"]' - )).injector.get(MatDialogClose).dialogResult).toBeFalse(); + it('should have assigned dialog close button with false as result', () => { + expect( + fixture.debugElement.query(By.css('[data-automation-id="adf-unsaved-changes-dialog-cancel-button"]')).injector.get(MatDialogClose) + .dialogResult + ).toBeFalse(); }); }); describe('Discard changes button', () => { - it('should have assigned mat-dialog-close with true as result', () => { - expect(fixture.debugElement.query(By.css( - '[data-automation-id="adf-unsaved-changes-dialog-discard-changes-button"]' - )).injector.get(MatDialogClose).dialogResult).toBeTrue(); + it('should have assigned dialog close button with true as result', () => { + expect( + fixture.debugElement + .query(By.css('[data-automation-id="adf-unsaved-changes-dialog-discard-changes-button"]')) + .injector.get(MatDialogClose).dialogResult + ).toBeTrue(); }); }); }); diff --git a/package-lock.json b/package-lock.json index 533a9649451..83df08ea76d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -162,6 +162,7 @@ } }, "lib/eslint-angular": { + "name": "@alfresco/eslint-plugin-eslint-angular", "version": "6.7.1", "license": "Apache-2.0" }, From 7ecaefc9d04ec2371a6757e238abe31b55ba59ac Mon Sep 17 00:00:00 2001 From: Wojciech Duda <69160975+wojd0@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:59:14 +0200 Subject: [PATCH 3/3] AAE-20779 simplified local package linking --- package-lock.json | 4 +--- package.json | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 83df08ea76d..f5a9c401642 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,9 +8,6 @@ "name": "alfresco-ng2-components", "version": "6.8.0", "license": "Apache-2.0", - "workspaces": [ - "./lib/eslint-angular" - ], "dependencies": { "@angular/animations": "14.1.3", "@angular/cdk": "14.1.2", @@ -50,6 +47,7 @@ "zone.js": "~0.11.4" }, "devDependencies": { + "@alfresco/eslint-plugin-eslint-angular": "file:lib/eslint-angular", "@angular-devkit/build-angular": "14.1.3", "@angular-devkit/schematics": "~14.2.12", "@angular-eslint/eslint-plugin": "15.2.1", diff --git a/package.json b/package.json index ac1139783d3..a6c3e0a53c1 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "zone.js": "~0.11.4" }, "devDependencies": { + "@alfresco/eslint-plugin-eslint-angular": "file:lib/eslint-angular", "@angular-devkit/build-angular": "14.1.3", "@angular-devkit/schematics": "~14.2.12", "@angular-eslint/eslint-plugin": "15.2.1", @@ -234,8 +235,5 @@ "node": ">=6.0.0" }, "module": "./index.js", - "typings": "./index.d.ts", - "workspaces": [ - "./lib/eslint-angular" - ] + "typings": "./index.d.ts" }