stdoutMostRecentExecution.mjs 4.7 KB

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