datetime.mjs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { describe, it, before, after } from 'mocha'
  2. import { expect } from 'chai'
  3. import { By } from 'selenium-webdriver'
  4. import {
  5. getRootAndWait,
  6. getActionButton,
  7. takeScreenshotOnFailure,
  8. waitForArgumentFormReady,
  9. waitForLogsPage,
  10. argumentFieldId,
  11. } from '../../lib/elements.js'
  12. describe('config: datetime', function () {
  13. before(async function () {
  14. await runner.start('datetime')
  15. })
  16. after(async () => {
  17. await runner.stop()
  18. })
  19. afterEach(function () {
  20. takeScreenshotOnFailure(this.currentTest, webdriver)
  21. })
  22. it('Datetime argument uses datetime-local input type', async function () {
  23. await getRootAndWait()
  24. const btn = await getActionButton(webdriver, 'Test datetime argument')
  25. await btn.click()
  26. await waitForArgumentFormReady()
  27. // Find the datetime input field
  28. const datetimeInput = await webdriver.findElement(By.id(argumentFieldId('datetime')))
  29. // Verify it's a datetime-local input type
  30. const inputType = await datetimeInput.getAttribute('type')
  31. expect(inputType).to.equal('datetime-local', 'Input type should be datetime-local')
  32. // Verify it has the step attribute set to 1 (for seconds precision)
  33. const step = await datetimeInput.getAttribute('step')
  34. expect(step).to.equal('1', 'Step attribute should be 1')
  35. // Verify the label is present
  36. const label = await webdriver.findElement(By.css(`label[for="${argumentFieldId('datetime')}"]`))
  37. expect(await label.getText()).to.contain('Select a date and time')
  38. })
  39. it('Datetime argument can be filled and submitted', async function () {
  40. await getRootAndWait()
  41. const btn = await getActionButton(webdriver, 'Test datetime argument')
  42. await btn.click()
  43. await waitForArgumentFormReady()
  44. // Find the datetime input field
  45. const datetimeInput = await webdriver.findElement(By.id(argumentFieldId('datetime')))
  46. // Set a datetime value (format: YYYY-MM-DDTHH:mm)
  47. // datetime-local returns values without seconds, backend will add :00
  48. const testDateTime = '2023-12-25T15:30'
  49. // Use JavaScript to set the value directly (more reliable for datetime-local inputs)
  50. await webdriver.executeScript(
  51. 'arguments[0].value = arguments[1]',
  52. datetimeInput,
  53. testDateTime
  54. )
  55. // Trigger input event to ensure Vue reactivity
  56. await webdriver.executeScript(
  57. 'arguments[0].dispatchEvent(new Event("input", { bubbles: true }))',
  58. datetimeInput
  59. )
  60. // Small wait for Vue to process the change
  61. await webdriver.sleep(100)
  62. // Verify the value was set
  63. const value = await datetimeInput.getAttribute('value')
  64. expect(value).to.equal(testDateTime)
  65. // Find and click the submit button
  66. const submitButton = await webdriver.findElement(
  67. By.css('button[name="start"]')
  68. )
  69. await submitButton.click()
  70. await waitForLogsPage()
  71. // Verify we're on the logs page (action was executed)
  72. const url = await webdriver.getCurrentUrl()
  73. expect(url).to.include('/logs/')
  74. })
  75. })