Skip to content

Commit

Permalink
Merge pull request #334 from pnax/url-domain
Browse files Browse the repository at this point in the history
Perform a test through the URL directly
  • Loading branch information
Alexandre Pion committed Aug 19, 2022
2 parents ddafbec + a473fb8 commit 544d439
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 15 deletions.
4 changes: 2 additions & 2 deletions e2e/FR02.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ test.describe('Zonemaster test FR02 - [All menus should be clickable in latest v
});

test('should go to domain page', async ({ page, baseURL }) => {
await page.locator('a.nav-link[routerlink="/domain_check"]').click();
await expect(page).toHaveURL(baseURL + '/domain_check');
await page.locator('a.nav-link[routerlink="/check"]').click();
await expect(page).toHaveURL(baseURL + '/check');
});

});
2 changes: 1 addition & 1 deletion e2e/FR09.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ test.describe('Zonemaster test FR09 - [Once a language is chosen, all other link
await expect(page.locator('h1')).toHaveText('Nom de domaine');
await page.locator('a.nav-link[routerlink="/faq"]').click();
await expect(page.locator('section.main > div > h1')).toHaveText('FAQ');
await expect(page.locator('a.nav-link[routerlink="/domain_check"]')).toHaveText("Test d'un domaine");
await expect(page.locator('a.nav-link[routerlink="/check"]')).toHaveText("Test d'un domaine");
});
});
2 changes: 1 addition & 1 deletion e2e/navigation.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test.describe('Navigation should be consistent and honor browser behaviour', ()
});

test('ensure navigation to result page is consistent - #300', async ({ page, baseURL}) => {
const domainCheckUrl = baseURL + '/domain_check';
const domainCheckUrl = baseURL + '/check';
const firstTestUrl = baseURL + '/result/226f6d4f44ae3f80';
const secondTestUrl = baseURL + '/result/a0fbcbf6c5ff5842';
const firstDomain = 'results.afNiC.Fr';
Expand Down
27 changes: 27 additions & 0 deletions e2e/redirect.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { test, expect } = require('@playwright/test');

import { goToHome, setLang } from './utils/app.utils';

test.describe('Redirection should properly work', () => {
test.beforeEach(async ({ page }) => {
await goToHome(page);
await setLang(page, 'en');
});

test('/ should redirect to /check', async ({ page, baseURL }) => {
await page.goto( baseURL + '/' );
await expect(page).toHaveURL( baseURL + '/check' );
});

test('/domain_check should redirect to /check', async ({ page, baseURL }) => {
await page.goto( baseURL + '/domain_check' );
await expect(page).toHaveURL( baseURL + '/check' );
});

test('/test/<test-id> should redirect to /result/<test-id>', async ({ page, baseURL }) => {
const testID = '226f6d4f44ae3f80';

await page.goto( baseURL + '/test/' + testID );
await expect(page).toHaveURL( baseURL + '/result/' + testID );
});
});
14 changes: 7 additions & 7 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class MyTranslationLoader extends TranslateLoader {
}

const appRoutes: Routes = [
{ path: 'domain_check', component: DomainComponent },
{ path: 'check/:domain', component: DomainComponent },
{ path: 'check', component: DomainComponent },
{ path: 'result/:resultID', component: ResultComponent },
{ path: 'test/:resultID', component: ResultComponent },
{ path: 'history', component: HistoryComponent },
{ path: 'faq', component: FaqComponent },
{ path: '',
redirectTo: 'domain_check',
pathMatch: 'full'
},

{ path: 'domain_check', redirectTo: 'check', pathMatch: 'full' },
{ path: 'test/:resultID', redirectTo: 'result/:resultID', pathMatch: 'full' },
{ path: '', redirectTo: 'check', pathMatch: 'full' },

{ path: '**', component: PageNotFoundComponent }
];

Expand Down
23 changes: 20 additions & 3 deletions src/app/components/form/form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Validators,
AbstractControl} from '@angular/forms';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { LangChangeEvent, TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';

Expand Down Expand Up @@ -51,21 +52,36 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
private _showProgressBar: boolean;
private langChangeSubscription: Subscription;

private routeParamsSubscription: Subscription;

public history = {};
public test = {};
public disable_check_button = false;
public form: FormGroup;

constructor(private formBuilder: FormBuilder, private translateService: TranslateService, private titleService: Title) {}
constructor(private activatedRoute: ActivatedRoute,
private formBuilder: FormBuilder,
private translateService: TranslateService,
private titleService: Title) {}

ngOnInit() {
this.titleService.setTitle('Zonemaster');
this.generate_form();

this.routeParamsSubscription = this.activatedRoute.params.subscribe((params: Params) => {
if ( params['domain'] ) {
let domainName: string = params['domain'];
this.form.controls.domain.setValue(domainName);
this.runDomainCheck();
}
});

this.langChangeSubscription = this.translateService.onLangChange.subscribe((_: LangChangeEvent) => {
if (this.form.touched) {
this.runDomainCheck(false);
}
});
this.generate_form();
this.titleService.setTitle('Zonemaster');

}

ngOnChanges(changes: { [property: string]: SimpleChange }) {
Expand All @@ -76,6 +92,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {

ngOnDestroy() {
this.langChangeSubscription.unsubscribe();
this.routeParamsSubscription.unsubscribe();
}

private static atLeastOneProtocolValidator(control: AbstractControl) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/navigation/navigation.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div [ngbCollapse]="!isNavbarCollapsed" class="collapse navbar-collapse" id="navBar">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" routerLink="/domain_check" routerLinkActive="active">{{'Domain check'|translate}} </a>
<a class="nav-link" routerLink="/check" routerLinkActive="active">{{'Domain check'|translate}} </a>
</li>
<li class="nav-item">
<a class="nav-link" routerLink="/faq" routerLinkActive="active" >{{'FAQ'|translate}} </a>
Expand Down

0 comments on commit 544d439

Please sign in to comment.