multi-dashboard-includes.mjs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { describe, it, before, after } from 'mocha'
  2. import { expect, assert } from 'chai'
  3. import { By } from 'selenium-webdriver'
  4. import {
  5. DEFAULT_UI_WAIT_MS,
  6. getRootAndWait,
  7. getActionButtons,
  8. getNavigationLinks,
  9. openSidebar,
  10. takeScreenshotOnFailure,
  11. waitForDashboardLoaded,
  12. } from '../../lib/elements.js'
  13. describe('config: multi-dashboard-includes', function () {
  14. this.timeout(30000)
  15. before(async function () {
  16. await runner.start('multi-dashboard-includes')
  17. })
  18. after(async () => {
  19. await runner.stop()
  20. })
  21. afterEach(function () {
  22. takeScreenshotOnFailure(this.currentTest, webdriver);
  23. });
  24. async function clickNavigationLinkByTitle (title) {
  25. await openSidebar()
  26. const navigationLinks = await getNavigationLinks()
  27. assert.isAbove(navigationLinks.length, 0, 'Expected at least one navigation link')
  28. const matching = []
  29. for (const li of navigationLinks) {
  30. const liTitle = await li.getAttribute('title')
  31. if (liTitle === title) {
  32. matching.push(li)
  33. }
  34. }
  35. assert.strictEqual(matching.length, 1, `Expected exactly one navigation link with title "${title}"`)
  36. await matching[0].click()
  37. await waitForDashboardLoaded(DEFAULT_UI_WAIT_MS, title)
  38. }
  39. async function getActionTitlesOnDashboard (dashboardTitle = null) {
  40. const buttons = await getActionButtons(dashboardTitle)
  41. const titles = []
  42. for (const button of buttons) {
  43. titles.push(await button.getAttribute('title'))
  44. }
  45. return titles
  46. }
  47. it('Should expose both dashboards from included files in navigation', async function () {
  48. await getRootAndWait()
  49. await openSidebar()
  50. const navigationLinks = await getNavigationLinks()
  51. assert.isAbove(navigationLinks.length, 0, 'Expected navigation to have at least one link')
  52. const titles = []
  53. for (const li of navigationLinks) {
  54. titles.push(await li.getAttribute('title'))
  55. }
  56. expect(titles).to.include('First Dashboard')
  57. expect(titles).to.include('Second Dashboard')
  58. })
  59. it('First Dashboard shows First and Second inline actions from include', async function () {
  60. await getRootAndWait()
  61. // Navigate to "First Dashboard"
  62. await clickNavigationLinkByTitle('First Dashboard')
  63. // Buttons on this dashboard only
  64. const titles = await getActionTitlesOnDashboard('First Dashboard')
  65. expect(titles).to.include('First Action')
  66. expect(titles).to.include('Second Action')
  67. // Ensure actions from the second dashboard are not rendered here
  68. expect(titles).to.not.include('Third Action')
  69. expect(titles).to.not.include('Fourth Action')
  70. })
  71. it('Second Dashboard shows Third and Fourth inline actions from include', async function () {
  72. await getRootAndWait()
  73. // Navigate to "Second Dashboard"
  74. await clickNavigationLinkByTitle('Second Dashboard')
  75. const titles = await getActionTitlesOnDashboard('Second Dashboard')
  76. expect(titles).to.include('Third Action')
  77. expect(titles).to.include('Fourth Action')
  78. // Ensure actions from the first dashboard are not rendered here
  79. expect(titles).to.not.include('First Action')
  80. expect(titles).to.not.include('Second Action')
  81. })
  82. })