Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAE-21233 Enable no angular material selectors rule for adf #9430

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,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'
}
}
]
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand All @@ -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();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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<IconCellComponent>;
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);
}
};

Expand All @@ -44,6 +47,7 @@ describe('IconCellComponent', () => {

fixture = TestBed.createComponent(IconCellComponent);
component = fixture.componentInstance;
loader = TestbedHarnessEnvironment.loader(fixture);
});

describe('Initialization', () => {
Expand Down Expand Up @@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand All @@ -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();
});
});
});
8 changes: 8 additions & 0 deletions lib/eslint-angular/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require('ts-node').register({
compilerOptions: {
module: 'commonjs',
target: 'es2019',
},
});

module.exports = require('./index.ts');
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading