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

Perform a test through the URL directly #334

Merged
11 commits merged into from Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from 10 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
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
24 changes: 21 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,37 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
private _showProgressBar: boolean;
private langChangeSubscription: Subscription;

private domainName: string = '';
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'] ) {
this.domainName = params['domain'];
this.form.controls.domain.setValue(this.domainName);
Copy link
Member

@hannaeko hannaeko Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the domainName property used anywhere else? If not would it make sense to remove it?

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 +93,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