envTemplateIcon.mjs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { describe, it, before, after } from 'mocha'
  2. import { expect } from 'chai'
  3. import { By, Condition } from 'selenium-webdriver'
  4. import * as process from 'node:process'
  5. import {
  6. getRootAndWait,
  7. takeScreenshotOnFailure,
  8. } from '../../lib/elements.js'
  9. describe('config: envTemplateIcon', function () {
  10. before(async function () {
  11. // Set the environment variable before starting the runner
  12. process.env.ADGUARD_ICON = 'test.png'
  13. await runner.start('envTemplateIcon')
  14. })
  15. after(async () => {
  16. await runner.stop()
  17. // Clean up the environment variable
  18. delete process.env.ADGUARD_ICON
  19. })
  20. afterEach(function () {
  21. takeScreenshotOnFailure(this.currentTest, webdriver);
  22. });
  23. it('Action icon is set from .Env template variable', async function () {
  24. await getRootAndWait()
  25. // Get the dashboard data which contains the actions
  26. // executeScript automatically waits for Promises returned from the script
  27. const dashboardResponse = await webdriver.executeScript(`
  28. return window.client.getDashboard({ title: 'Actions' })
  29. `)
  30. expect(dashboardResponse).to.not.be.null
  31. expect(dashboardResponse).to.have.own.property('dashboard')
  32. expect(dashboardResponse.dashboard).to.have.own.property('contents')
  33. expect(dashboardResponse.dashboard.contents).to.be.an('array')
  34. expect(dashboardResponse.dashboard.contents.length).to.be.greaterThan(0)
  35. // Actions are nested in dashboard contents - find the action with the expected title
  36. // The structure is: dashboard.contents[] -> component.contents[] -> action
  37. let testAction = null
  38. for (const component of dashboardResponse.dashboard.contents) {
  39. if (component.contents && Array.isArray(component.contents)) {
  40. for (const subcomponent of component.contents) {
  41. if (subcomponent.title === 'Test Action with Env Icon') {
  42. testAction = subcomponent
  43. break
  44. }
  45. }
  46. }
  47. // Also check if the component itself is the action
  48. if (component.title === 'Test Action with Env Icon') {
  49. testAction = component
  50. break
  51. }
  52. if (testAction) break
  53. }
  54. expect(testAction).to.not.be.null
  55. expect(testAction).to.have.own.property('icon')
  56. expect(testAction.icon).to.equal('test.png')
  57. })
  58. it('Action button displays icon from .Env template variable', async function () {
  59. await getRootAndWait()
  60. // Wait for the action button to be rendered
  61. await webdriver.wait(new Condition('wait for action button', async () => {
  62. const btns = await webdriver.findElements(By.css('[title="Test Action with Env Icon"]'))
  63. return btns.length === 1
  64. }), 10000)
  65. // Verify the button exists
  66. const buttons = await webdriver.findElements(By.css('[title="Test Action with Env Icon"]'))
  67. expect(buttons).to.have.length(1)
  68. // The icon should be rendered in the button - we can check via the GetDashboard API response
  69. // which is the most reliable way to verify the template parsing worked
  70. // executeScript automatically waits for Promises returned from the script
  71. const dashboardResponse = await webdriver.executeScript(`
  72. return window.client.getDashboard({ title: 'Actions' })
  73. `)
  74. expect(dashboardResponse).to.not.be.null
  75. expect(dashboardResponse).to.have.own.property('dashboard')
  76. // Find the action with the expected title
  77. // The structure is: dashboard.contents[] -> component.contents[] -> action
  78. let testAction = null
  79. for (const component of dashboardResponse.dashboard.contents) {
  80. if (component.contents && Array.isArray(component.contents)) {
  81. for (const subcomponent of component.contents) {
  82. if (subcomponent.title === 'Test Action with Env Icon') {
  83. testAction = subcomponent
  84. break
  85. }
  86. }
  87. }
  88. // Also check if the component itself is the action
  89. if (component.title === 'Test Action with Env Icon') {
  90. testAction = component
  91. break
  92. }
  93. if (testAction) break
  94. }
  95. expect(testAction).to.not.be.null
  96. expect(testAction).to.have.own.property('icon')
  97. expect(testAction.icon).to.equal('test.png')
  98. })
  99. })