2020-11-26 09:22:30 -05:00
|
|
|
import React from 'react'
|
|
|
|
import sinon from 'sinon'
|
2021-04-29 04:16:42 -04:00
|
|
|
import { expect } from 'chai'
|
2020-11-26 09:22:30 -05:00
|
|
|
import { screen, fireEvent } from '@testing-library/react'
|
|
|
|
import renderWithContext from '../../helpers/render-with-context'
|
|
|
|
|
|
|
|
import FileTreeitemMenu from '../../../../../../frontend/js/features/file-tree/components/file-tree-item/file-tree-item-menu'
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('<FileTreeitemMenu />', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
const setContextMenuCoords = sinon.stub()
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
afterEach(function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
setContextMenuCoords.reset()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders dropdown', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
renderWithContext(
|
|
|
|
<FileTreeitemMenu
|
|
|
|
id="123abc"
|
|
|
|
setContextMenuCoords={setContextMenuCoords}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
2021-04-29 04:16:42 -04:00
|
|
|
const toggleButton = screen.getByRole('button', { name: 'Menu' })
|
|
|
|
fireEvent.click(toggleButton)
|
|
|
|
|
2020-11-26 09:22:30 -05:00
|
|
|
screen.getByRole('menu')
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('open / close', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
renderWithContext(
|
|
|
|
<FileTreeitemMenu
|
|
|
|
id="123abc"
|
|
|
|
setContextMenuCoords={setContextMenuCoords}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
2021-04-29 04:16:42 -04:00
|
|
|
expect(screen.queryByRole('menu')).to.be.null
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2021-04-29 04:16:42 -04:00
|
|
|
const toggleButton = screen.getByRole('button', { name: 'Menu' })
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
fireEvent.click(toggleButton)
|
|
|
|
screen.getByRole('menu', { visible: true })
|
|
|
|
|
|
|
|
fireEvent.click(toggleButton)
|
|
|
|
screen.getByRole('menu', { visible: false })
|
|
|
|
})
|
|
|
|
})
|