datetime.mjs 2.9 KB

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