confirmation.mjs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. argumentFieldId,
  7. getRootAndWait,
  8. getActionButton,
  9. takeScreenshotOnFailure,
  10. waitForArgumentFormPage,
  11. waitForArgumentFormReady,
  12. waitForLogsPage,
  13. waitForExecutionComplete,
  14. getTerminalBuffer,
  15. } from '../../lib/elements.js'
  16. async function openArgumentForm (actionTitle) {
  17. await getRootAndWait()
  18. const btn = await getActionButton(webdriver, actionTitle)
  19. await btn.click()
  20. await waitForArgumentFormPage()
  21. await waitForArgumentFormReady()
  22. }
  23. async function getStartButton () {
  24. return await webdriver.findElement(By.css('button[name="start"]'))
  25. }
  26. async function waitForStartButtonEnabled () {
  27. await webdriver.wait(
  28. new Condition('wait for Start button to be enabled', async () => {
  29. const submitButton = await getStartButton()
  30. return await submitButton.isEnabled()
  31. }),
  32. DEFAULT_UI_WAIT_MS
  33. )
  34. }
  35. async function waitForStartButtonDisabled () {
  36. await webdriver.wait(
  37. new Condition('wait for Start button to be disabled', async () => {
  38. const submitButton = await getStartButton()
  39. return !(await submitButton.isEnabled())
  40. }),
  41. DEFAULT_UI_WAIT_MS
  42. )
  43. }
  44. async function waitForTerminalOutput (expectedSubstring) {
  45. await webdriver.wait(
  46. new Condition(`wait for terminal output containing ${expectedSubstring}`, async () => {
  47. try {
  48. const terminalReady = await webdriver.executeScript(`
  49. return !!(window.terminal && window.terminal.getBufferAsString);
  50. `)
  51. if (!terminalReady) {
  52. return false
  53. }
  54. const output = await getTerminalBuffer()
  55. return output && output.includes(expectedSubstring)
  56. } catch {
  57. return false
  58. }
  59. }),
  60. DEFAULT_UI_WAIT_MS
  61. )
  62. }
  63. async function confirmAndSubmit (checkbox) {
  64. await checkbox.click()
  65. await waitForStartButtonEnabled()
  66. const submitButton = await getStartButton()
  67. await submitButton.click()
  68. await waitForLogsPage()
  69. await waitForExecutionComplete()
  70. }
  71. describe('config: confirmation', function () {
  72. this.timeout(10000)
  73. before(async function () {
  74. await runner.start('confirmation')
  75. })
  76. after(async () => {
  77. await runner.stop()
  78. })
  79. afterEach(function () {
  80. takeScreenshotOnFailure(this.currentTest, webdriver)
  81. })
  82. it('Unnamed confirmation renders a checkbox and disables Start until ticked', async function () {
  83. await openArgumentForm('Test unnamed confirmation argument')
  84. const checkbox = await webdriver.findElement(By.css('#argument-popup input[type="checkbox"]'))
  85. expect(await checkbox.getTagName()).to.equal('input')
  86. expect(await checkbox.getAttribute('type')).to.equal('checkbox')
  87. expect(await checkbox.isSelected()).to.be.false
  88. const label = await webdriver.findElement(By.css(`label[for="${argumentFieldId('')}"]`))
  89. expect(await label.getText()).to.contain('Are you sure?!')
  90. const submitButton = await getStartButton()
  91. expect(await submitButton.isEnabled()).to.be.false
  92. })
  93. it('Unnamed confirmation runs the action without substituting a value', async function () {
  94. await openArgumentForm('Test unnamed confirmation argument')
  95. const checkbox = await webdriver.findElement(By.css('#argument-popup input[type="checkbox"]'))
  96. await confirmAndSubmit(checkbox)
  97. await waitForTerminalOutput('Confirmed action ran')
  98. })
  99. it('Named confirmation disables Start until ticked and submits 1 when checked', async function () {
  100. await openArgumentForm('Test named confirmation argument')
  101. const checkbox = await webdriver.findElement(By.id(argumentFieldId('agree')))
  102. expect(await checkbox.isSelected()).to.be.false
  103. const label = await webdriver.findElement(By.css(`label[for="${argumentFieldId('agree')}"]`))
  104. expect(await label.getText()).to.contain('I understand the consequences')
  105. const submitButton = await getStartButton()
  106. expect(await submitButton.isEnabled()).to.be.false
  107. await confirmAndSubmit(checkbox)
  108. await waitForTerminalOutput('Confirmation value: 1')
  109. })
  110. it('Named confirmation works with shell actions', async function () {
  111. await openArgumentForm('Test shell with named confirmation')
  112. const checkbox = await webdriver.findElement(By.id(argumentFieldId('agree')))
  113. const submitButton = await getStartButton()
  114. expect(await submitButton.isEnabled()).to.be.false
  115. await confirmAndSubmit(checkbox)
  116. await waitForTerminalOutput('Shell confirmation value: 1')
  117. })
  118. it('Confirmation keeps Start disabled while unchecked (unlike checkbox arguments)', async function () {
  119. await openArgumentForm('Test named confirmation argument')
  120. const checkbox = await webdriver.findElement(By.id(argumentFieldId('agree')))
  121. expect(await checkbox.isSelected()).to.be.false
  122. await waitForStartButtonDisabled()
  123. await checkbox.click()
  124. await webdriver.sleep(100)
  125. expect(await checkbox.isSelected()).to.be.true
  126. await waitForStartButtonEnabled()
  127. await checkbox.click()
  128. await webdriver.sleep(100)
  129. expect(await checkbox.isSelected()).to.be.false
  130. await waitForStartButtonDisabled()
  131. })
  132. })