A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.
TypeScript amazon-primeelectronepic-games-launcherepic-games-storeepic-storegaminggoggog-galaxyheroic-games-launcherlinuxplay-gamesprotonsteamwine
/**
* @jest-environment jsdom
*/
import { fireEvent, render, screen } from '@testing-library/react'
import ContextMenu, { type Item } from '../index'
jest.mock('../index.css', () => ({}))
const makeItem = (overrides: Partial<Item> = {}): Item => ({
icon: <span />,
label: 'Copy',
onclick: jest.fn(),
show: true,
...overrides
})
describe('ContextMenu', () => {
it('does not intercept the event when no item is visible', () => {
const { container } = render(
<ContextMenu items={[makeItem({ show: false })]}>
<div>selectable log</div>
</ContextMenu>
)
expect(fireEvent.contextMenu(screen.getByText('selectable log'))).toBe(true)
expect(screen.queryByText('Copy')).toBeNull()
expect((container.firstElementChild as HTMLElement).style.cursor).toBe('')
})
it('opens the menu and calls the action when an item is visible', () => {
const onclick = jest.fn()
render(
<ContextMenu items={[makeItem({ onclick })]}>
<div>selectable log</div>
</ContextMenu>
)
expect(fireEvent.contextMenu(screen.getByText('selectable log'))).toBe(
false
)
fireEvent.click(screen.getByText('Copy'))
expect(onclick).toHaveBeenCalledTimes(1)
})
})