stdoutMostRecentExecution.mjs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { describe, it, before, after } from 'mocha'
  2. import { expect } from 'chai'
  3. import { By, Condition } from 'selenium-webdriver'
  4. import {
  5. getRootAndWait,
  6. getActionButtons,
  7. takeScreenshotOnFailure,
  8. } from '../../lib/elements.js'
  9. describe('config: stdout-most-recent-execution', function () {
  10. before(async function () {
  11. await runner.start('stdoutMostRecentExecution')
  12. })
  13. after(async () => {
  14. await runner.stop()
  15. })
  16. afterEach(function () {
  17. takeScreenshotOnFailure(this.currentTest, webdriver)
  18. })
  19. it('stdout-most-recent-execution component is rendered', async function () {
  20. await getRootAndWait()
  21. const title = await webdriver.getTitle()
  22. expect(title).to.be.equal('Test Dashboard - OliveTin')
  23. // Wait for the mre-output element to appear
  24. await webdriver.wait(
  25. new Condition('wait for mre-output element', async () => {
  26. const elements = await webdriver.findElements(By.css('.mre-output'))
  27. return elements.length > 0
  28. }),
  29. 10000
  30. )
  31. const mreElements = await webdriver.findElements(By.css('.mre-output'))
  32. expect(mreElements).to.have.length(1, 'Expected one stdout-most-recent-execution component')
  33. })
  34. it('stdout-most-recent-execution displays initial state', async function () {
  35. await getRootAndWait()
  36. await webdriver.wait(
  37. new Condition('wait for mre-output element', async () => {
  38. const elements = await webdriver.findElements(By.css('.mre-output'))
  39. return elements.length > 0
  40. }),
  41. 10000
  42. )
  43. const mreElement = await webdriver.findElement(By.css('.mre-output'))
  44. const text = await mreElement.getText()
  45. // Should show either "Waiting...", "No execution found", or actual output
  46. expect(text).to.be.a('string')
  47. expect(text.length).to.be.greaterThan(0)
  48. })
  49. it('stdout-most-recent-execution updates after action execution', async function () {
  50. this.timeout(45000)
  51. await getRootAndWait()
  52. // Wait for the mre-output element
  53. await webdriver.wait(
  54. new Condition('wait for mre-output element', async () => {
  55. const elements = await webdriver.findElements(By.css('.mre-output'))
  56. return elements.length > 0
  57. }),
  58. 10000
  59. )
  60. const mreElement = await webdriver.findElement(By.css('.mre-output'))
  61. const initialText = await mreElement.getText()
  62. // Find the "Check status" action button (button text is the action title, not ID)
  63. await webdriver.wait(
  64. new Condition('wait for Check status button', async () => {
  65. const buttons = await webdriver.findElements(By.css('.action-button button'))
  66. for (const btn of buttons) {
  67. const text = await btn.getText()
  68. if (text.includes('Check status')) {
  69. return true
  70. }
  71. }
  72. return false
  73. }),
  74. 10000
  75. )
  76. const buttons = await webdriver.findElements(By.css('.action-button button'))
  77. let statusButton = null
  78. for (const btn of buttons) {
  79. const text = await btn.getText()
  80. if (text.includes('Check status')) {
  81. statusButton = btn
  82. break
  83. }
  84. }
  85. expect(statusButton).to.not.be.null
  86. // Click the button to execute the action
  87. await statusButton.click()
  88. // Wait a moment for the action to start
  89. await webdriver.sleep(2000)
  90. // Wait for the output to update (the component listens to EventExecutionFinished events)
  91. // We'll wait for the output to change from the initial state
  92. await webdriver.wait(
  93. new Condition('wait for output to update after execution', async () => {
  94. try {
  95. const mreElement = await webdriver.findElement(By.css('.mre-output'))
  96. const newText = await mreElement.getText()
  97. // Output should change from initial state and contain actual output
  98. // (not "Waiting...", "No execution found", or the same as initialText)
  99. const hasChanged = newText !== initialText
  100. const hasValidOutput = newText &&
  101. !newText.includes('Waiting...') &&
  102. !newText.includes('No execution found') &&
  103. !newText.includes('Error:') &&
  104. newText.trim().length > 0
  105. return hasChanged && hasValidOutput
  106. } catch (e) {
  107. return false
  108. }
  109. }),
  110. 20000
  111. )
  112. const updatedMreElement = await webdriver.findElement(By.css('.mre-output'))
  113. const updatedText = await updatedMreElement.getText()
  114. // The date command should produce output, so verify it's not empty and not an error state
  115. expect(updatedText).to.not.include('Waiting...')
  116. expect(updatedText).to.not.include('No execution found')
  117. expect(updatedText.trim().length).to.be.greaterThan(0)
  118. })
  119. })