checklist.mjs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import { describe, it, before, after } from 'mocha'
  2. import { expect } from 'chai'
  3. import { By, Condition } from 'selenium-webdriver'
  4. import {
  5. DEFAULT_UI_WAIT_MS,
  6. getRootAndWait,
  7. getActionButton,
  8. takeScreenshotOnFailure,
  9. getTerminalBuffer,
  10. waitForArgumentFormPage,
  11. waitForArgumentFormReady,
  12. waitForLogsPage,
  13. waitForExecutionComplete,
  14. } from '../../lib/elements.js'
  15. async function openChecklistArgumentForm(actionTitle = 'Test checklist argument') {
  16. await getRootAndWait()
  17. const btn = await getActionButton(webdriver, actionTitle)
  18. await btn.click()
  19. await waitForArgumentFormPage()
  20. await waitForArgumentFormReady()
  21. }
  22. async function submitChecklistForm() {
  23. const submitButton = await webdriver.findElement(By.css('button[name="start"]'))
  24. await submitButton.click()
  25. }
  26. async function pollTerminal(matcher, timeoutMs = DEFAULT_UI_WAIT_MS) {
  27. await webdriver.wait(
  28. new Condition('wait for terminal output', async () => {
  29. try {
  30. const terminalReady = await webdriver.executeScript(`
  31. return !!(window.terminal && window.terminal.getBufferAsString);
  32. `)
  33. if (!terminalReady) {
  34. return false
  35. }
  36. const output = await getTerminalBuffer()
  37. if (!output) {
  38. return false
  39. }
  40. return matcher(output.trim())
  41. } catch (e) {
  42. return false
  43. }
  44. }),
  45. timeoutMs
  46. )
  47. }
  48. async function waitForTerminalOutput(expectedValue, label = 'Selected segments') {
  49. await pollTerminal(
  50. (output) => output.includes(`${label}: ${expectedValue}`),
  51. DEFAULT_UI_WAIT_MS
  52. )
  53. }
  54. async function waitForTerminalOutputPattern(pattern) {
  55. await pollTerminal(
  56. (output) => pattern.test(output),
  57. 10000
  58. )
  59. }
  60. async function getCheckboxByValueIndex(index) {
  61. const checkboxes = await webdriver.findElements(
  62. By.css('.choice-checklist-item input[type="checkbox"]')
  63. )
  64. return checkboxes[index]
  65. }
  66. describe('config: checklist', function () {
  67. this.timeout(10000)
  68. before(async function () {
  69. await runner.start('checklist')
  70. })
  71. after(async () => {
  72. await runner.stop()
  73. })
  74. afterEach(function () {
  75. takeScreenshotOnFailure(this.currentTest, webdriver)
  76. })
  77. it('Checklist argument renders multiple checkbox inputs', async function () {
  78. await openChecklistArgumentForm()
  79. const kitchen = await getCheckboxByValueIndex(0)
  80. const bedroom = await getCheckboxByValueIndex(1)
  81. const hallway = await getCheckboxByValueIndex(2)
  82. expect(await kitchen.getAttribute('type')).to.equal('checkbox')
  83. expect(await bedroom.getAttribute('type')).to.equal('checkbox')
  84. expect(await hallway.getAttribute('type')).to.equal('checkbox')
  85. expect(await kitchen.isSelected()).to.be.true
  86. expect(await bedroom.isSelected()).to.be.true
  87. expect(await hallway.isSelected()).to.be.false
  88. })
  89. it('Checklist select none submits an empty value', async function () {
  90. await openChecklistArgumentForm()
  91. const selectNone = await webdriver.findElement(By.xpath("//button[normalize-space()='Select none']"))
  92. await selectNone.click()
  93. await webdriver.sleep(300)
  94. const valueInput = await webdriver.findElement(By.css('.choice-checklist > input'))
  95. expect(await valueInput.getAttribute('value')).to.equal('')
  96. await submitChecklistForm()
  97. await waitForLogsPage()
  98. await waitForExecutionComplete()
  99. await waitForTerminalOutputPattern(/Selected segments:\s*(\r?\n|$)/)
  100. })
  101. it('Checklist select all submits every choice value', async function () {
  102. await openChecklistArgumentForm()
  103. const selectNone = await webdriver.findElement(By.xpath("//button[normalize-space()='Select none']"))
  104. await selectNone.click()
  105. const selectAll = await webdriver.findElement(By.xpath("//button[normalize-space()='Select all']"))
  106. await selectAll.click()
  107. await submitChecklistForm()
  108. await waitForLogsPage()
  109. await waitForExecutionComplete()
  110. await waitForTerminalOutput('kitchen,bedroom,hallway')
  111. })
  112. it('Checklist toggles individual choices before submit', async function () {
  113. await openChecklistArgumentForm()
  114. const hallway = await getCheckboxByValueIndex(2)
  115. await hallway.click()
  116. await submitChecklistForm()
  117. await waitForLogsPage()
  118. await waitForExecutionComplete()
  119. await waitForTerminalOutput('kitchen,bedroom,hallway')
  120. })
  121. it('Checklist entity argument renders choices from entities', async function () {
  122. await openChecklistArgumentForm('Test checklist entity argument')
  123. const checkboxes = await webdriver.findElements(
  124. By.css('.choice-checklist-item input[type="checkbox"]')
  125. )
  126. expect(checkboxes).to.have.length(2)
  127. const labels = await webdriver.findElements(By.css('.choice-checklist-item span'))
  128. expect(await labels[0].getText()).to.equal('attic')
  129. expect(await labels[1].getText()).to.equal('basement')
  130. await checkboxes[0].click()
  131. await submitChecklistForm()
  132. await waitForLogsPage()
  133. await waitForExecutionComplete()
  134. await waitForTerminalOutput('attic', 'Selected rooms')
  135. })
  136. })