Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import React from 'react'; |
| 6 | import {render, screen, cleanup} from '@testing-library/react'; |
| 7 | import {assert} from 'chai'; |
| 8 | |
| 9 | import DotMobileStepper from './DotMobileStepper.tsx'; |
| 10 | |
| 11 | describe('DotMobileStepper', () => { |
| 12 | let container: HTMLElement; |
| 13 | |
| 14 | afterEach(cleanup); |
| 15 | |
| 16 | it('renders', () => { |
| 17 | container = render(<DotMobileStepper activeStep={0} nextEnabled={true}/>).container; |
| 18 | |
| 19 | // this is checking the buttons for the stepper rendered |
| 20 | const count = document.querySelectorAll('button').length; |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 21 | assert.equal(count, 1) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 22 | }); |
| 23 | |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 24 | it('back button not avlialbe on first step', () => { |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 25 | render(<DotMobileStepper activeStep={0} nextEnabled={true}/>).container; |
| 26 | |
| 27 | // Finds a button on the page with "back" as text using React testing library. |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 28 | const backButton = document.querySelector('[aria-label="backButton"]'); |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 29 | |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 30 | // Back button is not avliable on the first step. |
| 31 | assert.notExists(backButton); |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 32 | }); |
| 33 | |
| 34 | it('both buttons enabled on second step', () => { |
| 35 | render(<DotMobileStepper activeStep={1} nextEnabled={true}/>).container; |
| 36 | |
| 37 | // Finds a button on the page with "back" as text using React testing library. |
| 38 | const backButton = screen.getByRole('button', {name: /backButton/i}) as HTMLButtonElement; |
| 39 | |
| 40 | // Finds a button on the page with "next" as text using React testing library. |
| 41 | const nextButton = screen.getByRole('button', {name: /nextButton/i}) as HTMLButtonElement; |
| 42 | |
| 43 | // Back button is not disabled on the second step. |
| 44 | assert.isFalse(backButton.disabled); |
| 45 | |
| 46 | // Next button is not disabled on the second step. |
| 47 | assert.isFalse(nextButton.disabled); |
| 48 | }); |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 49 | }); |