Skip to content

Commit

Permalink
Added e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
fearnycompknowhow committed Jun 11, 2021
1 parent e78a452 commit 92634ae
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions projects/playground/e2e/integration/playground.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const EMAIL = '[email protected]';
const PASSWORD = Cypress.env('INTEGRATION_PASSWORD');
const APP_STATE = 'Any Random String';

const loginToAuth0 = () => {
cy.get('.auth0-lock-form')
Expand Down Expand Up @@ -44,6 +45,7 @@ describe('Smoke tests', () => {

it('do redirect login and show user and access token', () => {
cy.visit('/');
cy.get('[data-cy=app-state-input]').type(APP_STATE);
cy.get('#login').should('be.visible').click();
cy.url().should('include', 'https://brucke.auth0.com/login');
loginToAuth0();
Expand All @@ -60,6 +62,8 @@ describe('Smoke tests', () => {
cy.get('[data-cy=accessToken]').should('have.text', token);
});

cy.get('[data-cy=app-state-result]').should('have.value', APP_STATE);

cy.get('#logout').should('be.visible').click();
cy.get('#login').should('be.visible');
});
Expand Down
27 changes: 27 additions & 0 deletions projects/playground/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ <h2>Authentication</h2>
data-cy="login-popup"
/>
</label>

<br />
<br />

<label>
App State:
<input
type="text"
formControlName="appState"
data-cy="app-state-input"
/>
</label>

<br />
<br />

<button id="login" (click)="launchLogin()">Log in</button>
<button id="loginWithInvitation" (click)="loginHandleInvitationUrl()">
Log in with Invitation
Expand Down Expand Up @@ -132,6 +148,17 @@ <h2>Artifacts</h2>
<textarea data-cy="accessToken" cols="50" rows="2" disabled="true">{{
accessToken
}}</textarea>

<br />
<br />

<textarea
data-cy="app-state-result"
cols="50"
rows="2"
disabled="true"
>{{ appState }}</textarea
>
</li>
</ul>
</div>
Expand Down
19 changes: 17 additions & 2 deletions projects/playground/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Inject } from '@angular/core';
import { Component, Inject, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { AuthService } from 'projects/auth0-angular/src/lib/auth.service';
import { iif } from 'rxjs';
Expand All @@ -12,17 +12,19 @@ import { HttpClient } from '@angular/common/http';
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
export class AppComponent implements OnInit {
isAuthenticated$ = this.auth.isAuthenticated$;
isLoading$ = this.auth.isLoading$;
user$ = this.auth.user$;
claims$ = this.auth.idTokenClaims$;
accessToken = '';
appState = '';
error$ = this.auth.error$;

organization = '';

loginOptionsForm = new FormGroup({
appState: new FormControl(''),
usePopup: new FormControl(false),
});

Expand All @@ -36,6 +38,12 @@ export class AppComponent {
ignoreCache: new FormControl(false),
});

ngOnInit() {
this.auth.appState$.subscribe((appState) => {
this.appState = appState.deeply.nested.value;
});
}

constructor(
public auth: AuthService,
@Inject(DOCUMENT) private doc: Document,
Expand All @@ -51,6 +59,13 @@ export class AppComponent {
} else {
this.auth.loginWithRedirect({
...(this.organization ? { organization: this.organization } : null),
appState: {
deeply: {
nested: {
value: this.loginOptionsForm.value.appState,
},
},
},
});
}
}
Expand Down

0 comments on commit 92634ae

Please sign in to comment.