From 7608d1877ef22a79ed15e13d294c6c924692899e Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Tue, 10 Dec 2024 10:42:33 -0300 Subject: [PATCH 1/2] Add missing tooltips back to sidebar when collapsed --- .../gatsby-site/src/components/sidebar/treeNode.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/site/gatsby-site/src/components/sidebar/treeNode.js b/site/gatsby-site/src/components/sidebar/treeNode.js index d6a3904e0f..f64a1caae2 100644 --- a/site/gatsby-site/src/components/sidebar/treeNode.js +++ b/site/gatsby-site/src/components/sidebar/treeNode.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Trans } from 'react-i18next'; +import { Trans, useTranslation } from 'react-i18next'; import { ChevronDown, ChevronRight } from 'react-feather'; import Link from '../ui/Link'; // Assuming you have this component for internal links import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; @@ -19,6 +19,7 @@ import { faTable, faUser, } from '@fortawesome/free-solid-svg-icons'; +import { Tooltip } from 'flowbite-react'; const TreeNode = ({ item, @@ -50,6 +51,8 @@ const TreeNode = ({ } }; + const { t } = useTranslation(); + return (
  • - {icon && (isCollapsed ? {icon} : <>{icon})} + {icon && + (isCollapsed ? ( + + {icon} + + ) : ( + <>{icon} + ))} {!isCollapsed && ( {item.title} From 111f71e0a44313517f2039e1093bb84dfb3b3e69 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Tue, 10 Dec 2024 11:17:23 -0300 Subject: [PATCH 2/2] Add tests to check for collapsed sidebar and tooltip --- .../playwright/e2e/landingPage.spec.ts | 36 ++++++++++++++++--- .../src/components/sidebar/index.js | 4 ++- 2 files changed, 34 insertions(+), 6 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 })