checkbox.mjs 2.9 KB

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