|
| 1 | +import React from 'react'; |
| 2 | +import PlayArrowIcon from '@mui/icons-material/PlayArrow'; |
| 3 | +import { ThemeProvider, createTheme } from '@mui/material/styles'; |
| 4 | +import HighlightButton from './HighlightButton'; |
| 5 | + |
| 6 | +const mountHighlightButton = ({ |
| 7 | + disabled = false, |
| 8 | + highlight = false, |
| 9 | + size = 'medium', |
| 10 | +}: { |
| 11 | + disabled?: boolean; |
| 12 | + highlight?: boolean; |
| 13 | + size?: 'small' | 'medium' | 'large'; |
| 14 | +} = {}) => { |
| 15 | + const onClick = cy.stub().as('onClick'); |
| 16 | + const theme = createTheme(); |
| 17 | + |
| 18 | + cy.mount( |
| 19 | + <ThemeProvider theme={theme}> |
| 20 | + <HighlightButton |
| 21 | + ariaLabel="Play highlight" |
| 22 | + onClick={onClick} |
| 23 | + disabled={disabled} |
| 24 | + size={size} |
| 25 | + highlight={highlight} |
| 26 | + > |
| 27 | + <PlayArrowIcon data-cy="highlight-icon" /> |
| 28 | + </HighlightButton> |
| 29 | + </ThemeProvider> |
| 30 | + ); |
| 31 | +}; |
| 32 | + |
| 33 | +describe('HighlightButton', () => { |
| 34 | + it('renders the button with child content', () => { |
| 35 | + mountHighlightButton(); |
| 36 | + |
| 37 | + cy.get('[aria-label="Play highlight"]').should('exist'); |
| 38 | + cy.get('[data-cy="highlight-icon"]').should('be.visible'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('invokes onClick when enabled', () => { |
| 42 | + mountHighlightButton(); |
| 43 | + |
| 44 | + cy.get('[aria-label="Play highlight"]').click(); |
| 45 | + cy.get('@onClick').should('have.been.calledOnce'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('does not invoke onClick when disabled', () => { |
| 49 | + mountHighlightButton({ disabled: true }); |
| 50 | + |
| 51 | + cy.get('[aria-label="Play highlight"]').should('be.disabled').click({ |
| 52 | + force: true, |
| 53 | + }); |
| 54 | + cy.get('@onClick').should('not.have.been.called'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('applies highlight colors when enabled', () => { |
| 58 | + mountHighlightButton({ highlight: true }); |
| 59 | + |
| 60 | + cy.get('[aria-label="Play highlight"]') |
| 61 | + .should('have.css', 'background-color', 'rgb(25, 118, 210)') |
| 62 | + .and('have.css', 'color', 'rgb(255, 255, 255)'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('applies the size class based on prop', () => { |
| 66 | + mountHighlightButton({ size: 'small' }); |
| 67 | + |
| 68 | + cy.get('[aria-label="Play highlight"]').should( |
| 69 | + 'have.class', |
| 70 | + 'MuiIconButton-sizeSmall' |
| 71 | + ); |
| 72 | + }); |
| 73 | +}); |
0 commit comments