|
| 1 | +const port = 3000; |
| 2 | + |
| 3 | +/** |
| 4 | + * Tests for relative links within nested IonRouterOutlet components. |
| 5 | + * |
| 6 | + * This specifically tests the scenario where: |
| 7 | + * 1. IonRouterOutlet has a catch-all route (*) containing IonTabs |
| 8 | + * 2. Inside tabs, there's another outlet with nested routes using index routes |
| 9 | + * 3. React Router's <Link to="relative"> is used for navigation |
| 10 | + * |
| 11 | + * The expected behavior is: |
| 12 | + * - <Link to="page-a"> at /nested-tabs-relative-links/tab1 should produce |
| 13 | + * href="/nested-tabs-relative-links/tab1/page-a" (not /tab1/tab1/page-a) |
| 14 | + * - <Link to="/nested-tabs-relative-links/tab1/page-a"> should work and not 404 |
| 15 | + */ |
| 16 | +describe('Nested Tabs with Relative Links', () => { |
| 17 | + it('should navigate to tab1 by default', () => { |
| 18 | + cy.visit(`http://localhost:${port}/nested-tabs-relative-links`); |
| 19 | + cy.ionPageVisible('nested-tabs-relative-tab1'); |
| 20 | + cy.get('[data-testid="tab1-content"]').should('exist'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should have correct href for relative link', () => { |
| 24 | + cy.visit(`http://localhost:${port}/nested-tabs-relative-links/tab1`); |
| 25 | + cy.ionPageVisible('nested-tabs-relative-tab1'); |
| 26 | + |
| 27 | + // Check that the relative link has the correct href |
| 28 | + // It should be /nested-tabs-relative-links/tab1/page-a, NOT /tab1/tab1/page-a |
| 29 | + cy.get('[data-testid="link-relative-page-a"]') |
| 30 | + .should('have.attr', 'href', '/nested-tabs-relative-links/tab1/page-a'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should navigate to Page A via relative link', () => { |
| 34 | + cy.visit(`http://localhost:${port}/nested-tabs-relative-links/tab1`); |
| 35 | + cy.ionPageVisible('nested-tabs-relative-tab1'); |
| 36 | + |
| 37 | + // Click the relative link |
| 38 | + cy.get('[data-testid="link-relative-page-a"]').click(); |
| 39 | + |
| 40 | + // Should be at Page A |
| 41 | + cy.ionPageVisible('nested-tabs-relative-page-a'); |
| 42 | + cy.get('[data-testid="page-a-content"]').should('exist'); |
| 43 | + |
| 44 | + // URL should be correct |
| 45 | + cy.url().should('include', '/nested-tabs-relative-links/tab1/page-a'); |
| 46 | + // URL should NOT have duplicate path segments |
| 47 | + cy.url().should('not.include', '/tab1/tab1/'); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should navigate to Page A via absolute link', () => { |
| 51 | + cy.visit(`http://localhost:${port}/nested-tabs-relative-links/tab1`); |
| 52 | + cy.ionPageVisible('nested-tabs-relative-tab1'); |
| 53 | + |
| 54 | + // Click the absolute link |
| 55 | + cy.get('[data-testid="link-absolute-page-a"]').click(); |
| 56 | + |
| 57 | + // Should be at Page A (not 404) |
| 58 | + cy.ionPageVisible('nested-tabs-relative-page-a'); |
| 59 | + cy.get('[data-testid="page-a-content"]').should('exist'); |
| 60 | + |
| 61 | + // Should NOT show 404 |
| 62 | + cy.get('[data-testid="not-found"]').should('not.exist'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should navigate to Page B via relative link', () => { |
| 66 | + cy.visit(`http://localhost:${port}/nested-tabs-relative-links/tab1`); |
| 67 | + cy.ionPageVisible('nested-tabs-relative-tab1'); |
| 68 | + |
| 69 | + // Click the relative link to page B |
| 70 | + cy.get('[data-testid="link-relative-page-b"]').click(); |
| 71 | + |
| 72 | + // Should be at Page B |
| 73 | + cy.ionPageVisible('nested-tabs-relative-page-b'); |
| 74 | + cy.get('[data-testid="page-b-content"]').should('exist'); |
| 75 | + |
| 76 | + // URL should be correct |
| 77 | + cy.url().should('include', '/nested-tabs-relative-links/tab1/page-b'); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should navigate to Page A and back', () => { |
| 81 | + cy.visit(`http://localhost:${port}/nested-tabs-relative-links/tab1`); |
| 82 | + cy.ionPageVisible('nested-tabs-relative-tab1'); |
| 83 | + |
| 84 | + // Navigate to Page A |
| 85 | + cy.get('[data-testid="link-relative-page-a"]').click(); |
| 86 | + cy.ionPageVisible('nested-tabs-relative-page-a'); |
| 87 | + |
| 88 | + // Go back |
| 89 | + cy.ionBackClick('nested-tabs-relative-page-a'); |
| 90 | + |
| 91 | + // Should be back at Tab 1 |
| 92 | + cy.ionPageVisible('nested-tabs-relative-tab1'); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should directly visit Page A via URL', () => { |
| 96 | + cy.visit(`http://localhost:${port}/nested-tabs-relative-links/tab1/page-a`); |
| 97 | + |
| 98 | + // Should be at Page A (not 404) |
| 99 | + cy.ionPageVisible('nested-tabs-relative-page-a'); |
| 100 | + cy.get('[data-testid="page-a-content"]').should('exist'); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should switch tabs and maintain correct relative link resolution', () => { |
| 104 | + cy.visit(`http://localhost:${port}/nested-tabs-relative-links/tab1`); |
| 105 | + cy.ionPageVisible('nested-tabs-relative-tab1'); |
| 106 | + |
| 107 | + // Switch to Tab 2 |
| 108 | + cy.ionTabClick('Tab 2'); |
| 109 | + cy.ionPageVisible('nested-tabs-relative-tab2'); |
| 110 | + |
| 111 | + // Switch back to Tab 1 |
| 112 | + cy.ionTabClick('Tab 1'); |
| 113 | + cy.ionPageVisible('nested-tabs-relative-tab1'); |
| 114 | + |
| 115 | + // The relative link should still have correct href |
| 116 | + cy.get('[data-testid="link-relative-page-a"]') |
| 117 | + .should('have.attr', 'href', '/nested-tabs-relative-links/tab1/page-a'); |
| 118 | + }); |
| 119 | +}); |
0 commit comments