|
| 1 | +const port = 3000; |
| 2 | + |
| 3 | +/** |
| 4 | + * Tests for index route reuse across tabs with nested outlets. |
| 5 | + * |
| 6 | + * Validates that switching between tabs where each has its own nested |
| 7 | + * IonRouterOutlet with an index route correctly shows the right content. |
| 8 | + * This tests whether createViewItem's index route reuse check |
| 9 | + * (existingIsIndexRoute && newIsIndexRoute) causes issues when multiple |
| 10 | + * outlets each have their own index routes. |
| 11 | + */ |
| 12 | +describe('Index Route Reuse - Nested Outlet Index Routes', () => { |
| 13 | + it('should show tab1 index content by default', () => { |
| 14 | + cy.visit(`http://localhost:${port}/index-route-reuse`); |
| 15 | + cy.ionPageVisible('irr-tab1-home'); |
| 16 | + cy.get('[data-testid="irr-tab1-home-content"]').should('be.visible'); |
| 17 | + cy.get('[data-testid="irr-tab1-home-content"]').should('contain', 'Tab 1 Index Route Content'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should show tab2 index content when switching to tab2', () => { |
| 21 | + cy.visit(`http://localhost:${port}/index-route-reuse/tab1`); |
| 22 | + cy.ionPageVisible('irr-tab1-home'); |
| 23 | + |
| 24 | + // Switch to Tab 2 |
| 25 | + cy.ionTabClick('Tab 2'); |
| 26 | + cy.ionPageVisible('irr-tab2-home'); |
| 27 | + cy.get('[data-testid="irr-tab2-home-content"]').should('be.visible'); |
| 28 | + cy.get('[data-testid="irr-tab2-home-content"]').should('contain', 'Tab 2 Index Route Content'); |
| 29 | + |
| 30 | + // Verify URL changed to tab2 |
| 31 | + cy.url().should('include', '/index-route-reuse/tab2'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should show tab3 index content when switching to tab3', () => { |
| 35 | + cy.visit(`http://localhost:${port}/index-route-reuse/tab1`); |
| 36 | + cy.ionPageVisible('irr-tab1-home'); |
| 37 | + |
| 38 | + // Switch to Tab 3 |
| 39 | + cy.ionTabClick('Tab 3'); |
| 40 | + cy.ionPageVisible('irr-tab3-home'); |
| 41 | + cy.get('[data-testid="irr-tab3-home-content"]').should('be.visible'); |
| 42 | + cy.get('[data-testid="irr-tab3-home-content"]').should('contain', 'Tab 3 Index Route Content'); |
| 43 | + |
| 44 | + // Verify URL changed to tab3 |
| 45 | + cy.url().should('include', '/index-route-reuse/tab3'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should correctly show each tab index when cycling through all tabs', () => { |
| 49 | + cy.visit(`http://localhost:${port}/index-route-reuse/tab1`); |
| 50 | + cy.ionPageVisible('irr-tab1-home'); |
| 51 | + cy.get('[data-testid="irr-tab1-home-content"]').should('be.visible'); |
| 52 | + |
| 53 | + // Tab 1 -> Tab 2 |
| 54 | + cy.ionTabClick('Tab 2'); |
| 55 | + cy.ionPageVisible('irr-tab2-home'); |
| 56 | + cy.get('[data-testid="irr-tab2-home-content"]').should('be.visible'); |
| 57 | + cy.get('[data-testid="irr-tab2-home-content"]').should('contain', 'Tab 2 Index Route Content'); |
| 58 | + |
| 59 | + // Tab 2 -> Tab 3 |
| 60 | + cy.ionTabClick('Tab 3'); |
| 61 | + cy.ionPageVisible('irr-tab3-home'); |
| 62 | + cy.get('[data-testid="irr-tab3-home-content"]').should('be.visible'); |
| 63 | + cy.get('[data-testid="irr-tab3-home-content"]').should('contain', 'Tab 3 Index Route Content'); |
| 64 | + |
| 65 | + // Tab 3 -> Tab 1 (back to start) |
| 66 | + cy.ionTabClick('Tab 1'); |
| 67 | + cy.ionPageVisible('irr-tab1-home'); |
| 68 | + cy.get('[data-testid="irr-tab1-home-content"]').should('be.visible'); |
| 69 | + cy.get('[data-testid="irr-tab1-home-content"]').should('contain', 'Tab 1 Index Route Content'); |
| 70 | + }); |
| 71 | + |
| 72 | + it('should preserve tab1 detail navigation and return correctly', () => { |
| 73 | + cy.visit(`http://localhost:${port}/index-route-reuse/tab1`); |
| 74 | + cy.ionPageVisible('irr-tab1-home'); |
| 75 | + |
| 76 | + // Navigate to detail page |
| 77 | + cy.get('#irr-tab1-detail-btn').click(); |
| 78 | + cy.ionPageVisible('irr-tab1-detail'); |
| 79 | + cy.get('[data-testid="irr-tab1-detail-content"]').should('be.visible'); |
| 80 | + |
| 81 | + // Switch to Tab 2 |
| 82 | + cy.ionTabClick('Tab 2'); |
| 83 | + cy.ionPageVisible('irr-tab2-home'); |
| 84 | + cy.get('[data-testid="irr-tab2-home-content"]').should('be.visible'); |
| 85 | + |
| 86 | + // Switch back to Tab 1 - should show detail (preserved history) |
| 87 | + cy.ionTabClick('Tab 1'); |
| 88 | + cy.ionPageVisible('irr-tab1-detail'); |
| 89 | + cy.get('[data-testid="irr-tab1-detail-content"]').should('be.visible'); |
| 90 | + }); |
| 91 | + |
| 92 | + it('should show correct content after rapid tab switching', () => { |
| 93 | + cy.visit(`http://localhost:${port}/index-route-reuse/tab1`); |
| 94 | + cy.ionPageVisible('irr-tab1-home'); |
| 95 | + |
| 96 | + // Rapid switching: Tab1 -> Tab2 -> Tab3 -> Tab2 -> Tab1 |
| 97 | + cy.ionTabClick('Tab 2'); |
| 98 | + cy.ionPageVisible('irr-tab2-home'); |
| 99 | + |
| 100 | + cy.ionTabClick('Tab 3'); |
| 101 | + cy.ionPageVisible('irr-tab3-home'); |
| 102 | + |
| 103 | + cy.ionTabClick('Tab 2'); |
| 104 | + cy.ionPageVisible('irr-tab2-home'); |
| 105 | + cy.get('[data-testid="irr-tab2-home-content"]').should('be.visible'); |
| 106 | + cy.get('[data-testid="irr-tab2-home-content"]').should('contain', 'Tab 2 Index Route Content'); |
| 107 | + |
| 108 | + cy.ionTabClick('Tab 1'); |
| 109 | + cy.ionPageVisible('irr-tab1-home'); |
| 110 | + cy.get('[data-testid="irr-tab1-home-content"]').should('be.visible'); |
| 111 | + cy.get('[data-testid="irr-tab1-home-content"]').should('contain', 'Tab 1 Index Route Content'); |
| 112 | + }); |
| 113 | +}); |
0 commit comments