|
| 1 | +import { expect, testStep } from '@epic-web/workshop-utils/test' |
| 2 | +import { render, screen } from '@testing-library/react' |
| 3 | +import { userEvent } from '@testing-library/user-event' |
| 4 | +import { App } from './app.tsx' |
| 5 | + |
| 6 | +await testStep('can render the app', () => { |
| 7 | + render(<App />) |
| 8 | +}) |
| 9 | + |
| 10 | +const toggle = await testStep('Toggle is rendered', () => |
| 11 | + screen.findByRole('switch', { name: /party mode/i }), |
| 12 | +) |
| 13 | + |
| 14 | +await testStep('Toggle is off to start', () => |
| 15 | + expect(toggle).to.have.attr('aria-checked', 'false'), |
| 16 | +) |
| 17 | + |
| 18 | +await testStep(`Renders "Sad town 😭" when off`, () => |
| 19 | + screen.findByText('Sad town 😭'), |
| 20 | +) |
| 21 | + |
| 22 | +await testStep(`Does not render "Let's party 🥳" when off`, () => { |
| 23 | + const textNode = screen.queryByText("Let's party 🥳") |
| 24 | + if (textNode) { |
| 25 | + expect(textNode).not.toBeVisible() |
| 26 | + } |
| 27 | +}) |
| 28 | + |
| 29 | +await userEvent.click(toggle) |
| 30 | + |
| 31 | +await testStep('Clicking the toggle turns it on', async () => { |
| 32 | + expect(toggle).to.have.attr('aria-checked', 'true') |
| 33 | +}) |
| 34 | + |
| 35 | +await testStep(`Renders "Let's party 🥳" when on`, () => |
| 36 | + screen.findByText("Let's party 🥳"), |
| 37 | +) |
| 38 | + |
| 39 | +await testStep('Does not render "Sad town 😭" when on', () => { |
| 40 | + const textNode = screen.queryByText('Sad town 😭') |
| 41 | + if (textNode) { |
| 42 | + expect(textNode).not.toBeVisible() |
| 43 | + } |
| 44 | +}) |
| 45 | + |
| 46 | +const textField = await testStep('TextField is rendered', () => |
| 47 | + screen.findByLabelText('Venue'), |
| 48 | +) |
| 49 | + |
| 50 | +await testStep('TextField label and input are associated', () => { |
| 51 | + const label = screen.getByText('Venue') |
| 52 | + expect(label).to.have.attr('for', textField.id) |
| 53 | +}) |
0 commit comments