blob: 52031109575f81d1053cb1e719ef750ae4bb4d98 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2021 The Chromium Authors. All rights reserved.
2// 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;
21 assert.equal(count, 2)
22 });
23
24 it('back button disabled on first step', () => {
25 render(<DotMobileStepper activeStep={0} nextEnabled={true}/>).container;
26
27 // Finds a button on the page with "back" as text using React testing library.
28 const backButton = screen.getByRole('button', {name: /backButton/i}) as HTMLButtonElement;
29
30 // Back button is disabled on the first step.
31 assert.isTrue(backButton.disabled);
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 });
49
50 it('next button disabled on last step', () => {
51 render(<DotMobileStepper activeStep={2}/>).container;
52
53 // Finds a button on the page with "next" as text using React testing library.
54 const nextButton = screen.getByRole('button', {name: /nextButton/i}) as HTMLButtonElement;
55
56 // Next button is disabled on the second step.
57 assert.isTrue(nextButton.disabled);
58 });
59});