Skip to content

Commit

Permalink
feat: add guard tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ducksoupdev committed Jun 10, 2021
1 parent 5f9fa0d commit d85f335
Show file tree
Hide file tree
Showing 29 changed files with 2,927 additions and 44 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.0.0] - 2021-06-10

### Breaking
- Make package `type: module`
- Rename build file to `router.mjs`

### New
- Allow routes to be cancelled

### Updates
- Add guards to documentation
- Uplift NPM dependencies

## [2.2.0] - 2021-05-07

### New
Expand Down
77 changes: 77 additions & 0 deletions cypress/integration/routed-app-guards-resolve-route/app.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* global describe cy before it */
describe('Guards - resolveRoute', () => {
before(() => {
cy.visit('routed-app-guards-resolve-route')
})

it('has rendered the home page', () => {
cy.get('#router-outlet')
.should('contain.text', 'Welcome to the home page!')
})

it('home page navigation is active', () => {
cy.get('button.active')
.should('have.text', 'Home')
})

describe('route to page one', () => {
before(() => {
cy.get('button:nth-of-type(2)').click()
})

it('has rendered page one', () => {
cy.get('#router-outlet')
.should('contain.text', 'Welcome to page one!')
})

it('page one navigation is active', () => {
cy.get('button.active')
.should('have.text', 'Page one')
})
})

describe('route to cancelled page', () => {
before(() => {
cy.get('button:nth-of-type(3)').click()
})

it('has remained on page one', () => {
cy.location().should((loc) => {
expect(loc.pathname).to.eq('/test/e2e/routed-app-guards-resolve-route/one')
})
})
})

describe('route to error page', () => {
before(() => {
cy.get('button:nth-of-type(4)').click()
})

it('has rendered an error', () => {
cy.get('#router-outlet')
.should('contain.text', 'An error occurred: Action error')
})
})

describe('route to page two', () => {
before(() => {
cy.get('button:nth-of-type(5)').click()
})

it('has redirected to page one', () => {
cy.location().should((loc) => {
expect(loc.pathname).to.eq('/test/e2e/routed-app-guards-resolve-route/one')
})
})

it('has rendered page one', () => {
cy.get('#router-outlet')
.should('contain.text', 'Welcome to page one!')
})

it('page one navigation is active', () => {
cy.get('button.active')
.should('have.text', 'Page one')
})
})
})
55 changes: 55 additions & 0 deletions cypress/integration/routed-app-guards/app.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* global describe cy before it */
describe('Guards', () => {
before(() => {
cy.visit('routed-app-guards')
})

it('has rendered the home page', () => {
cy.get('#router-outlet')
.should('contain.text', 'Welcome to the home page!')
})

it('home page navigation is active', () => {
cy.get('button.active')
.should('have.text', 'Home')
})

describe('route to page one', () => {
before(() => {
cy.get('button:nth-of-type(2)').click()
})

it('has rendered page one', () => {
cy.get('#router-outlet')
.should('contain.text', 'Welcome to page one!')
})

it('page one navigation is active', () => {
cy.get('button.active')
.should('have.text', 'Page one')
})
})

describe('route to cancelled page', () => {
before(() => {
cy.get('button:nth-of-type(3)').click()
})

it('has remained on page one', () => {
cy.location().should((loc) => {
expect(loc.pathname).to.eq('/test/e2e/routed-app-guards/one')
})
})
})

describe('route to error page', () => {
before(() => {
cy.get('button:nth-of-type(4)').click()
})

it('has rendered an error', () => {
cy.get('#router-outlet')
.should('contain.text', 'An error occurred: Action error')
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* global describe cy before it */
describe('Hash guards - resolveRoute', () => {
before(() => {
cy.visit('routed-app-hash-guards-resolve-route')
})

it('has rendered the home page', () => {
cy.get('#router-outlet')
.should('contain.text', 'Welcome to the home page!')
})

it('home page navigation is active', () => {
cy.get('button.active')
.should('have.text', 'Home')
})

describe('route to page one', () => {
before(() => {
cy.get('button:nth-of-type(2)').click()
})

it('has rendered page one', () => {
cy.get('#router-outlet')
.should('contain.text', 'Welcome to page one!')
})

it('page one navigation is active', () => {
cy.get('button.active')
.should('have.text', 'Page one')
})
})

describe('route to cancelled page', () => {
before(() => {
cy.get('button:nth-of-type(3)').click()
})

it('has remained on page one', () => {
cy.location().should((loc) => {
expect(loc.hash).to.eq('#/one')
})
})
})

describe('route to error page', () => {
before(() => {
cy.get('button:nth-of-type(4)').click()
})

it('has rendered an error', () => {
cy.get('#router-outlet')
.should('contain.text', 'An error occurred: Action error')
})
})

describe('route to page two', () => {
before(() => {
cy.get('button:nth-of-type(5)').click()
})

it('has redirected to page one', () => {
cy.location().should((loc) => {
expect(loc.hash).to.eq('#/one')
})
})

it('has rendered page one', () => {
cy.get('#router-outlet')
.should('contain.text', 'Welcome to page one!')
})

it('page one navigation is active', () => {
cy.get('button.active')
.should('have.text', 'Page one')
})
})
})
55 changes: 55 additions & 0 deletions cypress/integration/routed-app-hash-guards/app.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* global describe cy before it */
describe('Hash Ggards', () => {
before(() => {
cy.visit('routed-app-hash-guards')
})

it('has rendered the home page', () => {
cy.get('#router-outlet')
.should('contain.text', 'Welcome to the home page!')
})

it('home page navigation is active', () => {
cy.get('button.active')
.should('have.text', 'Home')
})

describe('route to page one', () => {
before(() => {
cy.get('button:nth-of-type(2)').click()
})

it('has rendered page one', () => {
cy.get('#router-outlet')
.should('contain.text', 'Welcome to page one!')
})

it('page one navigation is active', () => {
cy.get('button.active')
.should('have.text', 'Page one')
})
})

describe('route to cancelled page', () => {
before(() => {
cy.get('button:nth-of-type(3)').click()
})

it('has remained on page one', () => {
cy.location().should((loc) => {
expect(loc.hash).to.eq('#/one')
})
})
})

describe('route to error page', () => {
before(() => {
cy.get('button:nth-of-type(4)').click()
})

it('has rendered an error', () => {
cy.get('#router-outlet')
.should('contain.text', 'An error occurred: Action error')
})
})
})
2 changes: 1 addition & 1 deletion dist/router.mjs

Large diffs are not rendered by default.

Loading

0 comments on commit d85f335

Please sign in to comment.