hotkeys-modal.test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { render, screen } from '@testing-library/react'
  2. import HotkeysModal from '../../../../../frontend/js/features/hotkeys-modal/components/hotkeys-modal'
  3. import { expect } from 'chai'
  4. import sinon from 'sinon'
  5. const modalProps = {
  6. show: true,
  7. handleHide: sinon.stub(),
  8. trackChangesVisible: false,
  9. }
  10. describe('<HotkeysModal />', function () {
  11. it('renders the translated modal title on cm6', async function () {
  12. const { baseElement } = render(
  13. <HotkeysModal {...modalProps} newSourceEditor />
  14. )
  15. expect(baseElement.querySelector('.modal-title').textContent).to.equal(
  16. 'Hotkeys (Source editor)'
  17. )
  18. })
  19. it('renders the translated modal title on ace', async function () {
  20. const { baseElement } = render(
  21. <HotkeysModal {...modalProps} newSourceEditor={false} />
  22. )
  23. expect(baseElement.querySelector('.modal-title').textContent).to.equal(
  24. 'Hotkeys (Legacy source editor)'
  25. )
  26. })
  27. it('renders translated heading with embedded code', function () {
  28. const { baseElement } = render(<HotkeysModal {...modalProps} />)
  29. const results = baseElement.querySelectorAll('h3 code')
  30. expect(results).to.have.length(1)
  31. })
  32. it('renders the hotkey descriptions', function () {
  33. const { baseElement } = render(<HotkeysModal {...modalProps} />)
  34. const hotkeys = baseElement.querySelectorAll(
  35. '[data-test-selector="hotkey"]'
  36. )
  37. expect(hotkeys).to.have.length(19)
  38. })
  39. it('adds extra hotkey descriptions when Track Changes is enabled', function () {
  40. const { baseElement } = render(
  41. <HotkeysModal {...modalProps} trackChangesVisible />
  42. )
  43. const hotkeys = baseElement.querySelectorAll(
  44. '[data-test-selector="hotkey"]'
  45. )
  46. expect(hotkeys).to.have.length(22)
  47. })
  48. it('uses Ctrl for non-macOS', function () {
  49. render(<HotkeysModal {...modalProps} />)
  50. expect(screen.getAllByText(/Ctrl/)).to.have.length(16)
  51. expect(screen.queryByText(/Cmd/)).to.not.exist
  52. })
  53. it('uses Cmd for macOS', function () {
  54. render(<HotkeysModal {...modalProps} isMac />)
  55. expect(screen.getAllByText(/Cmd/)).to.have.length(12)
  56. expect(screen.getAllByText(/Ctrl/)).to.have.length(4)
  57. })
  58. })