blob: b25baeacfdc9b0c670f7f903f5052c8a576bccbb [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} from '@testing-library/react';
7import userEvent from '@testing-library/user-event';
8import {screen} from '@testing-library/dom';
9import {assert} from 'chai';
10
11import SelectMenu from './SelectMenu.tsx';
12
13describe('SelectMenu', () => {
14 let container: React.RenderResult;
15
16 beforeEach(() => {
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020017 container = render(<SelectMenu optionsList = {['op1', 'op2']} />).container;
Copybara854996b2021-09-07 19:36:02 +000018 });
19
20 it('renders', () => {
21 const form = container.querySelector('form');
22 assert.isNotNull(form)
23 });
24
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020025 it('renders options on click', async () => {
Copybara854996b2021-09-07 19:36:02 +000026 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ínezac4a6442022-05-15 19:05:13 +020034 const count = (await screen.findAllByTestId('select-menu-item')).length;
Copybara854996b2021-09-07 19:36:02 +000035
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020036 assert.equal(count, 2);
Copybara854996b2021-09-07 19:36:02 +000037 });
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020038});