|
| 1 | +Cypress.on('uncaught:exception', (err) => { |
| 2 | + if (err.message.includes('Minified React error')) { |
| 3 | + return false |
| 4 | + } |
| 5 | +}) |
| 6 | + |
| 7 | +describe('Sub-Router', () => { |
| 8 | + const routes = [ |
| 9 | + { |
| 10 | + path: "/routes/sub-router", |
| 11 | + marker: "index", |
| 12 | + label: "Index route" |
| 13 | + }, |
| 14 | + { |
| 15 | + path: `/routes/sub-router/page/profile`, |
| 16 | + marker: `profile`, |
| 17 | + label: `Dynamic route`, |
| 18 | + }, |
| 19 | + { |
| 20 | + path: `/routes/sub-router/not-found`, |
| 21 | + marker: `NotFound`, |
| 22 | + label: `Default route (not found)`, |
| 23 | + }, |
| 24 | + { |
| 25 | + path: `/routes/sub-router/nested`, |
| 26 | + marker: `nested-page/index`, |
| 27 | + label: `Index route inside nested router`, |
| 28 | + }, |
| 29 | + { |
| 30 | + path: `/routes/sub-router/nested/foo`, |
| 31 | + marker: `nested-page/foo`, |
| 32 | + label: `Dynamic route inside nested router`, |
| 33 | + }, |
| 34 | + { |
| 35 | + path: `/routes/sub-router/static`, |
| 36 | + marker: `static-sibling`, |
| 37 | + label: `Static route that is a sibling to client only path`, |
| 38 | + }, |
| 39 | + ] as const |
| 40 | + |
| 41 | + routes.forEach(({ path, marker, label }) => { |
| 42 | + it(label, () => { |
| 43 | + cy.visit(path).waitForRouteChange() |
| 44 | + cy.get(`[data-testid="dom-marker"]`).contains(marker) |
| 45 | + |
| 46 | + cy.url().should( |
| 47 | + `match`, |
| 48 | + new RegExp(`^${Cypress.config().baseUrl + path}/?$`) |
| 49 | + ) |
| 50 | + }) |
| 51 | + }) |
| 52 | +}) |
| 53 | + |
| 54 | +describe('Paths', () => { |
| 55 | + const routes = [ |
| 56 | + { |
| 57 | + name: 'client-only', |
| 58 | + param: 'dune', |
| 59 | + }, |
| 60 | + { |
| 61 | + name: 'client-only/wildcard', |
| 62 | + param: 'atreides/harkonnen', |
| 63 | + }, |
| 64 | + { |
| 65 | + name: 'client-only/named-wildcard', |
| 66 | + param: 'corinno/fenring', |
| 67 | + }, |
| 68 | + ] as const |
| 69 | + |
| 70 | + for (const route of routes) { |
| 71 | + it(`should return "${route.name}" result`, () => { |
| 72 | + cy.visit(`/routes/${route.name}${route.param ? `/${route.param}` : ''}`).waitForRouteChange() |
| 73 | + cy.get("[data-testid=title]").should("have.text", route.name) |
| 74 | + cy.get("[data-testid=params]").should("have.text", route.param) |
| 75 | + }) |
| 76 | + } |
| 77 | +}) |
| 78 | + |
| 79 | +describe('Prioritize', () => { |
| 80 | + it('should prioritize static page over matchPath page with wildcard', () => { |
| 81 | + cy.visit('/routes/client-only/prioritize').waitForRouteChange() |
| 82 | + cy.get("[data-testid=title]").should("have.text", "client-only/prioritize static") |
| 83 | + }) |
| 84 | + it('should return result for wildcard on nested prioritized path', () => { |
| 85 | + cy.visit('/routes/client-only/prioritize/nested').waitForRouteChange() |
| 86 | + cy.get("[data-testid=title]").should("have.text", "client-only/prioritize matchpath") |
| 87 | + cy.get("[data-testid=params]").should("have.text", "nested") |
| 88 | + }) |
| 89 | +}) |
0 commit comments