preview-logs-toggle-button.test.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import React from 'react'
  2. import { screen, render } from '@testing-library/react'
  3. import PreviewLogsToggleButton from '../../../../../frontend/js/features/preview/components/preview-logs-toggle-button'
  4. describe('<PreviewLogsToggleButton />', function() {
  5. describe('basic toggle functionality', function() {
  6. const logsState = {
  7. nErrors: 0,
  8. nWarnings: 0,
  9. nLogEntries: 0
  10. }
  11. const onToggleLogs = () => {}
  12. it('should render a view logs button when previewing the PDF', function() {
  13. const showLogs = false
  14. render(
  15. <PreviewLogsToggleButton
  16. logsState={logsState}
  17. showLogs={showLogs}
  18. onToggle={onToggleLogs}
  19. />
  20. )
  21. screen.getByText('View logs')
  22. })
  23. it('should render a view PDF button when viewing logs', function() {
  24. const showLogs = true
  25. render(
  26. <PreviewLogsToggleButton
  27. logsState={logsState}
  28. showLogs={showLogs}
  29. onToggle={onToggleLogs}
  30. />
  31. )
  32. screen.getByText('View PDF')
  33. })
  34. })
  35. describe('compile status indicator', function() {
  36. const showLogs = false
  37. const onToggleLogs = () => {}
  38. it('should render a view logs button by default', function() {
  39. const logsState = {
  40. nErrors: 0,
  41. nWarnings: 0,
  42. nLogEntries: 0
  43. }
  44. render(
  45. <PreviewLogsToggleButton
  46. logsState={logsState}
  47. showLogs={showLogs}
  48. onToggle={onToggleLogs}
  49. />
  50. )
  51. screen.getByText('View logs')
  52. })
  53. it('should render an error status message when there are errors', function() {
  54. const logsState = {
  55. nErrors: 1,
  56. nWarnings: 0,
  57. nLogEntries: 0
  58. }
  59. render(
  60. <PreviewLogsToggleButton
  61. logsState={logsState}
  62. showLogs={showLogs}
  63. onToggle={onToggleLogs}
  64. />
  65. )
  66. screen.getByText(`Your project has errors (${logsState.nErrors})`)
  67. })
  68. it('should render an error status message when there are both errors and warnings', function() {
  69. const logsState = {
  70. nErrors: 1,
  71. nWarnings: 1,
  72. nLogEntries: 0
  73. }
  74. render(
  75. <PreviewLogsToggleButton
  76. logsState={logsState}
  77. showLogs={showLogs}
  78. onToggle={onToggleLogs}
  79. />
  80. )
  81. screen.getByText(`Your project has errors (${logsState.nErrors})`)
  82. })
  83. it('should render a warning status message when there are warnings but no errors', function() {
  84. const logsState = {
  85. nErrors: 0,
  86. nWarnings: 1,
  87. nLogEntries: 0
  88. }
  89. render(
  90. <PreviewLogsToggleButton
  91. logsState={logsState}
  92. showLogs={showLogs}
  93. onToggle={onToggleLogs}
  94. />
  95. )
  96. screen.getByText(`View warnings (${logsState.nWarnings})`)
  97. })
  98. it('should render 9+ errors when there are more than nine errors', function() {
  99. const logsState = {
  100. nErrors: 10,
  101. nWarnings: 0,
  102. nLogEntries: 0
  103. }
  104. render(
  105. <PreviewLogsToggleButton
  106. logsState={logsState}
  107. showLogs={showLogs}
  108. onToggle={onToggleLogs}
  109. />
  110. )
  111. screen.getByText('Your project has errors (9+)')
  112. })
  113. })
  114. })