Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/grid-ui/src/tests/components/TopBar.test.tsx
2887 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
import * as React from 'react'
19
import TopBar from '../../components/TopBar/TopBar'
20
import { render, screen } from '@testing-library/react'
21
import userEvent from '@testing-library/user-event'
22
23
const user = userEvent.setup()
24
25
it('renders basic information', () => {
26
const subheaderText = 'Hello, world!'
27
const handleClick = jest.fn()
28
render(<TopBar subheader={subheaderText} drawerOpen
29
toggleDrawer={handleClick}/>)
30
expect(screen.getByText('Selenium Grid')).toBeInTheDocument()
31
expect(screen.getByRole('img')).toHaveAttribute('alt', 'Selenium Grid Logo')
32
expect(screen.getByText(subheaderText)).toBeInTheDocument()
33
})
34
35
it('can toggle drawer if error flag is not set and the drawer is open',
36
async () => {
37
const handleClick = jest.fn()
38
render(<TopBar subheader="4.0.0" drawerOpen toggleDrawer={handleClick}/>)
39
const button = screen.getByRole('button')
40
expect(button.getAttribute('aria-label')).toBe('close drawer')
41
await user.click(button)
42
expect(handleClick).toHaveBeenCalledTimes(1)
43
})
44
45
it('can toggle drawer if error flag is not set and the drawer is closed',
46
async () => {
47
const handleClick = jest.fn()
48
render(<TopBar subheader="4.0.0" toggleDrawer={handleClick}/>)
49
const button = screen.getByRole('button')
50
expect(button.getAttribute('aria-label')).toBe('open drawer')
51
await user.click(button)
52
expect(handleClick).toHaveBeenCalledTimes(1)
53
})
54
55
it('should not toggle drawer if error flag is set', async () => {
56
const handleClick = jest.fn()
57
render(<TopBar subheader="4.0.0" error toggleDrawer={handleClick}/>)
58
expect(screen.queryByRole('button')).not.toBeInTheDocument()
59
const link = screen.getByRole('link')
60
expect(link.getAttribute('href')).toBe('#help')
61
await user.click(link)
62
expect(handleClick).toHaveBeenCalledTimes(0)
63
})
64
65