Path: blob/trunk/javascript/grid-ui/src/tests/components/TopBar.test.tsx
2887 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617import * as React from 'react'18import TopBar from '../../components/TopBar/TopBar'19import { render, screen } from '@testing-library/react'20import userEvent from '@testing-library/user-event'2122const user = userEvent.setup()2324it('renders basic information', () => {25const subheaderText = 'Hello, world!'26const handleClick = jest.fn()27render(<TopBar subheader={subheaderText} drawerOpen28toggleDrawer={handleClick}/>)29expect(screen.getByText('Selenium Grid')).toBeInTheDocument()30expect(screen.getByRole('img')).toHaveAttribute('alt', 'Selenium Grid Logo')31expect(screen.getByText(subheaderText)).toBeInTheDocument()32})3334it('can toggle drawer if error flag is not set and the drawer is open',35async () => {36const handleClick = jest.fn()37render(<TopBar subheader="4.0.0" drawerOpen toggleDrawer={handleClick}/>)38const button = screen.getByRole('button')39expect(button.getAttribute('aria-label')).toBe('close drawer')40await user.click(button)41expect(handleClick).toHaveBeenCalledTimes(1)42})4344it('can toggle drawer if error flag is not set and the drawer is closed',45async () => {46const handleClick = jest.fn()47render(<TopBar subheader="4.0.0" toggleDrawer={handleClick}/>)48const button = screen.getByRole('button')49expect(button.getAttribute('aria-label')).toBe('open drawer')50await user.click(button)51expect(handleClick).toHaveBeenCalledTimes(1)52})5354it('should not toggle drawer if error flag is set', async () => {55const handleClick = jest.fn()56render(<TopBar subheader="4.0.0" error toggleDrawer={handleClick}/>)57expect(screen.queryByRole('button')).not.toBeInTheDocument()58const link = screen.getByRole('link')59expect(link.getAttribute('href')).toBe('#help')60await user.click(link)61expect(handleClick).toHaveBeenCalledTimes(0)62})636465