2020-12-10 11:13:59 +00:00
|
|
|
import { render, screen } from '@testing-library/react'
|
2021-03-05 13:00:28 +00:00
|
|
|
import HotkeysModal from '../../../../../frontend/js/features/hotkeys-modal/components/hotkeys-modal'
|
2020-12-10 11:13:59 +00:00
|
|
|
import { expect } from 'chai'
|
2021-03-05 13:00:28 +00:00
|
|
|
import sinon from 'sinon'
|
2020-12-10 11:13:59 +00:00
|
|
|
|
2021-03-05 13:00:28 +00:00
|
|
|
const modalProps = {
|
|
|
|
show: true,
|
|
|
|
handleHide: sinon.stub(),
|
2021-04-27 07:52:58 +00:00
|
|
|
trackChangesVisible: false,
|
2020-12-10 11:13:59 +00:00
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:21 +00:00
|
|
|
describe('<HotkeysModal />', function () {
|
|
|
|
it('renders the translated modal title', async function () {
|
2021-03-05 13:00:28 +00:00
|
|
|
const { baseElement } = render(<HotkeysModal {...modalProps} />)
|
2020-12-10 11:13:59 +00:00
|
|
|
|
2021-03-05 13:00:28 +00:00
|
|
|
expect(baseElement.querySelector('.modal-title').textContent).to.equal(
|
2020-12-10 11:13:59 +00:00
|
|
|
'Hotkeys'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 13:17:21 +00:00
|
|
|
it('renders translated heading with embedded code', function () {
|
2021-03-05 13:00:28 +00:00
|
|
|
const { baseElement } = render(<HotkeysModal {...modalProps} />)
|
2020-12-10 11:13:59 +00:00
|
|
|
|
2021-03-05 13:00:28 +00:00
|
|
|
const results = baseElement.querySelectorAll('h3 code')
|
2020-12-10 11:13:59 +00:00
|
|
|
expect(results).to.have.length(1)
|
|
|
|
})
|
|
|
|
|
2021-04-14 13:17:21 +00:00
|
|
|
it('renders the hotkey descriptions', function () {
|
2021-03-05 13:00:28 +00:00
|
|
|
const { baseElement } = render(<HotkeysModal {...modalProps} />)
|
2020-12-10 11:13:59 +00:00
|
|
|
|
2021-03-05 13:00:28 +00:00
|
|
|
const hotkeys = baseElement.querySelectorAll(
|
|
|
|
'[data-test-selector="hotkey"]'
|
|
|
|
)
|
2020-12-10 11:13:59 +00:00
|
|
|
expect(hotkeys).to.have.length(19)
|
|
|
|
})
|
|
|
|
|
2021-04-14 13:17:21 +00:00
|
|
|
it('adds extra hotkey descriptions when Track Changes is enabled', function () {
|
2021-03-05 13:00:28 +00:00
|
|
|
const { baseElement } = render(
|
|
|
|
<HotkeysModal {...modalProps} trackChangesVisible />
|
2020-12-10 11:13:59 +00:00
|
|
|
)
|
|
|
|
|
2021-03-05 13:00:28 +00:00
|
|
|
const hotkeys = baseElement.querySelectorAll(
|
|
|
|
'[data-test-selector="hotkey"]'
|
|
|
|
)
|
2020-12-10 11:13:59 +00:00
|
|
|
expect(hotkeys).to.have.length(22)
|
|
|
|
})
|
|
|
|
|
2021-04-14 13:17:21 +00:00
|
|
|
it('uses Ctrl for non-macOS', function () {
|
2021-03-05 13:00:28 +00:00
|
|
|
render(<HotkeysModal {...modalProps} />)
|
2020-12-10 11:13:59 +00:00
|
|
|
|
2021-03-05 13:00:28 +00:00
|
|
|
expect(screen.getAllByText(/Ctrl/)).to.have.length(16)
|
2020-12-10 11:13:59 +00:00
|
|
|
expect(screen.queryByText(/Cmd/)).to.not.exist
|
|
|
|
})
|
|
|
|
|
2021-04-14 13:17:21 +00:00
|
|
|
it('uses Cmd for macOS', function () {
|
2021-03-05 13:00:28 +00:00
|
|
|
render(<HotkeysModal {...modalProps} isMac />)
|
2020-12-10 11:13:59 +00:00
|
|
|
|
2021-12-10 10:03:52 +00:00
|
|
|
expect(screen.getAllByText(/Cmd/)).to.have.length(12)
|
|
|
|
expect(screen.getAllByText(/Ctrl/)).to.have.length(4)
|
2020-12-10 11:13:59 +00:00
|
|
|
})
|
|
|
|
})
|