|
| 1 | +import { getH1, getH2, getH3 } from '../support/app.po'; |
| 2 | + |
| 3 | +declare global { |
| 4 | + interface Window { |
| 5 | + globalThis: { |
| 6 | + _mfSSRDowngrade?: boolean | string[]; |
| 7 | + }; |
| 8 | + } |
| 9 | +} |
| 10 | + |
| 11 | +describe('/', () => { |
| 12 | + beforeEach(() => cy.visit('/')); |
| 13 | + |
| 14 | + describe('Welcome message', () => { |
| 15 | + it('should display welcome message', () => { |
| 16 | + getH1().contains('Welcome message from host'); |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + // check that clicking back and forwards in client side routeing still renders the content correctly |
| 21 | + describe('Routing checks', () => { |
| 22 | + it('[ /basic ] - should render in client side and fetch data from server side', () => { |
| 23 | + // wait nav hydration |
| 24 | + cy.wait(3000); |
| 25 | + cy.get('.basic').parent().click(); |
| 26 | + cy.url().should('include', '/basic'); |
| 27 | + getH2().contains('[ provider - client ] fetched data'); |
| 28 | + |
| 29 | + const stub = cy.stub(); |
| 30 | + cy.on('window:alert', stub); |
| 31 | + |
| 32 | + cy.get('#provider-btn') |
| 33 | + .should('be.visible') |
| 34 | + .click() |
| 35 | + .then(() => { |
| 36 | + expect(stub.getCall(0)).to.be.calledWith( |
| 37 | + '[provider] Client side Javascript works!', |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + cy.window().then((win) => { |
| 42 | + expect(win.globalThis._mfSSRDowngrade).to.not.exist; |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + it('[ /client-downgrade ] - should render in client side and load data.client.js to fetch data', () => { |
| 47 | + cy.wait(3000); |
| 48 | + cy.get('.client-downgrade').parent().click(); |
| 49 | + cy.url().should('include', '/client-downgrade'); |
| 50 | + getH2().contains('fetch data from provider client'); |
| 51 | + |
| 52 | + const stub = cy.stub(); |
| 53 | + cy.on('window:alert', stub); |
| 54 | + |
| 55 | + cy.get('#client-downgrade-btn') |
| 56 | + .should('be.visible') |
| 57 | + .click() |
| 58 | + .then(() => { |
| 59 | + expect(stub.getCall(0)).to.be.calledWith( |
| 60 | + '[client-downgrade] Client side Javascript works!', |
| 61 | + ); |
| 62 | + }); |
| 63 | + cy.window().then((win) => { |
| 64 | + expect(win.globalThis._mfSSRDowngrade).to.not.exist; |
| 65 | + }); |
| 66 | + }); |
| 67 | + }); |
| 68 | +}); |
0 commit comments