overleaf/services/web/test/frontend/features/hotkeys-modal/components/hotkeys-modal.test.js
M Fahru 6dcc22642a Update "go to line" hotkey for cm6 and add new info text in hotkeys modal
* Update "go to line" hotkey for cm6 and add new info text in hotkeys modal

* Differentiate modal title between cm6 and ace hotkeys

* Update test to reflect change in hotkeys modal title

* Add test for hotkeys modal bottom text

* Update test on editor left menu hotkeys button to reflect change in hotkeys modal title

GitOrigin-RevId: 61bae16313ea7a37fa3b9441dbe5a93ab7823d01
2022-11-25 09:04:20 +00:00

73 lines
2.1 KiB
JavaScript

import { render, screen } from '@testing-library/react'
import HotkeysModal from '../../../../../frontend/js/features/hotkeys-modal/components/hotkeys-modal'
import { expect } from 'chai'
import sinon from 'sinon'
const modalProps = {
show: true,
handleHide: sinon.stub(),
trackChangesVisible: false,
}
describe('<HotkeysModal />', function () {
it('renders the translated modal title on cm6', async function () {
const { baseElement } = render(
<HotkeysModal {...modalProps} newSourceEditor />
)
expect(baseElement.querySelector('.modal-title').textContent).to.equal(
'Hotkeys (Source editor)'
)
})
it('renders the translated modal title on ace', async function () {
const { baseElement } = render(
<HotkeysModal {...modalProps} newSourceEditor={false} />
)
expect(baseElement.querySelector('.modal-title').textContent).to.equal(
'Hotkeys (Legacy source editor)'
)
})
it('renders translated heading with embedded code', function () {
const { baseElement } = render(<HotkeysModal {...modalProps} />)
const results = baseElement.querySelectorAll('h3 code')
expect(results).to.have.length(1)
})
it('renders the hotkey descriptions', function () {
const { baseElement } = render(<HotkeysModal {...modalProps} />)
const hotkeys = baseElement.querySelectorAll(
'[data-test-selector="hotkey"]'
)
expect(hotkeys).to.have.length(19)
})
it('adds extra hotkey descriptions when Track Changes is enabled', function () {
const { baseElement } = render(
<HotkeysModal {...modalProps} trackChangesVisible />
)
const hotkeys = baseElement.querySelectorAll(
'[data-test-selector="hotkey"]'
)
expect(hotkeys).to.have.length(22)
})
it('uses Ctrl for non-macOS', function () {
render(<HotkeysModal {...modalProps} />)
expect(screen.getAllByText(/Ctrl/)).to.have.length(16)
expect(screen.queryByText(/Cmd/)).to.not.exist
})
it('uses Cmd for macOS', function () {
render(<HotkeysModal {...modalProps} isMac />)
expect(screen.getAllByText(/Cmd/)).to.have.length(12)
expect(screen.getAllByText(/Ctrl/)).to.have.length(4)
})
})