From bdecb4c0d4781142a40690b54aa87ba938f06ad6 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Thu, 12 Dec 2024 17:00:20 -0300 Subject: [PATCH] Add missing tooltips back to sidebar when collapsed (#3273) * Add missing tooltips back to sidebar when collapsed * Add tests to check for collapsed sidebar and tooltip --- .../playwright/e2e/landingPage.spec.ts | 36 ++++++++++++++++--- .../src/components/sidebar/index.js | 4 ++- .../src/components/sidebar/treeNode.js | 14 ++++++-- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/site/gatsby-site/playwright/e2e/landingPage.spec.ts b/site/gatsby-site/playwright/e2e/landingPage.spec.ts index 40c35ffd22..0e0809aef7 100644 --- a/site/gatsby-site/playwright/e2e/landingPage.spec.ts +++ b/site/gatsby-site/playwright/e2e/landingPage.spec.ts @@ -101,11 +101,11 @@ test.describe('The Landing page', () => { ); test('Loads the random incidents carousel', async ({ page, skipOnEmptyEnvironment }) => { - await page.goto('/'); - await page.locator('[data-cy="random-incidents-carousel"]').scrollIntoViewIfNeeded(); - await expect(page.locator('[data-cy="random-incidents-carousel"]')).toBeVisible(); - await expect(page.locator('[data-cy="random-incidents-carousel-item"]')).toHaveCount(5); - }); + await page.goto('/'); + await page.locator('[data-cy="random-incidents-carousel"]').scrollIntoViewIfNeeded(); + await expect(page.locator('[data-cy="random-incidents-carousel"]')).toBeVisible(); + await expect(page.locator('[data-cy="random-incidents-carousel-item"]')).toHaveCount(5); + }); test('Renders commit sha in the footer', async ({ page }) => { await page.goto('/'); @@ -119,4 +119,30 @@ test.describe('The Landing page', () => { await expect(lis).toBeGreaterThan(0); }); + test('Should collapse sidebar', async ({ page, skipOnEmptyEnvironment }) => { + await page.goto('/'); + const sidebarTree = page.locator('[data-testid="sidebar-desktop"]'); + await sidebarTree.locator('[data-cy="collapse-button"]').click(); + const sidebar = await page.locator('[id="sidebar"]').first(); + let hasClass = await sidebar.evaluate((el, className) => { + return el.classList.contains(className); + }, 'collapsed'); + expect(hasClass).toBe(true); + await sidebarTree.locator('[data-cy="collapse-button"]').click(); + hasClass = await sidebar.evaluate((el, className) => { + return el.classList.contains(className); + }, 'collapsed'); + expect(hasClass).toBe(false); + }); + + test('Should display sidebar tooltip when collapsed', async ({ page, skipOnEmptyEnvironment }) => { + await page.goto('/'); + const sidebarTree = page.locator('[data-testid="sidebar-desktop"]'); + await sidebarTree.locator('[data-cy="collapse-button"]').click(); + // Hovers over a sidebar item + await page.getByTestId('sidebar-desktop').getByTestId("sidebar-welcome").hover(); + await expect(page.getByTestId('sidebar-desktop').locator('[data-testid="flowbite-tooltip"]', { hasText: 'Welcome to the AIID' })) + .toBeVisible(); + + }); }); diff --git a/site/gatsby-site/src/components/sidebar/index.js b/site/gatsby-site/src/components/sidebar/index.js index 814acb8388..09c9f97c8f 100644 --- a/site/gatsby-site/src/components/sidebar/index.js +++ b/site/gatsby-site/src/components/sidebar/index.js @@ -227,7 +227,9 @@ const Sidebar = ({ defaultCollapsed = false, location = null, setNavCollapsed })