blob: ce5e3a3b0dee3c2a068cb145db8d80f951c5d832 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2021 The Chromium Authors
Copybara854996b2021-09-07 19:36:02 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import React from 'react';
6import {render, screen, cleanup} from '@testing-library/react';
7import {assert} from 'chai';
8
9import DotMobileStepper from './DotMobileStepper.tsx';
10
11describe('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ínezac4a6442022-05-15 19:05:13 +020021 assert.equal(count, 1)
Copybara854996b2021-09-07 19:36:02 +000022 });
23
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020024 it('back button not avlialbe on first step', () => {
Copybara854996b2021-09-07 19:36:02 +000025 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ínezac4a6442022-05-15 19:05:13 +020028 const backButton = document.querySelector('[aria-label="backButton"]');
Copybara854996b2021-09-07 19:36:02 +000029
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020030 // Back button is not avliable on the first step.
31 assert.notExists(backButton);
Copybara854996b2021-09-07 19:36:02 +000032 });
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ínezac4a6442022-05-15 19:05:13 +020049});