checkbox.mjs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. waitForLogsPage,
  12. waitForExecutionComplete,
  13. argumentFieldId,
  14. } from '../../lib/elements.js'
  15. async function openCheckboxArgumentForm() {
  16. await getRootAndWait()
  17. const btn = await getActionButton(webdriver, 'Test checkbox argument')
  18. await btn.click()
  19. await waitForArgumentFormPage()
  20. }
  21. async function getCheckboxInput() {
  22. return await webdriver.findElement(By.id(argumentFieldId('confirm')))
  23. }
  24. async function submitCheckboxForm() {
  25. const submitButton = await webdriver.findElement(By.css('button[name="start"]'))
  26. await submitButton.click()
  27. }
  28. async function waitForTerminalOutput(expectedValue) {
  29. await webdriver.wait(
  30. new Condition(`wait for checkbox value ${expectedValue} in output`, async () => {
  31. try {
  32. const terminalReady = await webdriver.executeScript(`
  33. return !!(window.terminal && window.terminal.getBufferAsString);
  34. `)
  35. if (!terminalReady) {
  36. return false
  37. }
  38. const output = await getTerminalBuffer()
  39. if (!output) {
  40. return false
  41. }
  42. return output.trim().includes(`Checkbox value: ${expectedValue}`)
  43. } catch (e) {
  44. return false
  45. }
  46. }),
  47. DEFAULT_UI_WAIT_MS
  48. )
  49. }
  50. describe('config: checkbox', function () {
  51. before(async function () {
  52. await runner.start('checkbox')
  53. })
  54. after(async () => {
  55. await runner.stop()
  56. })
  57. afterEach(function () {
  58. takeScreenshotOnFailure(this.currentTest, webdriver)
  59. })
  60. it('Checkbox argument is rendered as a checkbox input', async function () {
  61. await openCheckboxArgumentForm()
  62. const checkboxInput = await getCheckboxInput()
  63. expect(await checkboxInput.getTagName()).to.equal('input')
  64. expect(await checkboxInput.getAttribute('type')).to.equal('checkbox')
  65. const label = await webdriver.findElement(By.css(`label[for="${argumentFieldId('confirm')}"]`))
  66. expect(await label.getText()).to.contain('Confirm option')
  67. })
  68. it('Checkbox argument submits 0 by default when unchecked', async function () {
  69. await openCheckboxArgumentForm()
  70. const checkboxInput = await getCheckboxInput()
  71. expect(await checkboxInput.isSelected()).to.be.false
  72. await submitCheckboxForm()
  73. await waitForLogsPage()
  74. await waitForExecutionComplete()
  75. await waitForTerminalOutput('0')
  76. })
  77. it('Checkbox argument can be toggled and submitted', async function () {
  78. await openCheckboxArgumentForm()
  79. const checkboxInput = await getCheckboxInput()
  80. await checkboxInput.click()
  81. await webdriver.sleep(100)
  82. expect(await checkboxInput.isSelected()).to.be.true
  83. await submitCheckboxForm()
  84. await waitForLogsPage()
  85. await waitForExecutionComplete()
  86. await waitForTerminalOutput('1')
  87. })
  88. })