`
})
export class TestTemplate {}
let testHistoryInits = 0;
describe('router', () => {
beforeEach(() => {
history.pushState(null, null, '/');
cy.mount('');
});
it('routes with links and sets attributes', () => {
// Show the default page
cy.get('#page1').should('not.exist');
cy.get('test-component').should('not.exist');
cy.get('#default').should('exist');
cy.get('#notShown').should('not.exist');
// Go to page 1
cy.get('a#page1link').click();
cy.get('#page1').should('exist');
cy.get('test-component').should('not.exist');
cy.get('#default').should('not.exist');
cy.get('#notShown').should('not.exist');
// Go to the detail component
cy.get('a#testingId').click();
cy.get('#page1').should('not.exist');
cy.get('test-component').should('exist');
cy.get('#default').should('not.exist');
cy.get('#notShown').should('not.exist');
// Confirm the attribute contains the matching path segment
cy.get('#id').should('have.text', 'testingId');
// Back to page 1
cy.get('button').click();
// Go to the detail component with a deeper route
cy.get('a#deeper').click();
cy.get('#page1').should('not.exist');
cy.get('test-component').should('exist');
cy.get('#default').should('not.exist');
cy.get('#notShown').should('not.exist');
// Confirm the attribute only shows the first matching path segment
cy.get('#id').should('have.text', 'deeper');
// Back to page 1
cy.get('button').click()
// Verify that a slash is ignored at the end of a route
cy.get('#slash').click();
cy.get('#location').should('have.text', '/page1/');
cy.get('#page1').should('exist');
cy.get('test-component').should('not.exist');
// Back to default route
cy.get('#startOver').click();
});
it('navigates correctly with history', () => {
// Confirm components do not get instantiated over and over
let initsBefore;
cy.get('a#page2link').click();
cy.get('#inits').then(() => {
initsBefore = testHistoryInits;
});
cy.get('#deeper').click();
cy.get('#deeper').click();
cy.get('#inits').then(() => {
expect(testHistoryInits).to.equal(initsBefore);
});
// Confirm navigation back pops from the state
cy.get('#location').should('have.text', '/page2/deeper');
cy.get('button#back').click();
cy.get('#location').should('have.text', '/page2/deeper'); // not changed visibly
cy.get('button#back').click();
cy.get('#location').should('have.text', '/page2');
cy.get('button#forward').click();
cy.get('#location').should('have.text', '/page2/deeper');
cy.get('button#pushState').click();
cy.get('#location').should('have.text', '/');
});
it('works with a element', () => {
// Navigate to the template
cy.get('a#page3link').click();
cy.get('#page3default').should('exist');
// Route to the test element
cy.get('a#page3link').click();
cy.get('#123').should('exist');
cy.get('#id').should('have.text', '123');
});
});