preview-toolbar.test.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from 'react'
  2. import sinon from 'sinon'
  3. import { expect } from 'chai'
  4. import { screen, render } from '@testing-library/react'
  5. import PreviewToolbar from '../../../../../frontend/js/features/preview/components/preview-toolbar'
  6. describe('<PreviewToolbar />', function() {
  7. const onClearCache = sinon.stub()
  8. const onRecompile = sinon.stub()
  9. const onRunSyntaxCheckNow = sinon.stub()
  10. const onSetAutoCompile = sinon.stub()
  11. const onSetDraftMode = sinon.stub()
  12. const onSetSyntaxCheck = sinon.stub()
  13. const onToggleLogs = sinon.stub()
  14. function renderPreviewToolbar(compilerState = {}, logState = {}, showLogs) {
  15. render(
  16. <PreviewToolbar
  17. compilerState={{
  18. isAutoCompileOn: true,
  19. isClearingCache: false,
  20. isCompiling: false,
  21. isDraftModeOn: false,
  22. isSyntaxCheckOn: false,
  23. logEntries: {},
  24. ...compilerState
  25. }}
  26. logsState={{ nErrors: 0, nWarnings: 0, nLogEntries: 0, ...logState }}
  27. onClearCache={onClearCache}
  28. onRecompile={onRecompile}
  29. onRunSyntaxCheckNow={onRunSyntaxCheckNow}
  30. onSetAutoCompile={onSetAutoCompile}
  31. onSetDraftMode={onSetDraftMode}
  32. onSetSyntaxCheck={onSetSyntaxCheck}
  33. onToggleLogs={onToggleLogs}
  34. outputFiles={[]}
  35. pdfDownloadUrl="/download-pdf-url"
  36. showLogs={showLogs || false}
  37. />
  38. )
  39. }
  40. it('renders the toolbar', function() {
  41. renderPreviewToolbar()
  42. screen.getByText('Recompile')
  43. screen.getByText('Download PDF')
  44. screen.getByText('View logs')
  45. })
  46. it('all toolbar items have "toolbar-item" class and text has "toolbar-text"', function() {
  47. renderPreviewToolbar()
  48. const toolbar = screen.getByTestId('toolbar-preview')
  49. for (const toolbarSection of toolbar.children) {
  50. for (const toolbarItem of toolbarSection.children) {
  51. expect(toolbarItem.className).to.contain('toolbar-item')
  52. for (const parts of toolbarItem.children) {
  53. for (const part of parts.children) {
  54. if (part.nodeName !== 'LI' && part.textContent) {
  55. expect(part.className).to.contain('toolbar-text')
  56. }
  57. }
  58. }
  59. }
  60. }
  61. })
  62. })