Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | // 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 | |
| 5 | import React from 'react'; |
| 6 | import {render} from '@testing-library/react'; |
| 7 | import userEvent from '@testing-library/user-event'; |
| 8 | import {screen} from '@testing-library/dom'; |
| 9 | import {assert} from 'chai'; |
| 10 | |
| 11 | import SelectMenu from './SelectMenu.tsx'; |
| 12 | |
| 13 | describe('SelectMenu', () => { |
| 14 | let container: React.RenderResult; |
| 15 | |
| 16 | beforeEach(() => { |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 17 | container = render(<SelectMenu optionsList = {['op1', 'op2']} />).container; |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 18 | }); |
| 19 | |
| 20 | it('renders', () => { |
| 21 | const form = container.querySelector('form'); |
| 22 | assert.isNotNull(form) |
| 23 | }); |
| 24 | |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 25 | it('renders options on click', async () => { |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 26 | const input = document.getElementById('outlined-select-category'); |
| 27 | if (!input) { |
| 28 | throw new Error('Input is undefined'); |
| 29 | } |
| 30 | |
| 31 | userEvent.click(input) |
| 32 | |
| 33 | // 14 is the current number of options in the select menu |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 34 | const count = (await screen.findAllByTestId('select-menu-item')).length; |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 35 | |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 36 | assert.equal(count, 2); |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 37 | }); |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 38 | }); |