themeLoading.mjs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { describe, it, before, after } from 'mocha'
  2. import { expect } from 'chai'
  3. import {
  4. getRootAndWait,
  5. takeScreenshotOnFailure,
  6. } from '../../lib/elements.js'
  7. describe('config: themeLoading', function () {
  8. before(async function () {
  9. await runner.start('themeLoading')
  10. })
  11. after(async () => {
  12. await runner.stop()
  13. })
  14. afterEach(function () {
  15. takeScreenshotOnFailure(this.currentTest, webdriver)
  16. })
  17. it('Available themes are discovered and returned in Init response', async function () {
  18. await getRootAndWait()
  19. // Wait for initResponse to be available
  20. await webdriver.wait(async () => {
  21. const hasInitResponse = await webdriver.executeScript(
  22. 'return typeof window.initResponse !== "undefined" && window.initResponse !== null'
  23. )
  24. return hasInitResponse
  25. }, 5000, 'Init response should be available')
  26. // Get available themes from the Init response
  27. const availableThemes = await webdriver.executeScript(
  28. 'return window.initResponse ? (window.initResponse.availableThemes || []) : []'
  29. )
  30. // Verify themes array exists and is an array
  31. expect(availableThemes).to.be.an('array')
  32. // Verify that themes with theme.css are discovered
  33. // theme-one and theme-two have theme.css, invalid-theme does not
  34. expect(availableThemes).to.include('theme-one')
  35. expect(availableThemes).to.include('theme-two')
  36. // Verify that themes without theme.css are not included
  37. expect(availableThemes).to.not.include('invalid-theme')
  38. // Verify themes are sorted alphabetically
  39. const sortedThemes = [...availableThemes].sort()
  40. expect(availableThemes).to.deep.equal(sortedThemes)
  41. })
  42. it('Available themes list is accessible via JavaScript', async function () {
  43. await getRootAndWait()
  44. // Wait for initResponse to be available
  45. await webdriver.wait(async () => {
  46. const hasInitResponse = await webdriver.executeScript(
  47. 'return typeof window.initResponse !== "undefined" && window.initResponse !== null'
  48. )
  49. return hasInitResponse
  50. }, 5000, 'Init response should be available')
  51. // Verify availableThemes is accessible
  52. const availableThemes = await webdriver.executeScript(
  53. 'return window.initResponse ? (window.initResponse.availableThemes || []) : []'
  54. )
  55. expect(availableThemes).to.be.an('array')
  56. expect(availableThemes.length).to.be.at.least(2)
  57. })
  58. })