Skip to content

Commit

Permalink
AG-1435: lint e2e tests as described in playwright best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
hallieswan committed Apr 30, 2024
1 parent ad5ddfa commit 49839b8
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 38 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
"sourceType": "module",
"project": ["./tsconfig.base.json"]
},
"plugins": ["@typescript-eslint"],
"rules": {
Expand All @@ -23,6 +24,7 @@
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-this-alias": "off"
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-floating-promises": "warn"
}
}
2 changes: 2 additions & 0 deletions src/app/core/components/footer/footer.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ describe('Component: Footer', () => {
const link = element.querySelector('.footer-logo a') as HTMLElement;
expect(link).toBeTruthy();

// https://github.com/angular/angular/issues/45202
// eslint-disable-next-line @typescript-eslint/no-floating-promises
router.navigate(['/about']);
tick();
expect(location.path()).toBe('/about');
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/components/header/header.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ describe('Component: Header', () => {
const link = element.querySelector('.header-logo a') as HTMLElement;
expect(link).toBeTruthy();

// https://github.com/angular/angular/issues/45202
// eslint-disable-next-line @typescript-eslint/no-floating-promises
router.navigate(['/nominated-targets']);
tick();
expect(location.path()).toBe('/nominated-targets');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('Component: BarChart - Median', () => {
let element: HTMLElement;

beforeEach(waitForAsync(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
TestBed.configureTestingModule({
declarations: [MedianBarChartComponent],
imports: [RouterTestingModule],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('Component: GeneComparisonToolComponent', () => {
let route: ActivatedRoute;

beforeEach(fakeAsync(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
TestBed.configureTestingModule({
declarations: [
GeneComparisonToolComponent,
Expand Down Expand Up @@ -430,6 +431,7 @@ describe('Component: GeneComparisonToolComponent', () => {
) as HTMLElement;
filterClearButton.click();

// eslint-disable-next-line @typescript-eslint/no-floating-promises
fixture.whenStable().then(() => {
fixture.detectChanges();
expectSignificanceThresholdIsNotApplied();
Expand All @@ -448,6 +450,7 @@ describe('Component: GeneComparisonToolComponent', () => {
) as HTMLElement;
clearAllButton.click();

// eslint-disable-next-line @typescript-eslint/no-floating-promises
fixture.whenStable().then(() => {
fixture.detectChanges();
expectSignificanceThresholdIsNotApplied();
Expand All @@ -459,13 +462,15 @@ describe('Component: GeneComparisonToolComponent', () => {
component.initData([comparisonGeneMock1, comparisonGeneMock2]);
route.queryParams = of({});

// eslint-disable-next-line @typescript-eslint/no-floating-promises
fixture.whenStable().then(() => {
fixture.detectChanges();
expectSignificanceThresholdIsNotApplied();

const toggle = element.querySelector(TOGGLE_CLASS) as HTMLElement;
toggle.click();

// eslint-disable-next-line @typescript-eslint/no-floating-promises
fixture.whenStable().then(() => {
fixture.detectChanges();
expectSignificanceThresholdIsApplied();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export class GeneDetailsComponent implements OnInit, AfterViewInit {
.subscribe((gene) => {
if (!gene) {
this.helperService.setLoading(false);
// https://github.com/angular/angular/issues/45202
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigateByUrl('/404-not-found', { skipLocationChange: true });
} else {
this.gene = gene;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export class GeneNetworkComponent implements OnInit {
}

navigateToSimilarGenes() {
// https://github.com/angular/angular/issues/45202
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate([
'/genes/' + this._gene?.ensembl_gene_id + '/similar',
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export class GeneSearchComponent extends Unsub implements AfterViewInit {
this.results = [];
this.showGeneResults = false;
this.searchNavigated.emit();
// https://github.com/angular/angular/issues/45202
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(['/genes/' + id]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export class GeneSimilarComponent implements OnInit {
.subscribe((gene: Gene | null) => {
if (!gene) {
this.helperService.setLoading(false);
// https://github.com/angular/angular/issues/45202
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigateByUrl('/404-not-found', { skipLocationChange: true });
} else {
this.gene = gene;
Expand Down Expand Up @@ -144,6 +146,8 @@ export class GeneSimilarComponent implements OnInit {
navigateToGeneComparisonTool() {
const ids: string[] = this.genes.map((g: Gene) => g.ensembl_gene_id);
this.helperService.setGCTSelection(ids);
// https://github.com/angular/angular/issues/45202
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(['/genes/comparison']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export class GeneTableComponent implements OnInit {
}

navigateToGene(gene: any) {
// https://github.com/angular/angular/issues/45202
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(['/genes/' + gene.ensembl_gene_id]);
}

Expand Down Expand Up @@ -174,12 +176,16 @@ export class GeneTableComponent implements OnInit {

navigateToGeneComparisonTool() {
if (typeof this.gctLink === 'object') {
// https://github.com/angular/angular/issues/45202
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(['/genes/comparison'], {
queryParams: this.gctLink,
});
} else {
const ids: string[] = this._genes.map((g: Gene) => g.ensembl_gene_id);
this.helperService.setGCTSelection(ids);
// https://github.com/angular/angular/issues/45202
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(['/genes/comparison']);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/gene-details.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ test.describe('specific viewport block', () => {
await expect(page).toHaveTitle('Agora');

// expect div for page not found content to be visible
expect(page.locator('.page-not-found')).toBeVisible();
await expect(page.locator('.page-not-found')).toBeVisible();
});
});
});
4 changes: 2 additions & 2 deletions tests/gene-similar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ test.describe('specific viewport block', () => {
await expect(page).toHaveTitle('Agora');

// expect div for page not found content to be visible
expect(page.locator('.page-not-found')).toBeVisible();
await expect(page.locator('.page-not-found')).toBeVisible();
});
});
});
10 changes: 5 additions & 5 deletions tests/homepage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ test.describe('specific viewport block', () => {
await page.goto('/');

// Hamburger menu should be hidden for the desktop viewport
expect(page.locator('button.header-nav-toggle')).toBeHidden();
await expect(page.locator('button.header-nav-toggle')).toBeHidden();

// look for news link and click it
const newsLink = await page.getByRole('link', { name: 'News'});
const newsLink = page.getByRole('link', { name: 'News' });

// news link should be visible on the home page
expect(newsLink).toBeVisible();
await expect(newsLink).toBeVisible();

await newsLink.click();
await expect(page).toHaveTitle('News | Agora Releases');
});
});
});
37 changes: 37 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2017",
"module": "es2020",
"lib": ["es2020", "dom"],
"allowSyntheticDefaultImports": true
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
},
"include": [
"./src/**/*.ts",
"./src/**/*.html",
"./src/**/*.scss",
"./tests/**.ts",
"./tests/**/**.ts",
"playwright.config.ts"
]
}
28 changes: 1 addition & 27 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2017",
"module": "es2020",
"lib": ["es2020", "dom"],
"allowSyntheticDefaultImports": true
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
},
"extends": "./tsconfig.base.json",
"exclude": [
"./node_modules",
"./dist",
Expand Down

0 comments on commit 49839b8

Please sign in to comment.