Skip to content

Commit

Permalink
Merge pull request #1299 from sagely1/AG-1399-unknown-ensg-hanging
Browse files Browse the repository at this point in the history
AG-1399 fix invalid ensg in url from hanging
  • Loading branch information
sagely1 authored Apr 18, 2024
2 parents 721c95d + d6e6949 commit c6e8c81
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/app/core/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ApiService {
return url;
}

getGene(id: string): Observable<Gene> {
getGene(id: string): Observable<Gene | null> {
return this.http.get<Gene>(this.getBaseUrl() + '/api/genes/' + id, {
headers: new HttpHeaders(defaultHeaders),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,40 +135,45 @@ export class GeneDetailsComponent implements OnInit, AfterViewInit {
if (params.get('id')) {
this.geneService
.getGene(params.get('id') as string)
.subscribe((gene: Gene) => {
this.gene = gene;

this.panels.forEach((p: Panel) => {
if (p.name == 'nominations' && !this.gene?.total_nominations) {
p.disabled = true;
} else if (
p.name == 'experimental-validation' &&
!this.gene?.experimental_validation?.length
) {
p.disabled = true;
} else {
p.disabled = false;
.subscribe((gene) => {
if (!gene) {
this.helperService.setLoading(false);
this.router.navigateByUrl('/404-not-found', { skipLocationChange: true });
} else {
this.gene = gene;

this.panels.forEach((p: Panel) => {
if (p.name == 'nominations' && !this.gene?.total_nominations) {
p.disabled = true;
} else if (
p.name == 'experimental-validation' &&
!this.gene?.experimental_validation?.length
) {
p.disabled = true;
} else {
p.disabled = false;
}
});

const nominationsPanel = this.panels.find(
(p) => p.name == 'nominations'
);
if (nominationsPanel) {
nominationsPanel.disabled = !this.gene.total_nominations ? true : false;
}
});

const nominationsPanel = this.panels.find(
(p) => p.name == 'nominations'
);
if (nominationsPanel) {
nominationsPanel.disabled = !this.gene.total_nominations ? true : false;
}
const experimentalValidationPanel = this.panels.find(
(p) => p.name == 'experimental-validation'
);
if (experimentalValidationPanel) {
experimentalValidationPanel.disabled = !this.gene
.experimental_validation?.length
? true
: false;
}

const experimentalValidationPanel = this.panels.find(
(p) => p.name == 'experimental-validation'
);
if (experimentalValidationPanel) {
experimentalValidationPanel.disabled = !this.gene
.experimental_validation?.length
? true
: false;
this.helperService.setLoading(false);
}

this.helperService.setLoading(false);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ export class GeneSimilarComponent implements OnInit {
this.helperService.setLoading(true);
this.geneService
.getGene(params.get('id') as string)
.subscribe((gene: Gene) => {
this.gene = gene;
this.init();
.subscribe((gene: Gene | null) => {
if (!gene) {
this.helperService.setLoading(false);
this.router.navigateByUrl('/404-not-found', { skipLocationChange: true });
} else {
this.gene = gene;
this.init();
}
});
}
});
Expand Down
8 changes: 5 additions & 3 deletions src/app/features/genes/services/gene.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ export class GeneService {

// ------------------------------------------------------------------------ //

getGene(id: string): Observable<Gene> {
getGene(id: string): Observable<Gene | null> {
if (this.genes[id]) {
return of(this.genes[id]);
}

return this.apiService.getGene(id).pipe(
map((gene: Gene) => {
map((gene: Gene | null) => {
if (!gene)
return null;
gene.similar_genes_network = this.getSimilarGenesNetwork(gene);
return (this.genes[id] = gene);
})
Expand Down
2 changes: 1 addition & 1 deletion src/app/testing/api-service-stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {

@Injectable()
export class ApiServiceStub {
getGene(id: string): Observable<Gene> {
getGene(id: string): Observable<Gene | null> {
return of(geneMock1);
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/testing/gene-service-stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class GeneServiceStub {
this.geneService = new GeneService(new ApiServiceStub() as ApiService);
}

getGene(id: string): Observable<Gene> {
getGene(id: string): Observable<Gene | null> {
return this.geneService.getGene(id);
}

Expand Down
17 changes: 17 additions & 0 deletions tests/gene-details.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test, expect } from '@playwright/test';

test.describe('specific viewport block', () => {
test.slow();
test.use({ viewport: { width: 1600, height: 1200 } });

test('invalid gene results in a 404 redirect', async ({ page }) => {
// go to invalid ENSG page
await page.goto('/genes/ENSG00000000000');

// expect a title "to contain" a substring.
await expect(page).toHaveTitle('Agora');

// expect div for page not found content to be visible
expect(page.locator('.page-not-found')).toBeVisible();
});
});
17 changes: 17 additions & 0 deletions tests/gene-similar.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test, expect } from '@playwright/test';

test.describe('specific viewport block', () => {
test.slow();
test.use({ viewport: { width: 1600, height: 1200 } });

test('invalid gene results in a 404 redirect', async ({ page }) => {
// go to invalid ENSG page
await page.goto('/genes/ENSG00000000000/similar');

// expect a title "to contain" a substring.
await expect(page).toHaveTitle('Agora');

// expect div for page not found content to be visible
expect(page.locator('.page-not-found')).toBeVisible();
});
});

0 comments on commit c6e8c81

Please sign in to comment.