|
| 1 | +import { createTest } from '../create-test' |
| 2 | +import { getUrl } from './flush-after-navigate.defs' |
| 3 | + |
| 4 | +export const testFlushAfterNavigate = createTest( |
| 5 | + 'Flush after navigate', |
| 6 | + ({ path }) => { |
| 7 | + it('should apply pending search params after navigation', () => { |
| 8 | + cy.visit(getUrl(path + '/start', { debounce: 200 })) |
| 9 | + cy.contains('#hydration-marker', 'hydrated').should('be.hidden') |
| 10 | + cy.get('#test').click() |
| 11 | + cy.get('a').click() |
| 12 | + cy.location('pathname').should('eq', path + '/end') |
| 13 | + cy.get('#client-state').should('have.text', 'pass') |
| 14 | + cy.location('search').should('be.empty') |
| 15 | + cy.location('search').should('eq', '?test=pass') // Then it flushes |
| 16 | + }) |
| 17 | + it('should apply pending search params on top of existing link state in navigation', () => { |
| 18 | + cy.visit(getUrl(path + '/start', { debounce: 200, linkState: 'nav' })) |
| 19 | + cy.contains('#hydration-marker', 'hydrated').should('be.hidden') |
| 20 | + cy.get('#test').click() |
| 21 | + cy.get('a').click() |
| 22 | + cy.location('pathname').should('eq', path + '/end') |
| 23 | + cy.get('#client-state').should('have.text', 'pass') |
| 24 | + cy.location('search').should('eq', '?test=nav') |
| 25 | + cy.location('search').should('eq', '?test=pass') // Then it flushes |
| 26 | + }) |
| 27 | + it('should apply pending search params queued while throttled after navigation', () => { |
| 28 | + cy.visit(getUrl(path + '/start', { throttle: 200 })) |
| 29 | + cy.contains('#hydration-marker', 'hydrated').should('be.hidden') |
| 30 | + cy.get('#preflush').click() // Trigger an immediate flush to enable the throttling queue |
| 31 | + cy.get('#test').click() // Queue the change |
| 32 | + cy.get('a').click() // Navigate |
| 33 | + cy.location('pathname').should('eq', path + '/end') |
| 34 | + cy.get('#client-state').should('have.text', 'pass') |
| 35 | + cy.location('search').should('be.empty') |
| 36 | + cy.location('search').should('eq', '?test=pass') // Then it flushes again |
| 37 | + }) |
| 38 | + it('should apply pending search params queued while throttled after navigation with link state', () => { |
| 39 | + cy.visit(getUrl(path + '/start', { throttle: 200, linkState: 'nav' })) |
| 40 | + cy.contains('#hydration-marker', 'hydrated').should('be.hidden') |
| 41 | + cy.get('#preflush').click() // Trigger an immediate flush to enable the throttling queue |
| 42 | + cy.get('#test').click() // Queue the change |
| 43 | + cy.get('a').click() // Navigate |
| 44 | + cy.location('pathname').should('eq', path + '/end') |
| 45 | + cy.get('#client-state').should('have.text', 'pass') |
| 46 | + cy.location('search').should('eq', '?test=nav') |
| 47 | + cy.location('search').should('eq', '?test=pass') // Then it flushes again |
| 48 | + }) |
| 49 | + } |
| 50 | +) |
0 commit comments