hotkeys-modal.test.js 1.8 KB

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