enabledExpression.mjs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { describe, it, before, after } from 'mocha'
  2. import { expect } from 'chai'
  3. import { By, until } from 'selenium-webdriver'
  4. import {
  5. getRootAndWait,
  6. takeScreenshotOnFailure,
  7. } from '../../lib/elements.js'
  8. describe('config: enabledExpression', function () {
  9. before(async function () {
  10. await runner.start('enabledExpression')
  11. })
  12. after(async () => {
  13. await runner.stop()
  14. })
  15. afterEach(function () {
  16. takeScreenshotOnFailure(this.currentTest, webdriver);
  17. });
  18. it('Action with enabledExpression false is disabled', async function() {
  19. await getRootAndWait()
  20. // Navigate to the Lights Dashboard
  21. await webdriver.get(runner.baseUrl() + '/dashboard/Lights%20Dashboard')
  22. // Wait for dashboard to load
  23. await webdriver.wait(until.elementLocated(By.css('.action-button')), 10000)
  24. // Find action buttons
  25. const actionButtons = await webdriver.findElements(By.css('.action-button button'))
  26. // Find "Turn On Light" button for "Living Room Light" (powered_on: false, so Turn On should be enabled)
  27. // Find "Turn Off Light" button for "Bedroom Light" (powered_on: true, so Turn Off should be enabled)
  28. let turnOnButton = null
  29. let turnOffButton = null
  30. for (const btn of actionButtons) {
  31. const title = await btn.getAttribute('title')
  32. if (title && title.includes('Turn On Light') && title.includes('Living Room')) {
  33. turnOnButton = btn
  34. }
  35. if (title && title.includes('Turn Off Light') && title.includes('Bedroom')) {
  36. turnOffButton = btn
  37. }
  38. }
  39. expect(turnOnButton).to.not.be.null
  40. expect(turnOffButton).to.not.be.null
  41. // Check that Turn On button is enabled (light is off)
  42. const turnOnDisabled = await turnOnButton.getAttribute('disabled')
  43. expect(turnOnDisabled).to.be.null
  44. // Check that Turn Off button is enabled (light is on)
  45. const turnOffDisabled = await turnOffButton.getAttribute('disabled')
  46. expect(turnOffDisabled).to.be.null
  47. })
  48. it('Action without enabledExpression is always enabled', async function() {
  49. await getRootAndWait()
  50. // Navigate to actions view
  51. await webdriver.get(runner.baseUrl())
  52. // Wait for action buttons
  53. await webdriver.wait(until.elementLocated(By.css('.action-button')), 10000)
  54. // Find "Always Enabled Action" button
  55. const actionButtons = await webdriver.findElements(By.css('.action-button button'))
  56. let alwaysEnabledButton = null
  57. for (const btn of actionButtons) {
  58. const title = await btn.getAttribute('title')
  59. if (title === 'Always Enabled Action') {
  60. alwaysEnabledButton = btn
  61. break
  62. }
  63. }
  64. expect(alwaysEnabledButton).to.not.be.null
  65. // Check that it's enabled
  66. const disabled = await alwaysEnabledButton.getAttribute('disabled')
  67. expect(disabled).to.be.null
  68. })
  69. })