hotkeys-modal.test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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', async function () {
  12. const { baseElement } = render(<HotkeysModal {...modalProps} />)
  13. expect(baseElement.querySelector('.modal-title').textContent).to.equal(
  14. 'Hotkeys'
  15. )
  16. })
  17. it('renders translated heading with embedded code', function () {
  18. const { baseElement } = render(<HotkeysModal {...modalProps} />)
  19. const results = baseElement.querySelectorAll('h3 code')
  20. expect(results).to.have.length(1)
  21. })
  22. it('renders the hotkey descriptions', function () {
  23. const { baseElement } = render(<HotkeysModal {...modalProps} />)
  24. const hotkeys = baseElement.querySelectorAll(
  25. '[data-test-selector="hotkey"]'
  26. )
  27. expect(hotkeys).to.have.length(19)
  28. })
  29. it('adds extra hotkey descriptions when Track Changes is enabled', function () {
  30. const { baseElement } = render(
  31. <HotkeysModal {...modalProps} trackChangesVisible />
  32. )
  33. const hotkeys = baseElement.querySelectorAll(
  34. '[data-test-selector="hotkey"]'
  35. )
  36. expect(hotkeys).to.have.length(22)
  37. })
  38. it('uses Ctrl for non-macOS', function () {
  39. render(<HotkeysModal {...modalProps} />)
  40. expect(screen.getAllByText(/Ctrl/)).to.have.length(16)
  41. expect(screen.queryByText(/Cmd/)).to.not.exist
  42. })
  43. it('uses Cmd for macOS', function () {
  44. render(<HotkeysModal {...modalProps} isMac />)
  45. expect(screen.getAllByText(/Cmd/)).to.have.length(12)
  46. expect(screen.getAllByText(/Ctrl/)).to.have.length(4)
  47. })
  48. })