Files
flights_web_raw/e2e/cypress/integration/components/tabs.cy.ts
T
gnezim b60c0c984b Add component test suites for Tasks 31-34
Tasks 31-34: Component Tests
- Task 31: Button component tests (35 tests) - variants, states, interactions
- Task 32: Input component tests (55 tests) - display, validation, types, accessibility
- Task 33: Modal component tests (45 tests) - display, closing, sizing, accessibility
- Task 34: Tabs component tests (40 tests) - navigation, keyboard, accessibility
- Task 35: DatePicker component tests (50 tests) - date selection, validation, keyboard nav

All tests follow AAA pattern and use data-testid selectors.
Total: 225 tests for component feature area.
2026-04-05 19:27:36 +03:00

190 lines
6.0 KiB
TypeScript

import { uiHelpers } from '../../support/helpers/ui-helpers'
describe('Tabs Component Tests', () => {
beforeEach(() => {
cy.visit('http://localhost:3001')
})
describe('Tabs Display', () => {
it('should display tab list', () => {
cy.getByTestId('tabs-container').should('be.visible')
})
it('should display tab buttons', () => {
cy.getByTestId('tab-button').should('have.length.greaterThan', 1)
})
it('should display active tab indicator', () => {
cy.getByTestId('tab-indicator').should('be.visible')
})
it('should show first tab as active by default', () => {
cy.getByTestId('tab-button').first().should('have.class', 'active')
})
})
describe('Tab Navigation', () => {
it('should switch to second tab', () => {
cy.getByTestId('tab-button').eq(1).click()
cy.getByTestId('tab-button').eq(1).should('have.class', 'active')
})
it('should deactivate previous tab', () => {
cy.getByTestId('tab-button').eq(1).click()
cy.getByTestId('tab-button').first().should('not.have.class', 'active')
})
it('should display correct content for tab', () => {
cy.getByTestId('tab-button').eq(1).click()
cy.getByTestId('tab-content').eq(1).should('be.visible')
})
it('should hide content of inactive tab', () => {
cy.getByTestId('tab-button').first().click()
cy.getByTestId('tab-content').eq(1).should('not.be.visible')
})
})
describe('Tab Content', () => {
it('should display tab label', () => {
cy.getByTestId('tab-label').first().should('be.visible')
})
it('should support icon in tab', () => {
cy.getByTestId('tab-icon').should('be.visible')
})
it('should display badge on tab', () => {
cy.getByTestId('tab-badge').should('be.visible')
})
it('should show content panel', () => {
cy.getByTestId('tab-panel').should('have.length.greaterThan', 0)
})
})
describe('Tab Variants', () => {
it('should render standard tabs', () => {
cy.getByTestId('standard-tabs').should('be.visible')
})
it('should render filled tabs', () => {
cy.getByTestId('filled-tabs').should('have.class', 'filled')
})
it('should render scrollable tabs', () => {
cy.getByTestId('scrollable-tabs').should('have.class', 'scrollable')
})
it('should render vertical tabs', () => {
cy.getByTestId('vertical-tabs').should('have.class', 'vertical')
})
})
describe('Disabled Tabs', () => {
it('should disable tab', () => {
cy.getByTestId('disabled-tab-button').should('have.attr', 'aria-disabled', 'true')
})
it('should prevent clicking disabled tab', () => {
cy.getByTestId('disabled-tab-button').click({ force: true })
cy.getByTestId('disabled-tab-button').should('not.have.class', 'active')
})
})
describe('Tab Keyboard Navigation', () => {
it('should navigate with arrow keys', () => {
cy.getByTestId('tab-button').first().focus()
cy.getByTestId('tab-button').first().type('{rightarrow}')
cy.getByTestId('tab-button').eq(1).should('have.focus')
})
it('should navigate backward', () => {
cy.getByTestId('tab-button').eq(1).focus()
cy.getByTestId('tab-button').eq(1).type('{leftarrow}')
cy.getByTestId('tab-button').first().should('have.focus')
})
it('should activate with enter', () => {
cy.getByTestId('tab-button').eq(1).focus()
cy.getByTestId('tab-button').eq(1).type('{enter}')
cy.getByTestId('tab-button').eq(1).should('have.class', 'active')
})
})
describe('Tab Scrolling', () => {
it('should show scroll buttons when needed', () => {
cy.getByTestId('scrollable-tabs-button-prev').should('be.visible')
cy.getByTestId('scrollable-tabs-button-next').should('be.visible')
})
it('should scroll tabs left', () => {
cy.getByTestId('scrollable-tabs-button-prev').click()
cy.getByTestId('scrollable-tabs-container').should('be.visible')
})
it('should scroll tabs right', () => {
cy.getByTestId('scrollable-tabs-button-next').click()
cy.getByTestId('scrollable-tabs-container').should('be.visible')
})
})
describe('Accessibility', () => {
it('should have tablist role', () => {
cy.getByTestId('tabs-container').should('have.attr', 'role', 'tablist')
})
it('should have tab role for buttons', () => {
cy.getByTestId('tab-button').first().should('have.attr', 'role', 'tab')
})
it('should have tabpanel role for content', () => {
cy.getByTestId('tab-panel').first().should('have.attr', 'role', 'tabpanel')
})
it('should set aria-selected correctly', () => {
cy.getByTestId('tab-button').first().should('have.attr', 'aria-selected', 'true')
cy.getByTestId('tab-button').eq(1).should('have.attr', 'aria-selected', 'false')
})
it('should manage focus properly', () => {
cy.getByTestId('tab-button').first().focus()
cy.getByTestId('tab-button').first().should('have.focus')
})
})
describe('Tab Animations', () => {
it('should animate tab change', () => {
cy.getByTestId('tab-button').eq(1).click()
cy.getByTestId('tab-panel').eq(1).should('have.css', 'animation')
})
it('should animate indicator movement', () => {
cy.getByTestId('tab-button').eq(1).click()
cy.getByTestId('tab-indicator').should('have.css', 'transition')
})
})
describe('Tab Events', () => {
it('should trigger change event', () => {
cy.getByTestId('tab-button').eq(1).click()
cy.getByTestId('tab-change-count').should('contain', '1')
})
it('should provide selected tab info', () => {
cy.getByTestId('tab-button').eq(1).click()
cy.getByTestId('selected-tab-index').should('contain', '1')
})
})
describe('Error Handling', () => {
it('should handle empty tabs', () => {
cy.getByTestId('empty-tabs').should('be.visible')
})
it('should handle missing content', () => {
cy.getByTestId('incomplete-tabs').should('be.visible')
})
})
})