|
| 1 | +describe('Code Tabs', () => { |
| 2 | + beforeEach(() => { |
| 3 | + // Visit a page with code tabs |
| 4 | + cy.visit('/quickstart'); |
| 5 | + }); |
| 6 | + |
| 7 | + it('should display tab list with multiple options', () => { |
| 8 | + cy.get('[role="tablist"]').should('exist'); |
| 9 | + cy.get('[role="tab"]').should('have.length.at.least', 2); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should have first tab selected by default', () => { |
| 13 | + cy.get('[role="tab"]').first().should('have.attr', 'aria-selected', 'true'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should switch tab content when clicking different tab', () => { |
| 17 | + // Get the tabs |
| 18 | + cy.get('[role="tablist"]') |
| 19 | + .first() |
| 20 | + .within(() => { |
| 21 | + cy.get('[role="tab"]').then(($tabs) => { |
| 22 | + if ($tabs.length >= 2) { |
| 23 | + // Click second tab |
| 24 | + cy.wrap($tabs[1]).click(); |
| 25 | + // Second tab should now be selected |
| 26 | + cy.wrap($tabs[1]).should('have.attr', 'aria-selected', 'true'); |
| 27 | + // First tab should be deselected |
| 28 | + cy.wrap($tabs[0]).should('have.attr', 'aria-selected', 'false'); |
| 29 | + } |
| 30 | + }); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should show corresponding content for selected tab', () => { |
| 35 | + cy.get('[role="tablist"]') |
| 36 | + .first() |
| 37 | + .within(() => { |
| 38 | + cy.get('[role="tab"]').then(($tabs) => { |
| 39 | + if ($tabs.length >= 2) { |
| 40 | + // Get text of second tab |
| 41 | + const tabText = $tabs[1].textContent; |
| 42 | + // Click it |
| 43 | + cy.wrap($tabs[1]).click(); |
| 44 | + } |
| 45 | + }); |
| 46 | + }); |
| 47 | + // Tab panel should be visible |
| 48 | + cy.get('[role="tabpanel"]').should('be.visible'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should maintain tab selection after scrolling', () => { |
| 52 | + cy.get('[role="tablist"]') |
| 53 | + .first() |
| 54 | + .within(() => { |
| 55 | + cy.get('[role="tab"]').eq(1).click(); |
| 56 | + cy.get('[role="tab"]') |
| 57 | + .eq(1) |
| 58 | + .should('have.attr', 'aria-selected', 'true'); |
| 59 | + }); |
| 60 | + // Scroll down and back up |
| 61 | + cy.scrollTo('bottom'); |
| 62 | + cy.scrollTo('top'); |
| 63 | + // Tab should still be selected |
| 64 | + cy.get('[role="tablist"]') |
| 65 | + .first() |
| 66 | + .within(() => { |
| 67 | + cy.get('[role="tab"]') |
| 68 | + .eq(1) |
| 69 | + .should('have.attr', 'aria-selected', 'true'); |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
| 73 | + |
| 74 | +describe('Code Blocks', () => { |
| 75 | + beforeEach(() => { |
| 76 | + cy.visit('/quickstart'); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should display code blocks with syntax highlighting', () => { |
| 80 | + cy.get('pre code, .astro-code').should('have.length.at.least', 1); |
| 81 | + }); |
| 82 | + |
| 83 | + it('should have copy button on code blocks', () => { |
| 84 | + // Starlight adds copy buttons to code blocks |
| 85 | + cy.get('pre').first().realHover |
| 86 | + ? cy.get('pre').first().realHover() |
| 87 | + : cy.get('pre').first().trigger('mouseenter'); |
| 88 | + // Look for copy button (Starlight uses data-copy-button or similar) |
| 89 | + cy.get('button[data-copy], .copy-button, button:has(svg)').should('exist'); |
| 90 | + }); |
| 91 | +}); |
0 commit comments