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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.getByRole('button', { name: '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.getByRole('button', { name: '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.getByRole('button', { name: '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.getByRole('button', {
  67. name: `Your project has errors (${logsState.nErrors})`
  68. })
  69. })
  70. it('should render an error status message when there are both errors and warnings', function() {
  71. const logsState = {
  72. nErrors: 1,
  73. nWarnings: 1,
  74. nLogEntries: 0
  75. }
  76. render(
  77. <PreviewLogsToggleButton
  78. logsState={logsState}
  79. showLogs={showLogs}
  80. onToggle={onToggleLogs}
  81. />
  82. )
  83. screen.getByRole('button', {
  84. name: `Your project has errors (${logsState.nErrors})`
  85. })
  86. })
  87. it('should render a warning status message when there are warnings but no errors', function() {
  88. const logsState = {
  89. nErrors: 0,
  90. nWarnings: 1,
  91. nLogEntries: 0
  92. }
  93. render(
  94. <PreviewLogsToggleButton
  95. logsState={logsState}
  96. showLogs={showLogs}
  97. onToggle={onToggleLogs}
  98. />
  99. )
  100. screen.getByRole('button', {
  101. name: `View warnings (${logsState.nWarnings})`
  102. })
  103. })
  104. it('should render 9+ errors when there are more than nine errors', function() {
  105. const logsState = {
  106. nErrors: 10,
  107. nWarnings: 0,
  108. nLogEntries: 0
  109. }
  110. render(
  111. <PreviewLogsToggleButton
  112. logsState={logsState}
  113. showLogs={showLogs}
  114. onToggle={onToggleLogs}
  115. />
  116. )
  117. screen.getByRole('button', { name: `Your project has errors (9+)` })
  118. })
  119. })
  120. })