multi-dashboard-includes.mjs 3.1 KB

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