From a8ee4cdb4ad6ec5204ff93b19ba731f9d382854d Mon Sep 17 00:00:00 2001 From: Stavros Tomas <55188371+stavros-tomas@users.noreply.github.com> Date: Fri, 14 Jun 2024 07:23:21 +0100 Subject: [PATCH] [CHUX-467] ec-navigation mobile view (#1976) * chux-467:feat:mobile-view * chux-467:chore:mobile-view more updates * chux-467:chore:mobile-view more updates * CHUX-467:test:unit * CHUX-467:test: more unit tests * CHUX-467:chore:export letter icon * CHUX-467:chore: adjust width of images and make menu close on navigation link clicked * CHUX-467:chore:update snapshots * CHUX-467:chore:update styles --- .../__snapshots__/ec-menu.spec.ts.snap | 47 ++ src/components/ec-menu/ec-menu.spec.ts | 17 + src/components/ec-menu/ec-menu.vue | 5 + .../ec-mobile-header.spec.ts.snap | 3 +- .../ec-mobile-header/ec-mobile-header.spec.ts | 9 + .../ec-mobile-header/ec-mobile-header.vue | 25 +- .../ec-navigation-link/ec-navigation-link.vue | 5 + .../__snapshots__/ec-navigation.spec.ts.snap | 505 ++++++++++++++---- .../ec-navigation/ec-navigation.spec.ts | 56 +- .../ec-navigation/ec-navigation.vue | 105 +++- src/main.ts | 2 + 11 files changed, 648 insertions(+), 131 deletions(-) diff --git a/src/components/ec-menu/__snapshots__/ec-menu.spec.ts.snap b/src/components/ec-menu/__snapshots__/ec-menu.spec.ts.snap index 065f8888c..a2bdc76f4 100644 --- a/src/components/ec-menu/__snapshots__/ec-menu.spec.ts.snap +++ b/src/components/ec-menu/__snapshots__/ec-menu.spec.ts.snap @@ -1,5 +1,52 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`EcMenu > @events > should propagate the event from the navigation link 1`] = ` + +`; + exports[`EcMenu > should attach custom listeners passed in the link definition 1`] = ` @@ -37,6 +38,10 @@ import { computed } from 'vue'; import EcNavigationLink from '../ec-navigation-link'; import type { MenuLink, MenuProps } from './types'; +const emit = defineEmits<{ + 'navigation-link-clicked': [], +}>(); + const props = withDefaults(defineProps(), { links: () => [], }); diff --git a/src/components/ec-mobile-header/__snapshots__/ec-mobile-header.spec.ts.snap b/src/components/ec-mobile-header/__snapshots__/ec-mobile-header.spec.ts.snap index 832e84d10..264d42444 100644 --- a/src/components/ec-mobile-header/__snapshots__/ec-mobile-header.spec.ts.snap +++ b/src/components/ec-mobile-header/__snapshots__/ec-mobile-header.spec.ts.snap @@ -6,7 +6,7 @@ exports[`EcMobileHeader > should render properly 1`] = ` data-test="ec-mobile-header" > + +`; + +exports[`EcNavigation > mobile navigation > should close the mobile navigation when the close menu button is clicked > before 1`] = `
+
+
+ +
+ +
+ + + +
+ + +
+ + +
+`; + +exports[`EcNavigation > mobile navigation > should close the mobile navigation when the slot \`onNavigationLinkClicked\` binding is triggered > after 1`] = ` +
+
+ + + +
+ +
+`; + +exports[`EcNavigation > mobile navigation > should close the mobile navigation when the slot \`onNavigationLinkClicked\` binding is triggered > before 1`] = ` +
+
+
+ +
+ +
+ + + +
+ + + +
+ + +
+`; + +exports[`EcNavigation > mobile navigation > should render mobile header if "isResponsive" prop is true 1`] = ` +
+
+ + + +
+ +
+`; + +exports[`EcNavigation > mobile navigation > should show render the mobile navigation when the mobile header menu button is clicked > after 1`] = ` +
+
+ +
+ +
+ + + +
+ + +
+ + +
+`; + +exports[`EcNavigation > mobile navigation > should show render the mobile navigation when the mobile header menu button is clicked > before 1`] = ` +
+
+ + +
+ +
+`; + +exports[`EcNavigation > should apply light mode CSS classes if "isInLightMode" prop is true 1`] = ` +
+
+
+ +
+

should be collapsable when isCollapsable is set 1`] = ` data-test="ec-navigation" >
- +
+ +
+
@@ -70,15 +373,20 @@ exports[`EcNavigation > should be collapsed when isCollapsed is set to true 1`] data-test="ec-navigation" >
- +
+ +
+
@@ -101,15 +409,20 @@ exports[`EcNavigation > should be expanded when isCollapsed is set to false 1`] data-test="ec-navigation" >
- +
+ +
+
@@ -131,7 +444,12 @@ exports[`EcNavigation > should not render branding if logo is given in branding class="ec-navigation" data-test="ec-navigation" > - +
+ + +
@@ -152,7 +470,12 @@ exports[`EcNavigation > should not render branding if no logo is given in brandi class="ec-navigation" data-test="ec-navigation" > - +
+ + +
@@ -174,15 +497,20 @@ exports[`EcNavigation > should only render mandatory slot if no other slots were data-test="ec-navigation" >
- +
+ +
+
@@ -205,15 +533,20 @@ exports[`EcNavigation > should render all given slots 1`] = ` data-test="ec-navigation" >
- +
+ +
+
`; -exports[`EcNavigation > should render mobile header if "isResponsive" prop is true 1`] = ` -
- - -
-`; - exports[`EcNavigation > should render with custom attributes 1`] = `
should render with custom attributes 1`] = ` id="test-id" >
- +
+ +
+
diff --git a/src/components/ec-navigation/ec-navigation.spec.ts b/src/components/ec-navigation/ec-navigation.spec.ts index f7a406d65..ea64687c3 100644 --- a/src/components/ec-navigation/ec-navigation.spec.ts +++ b/src/components/ec-navigation/ec-navigation.spec.ts @@ -93,19 +93,63 @@ describe('EcNavigation', () => { expect(wrapper.findAllByDataTest('ec-navigation__block').length).toBe(5); }); - it('should render mobile header if "isResponsive" prop is true', () => { + it('should apply light mode CSS classes if "isInLightMode" prop is true', () => { const wrapper = mountNavigation({ - isResponsive: true, + isInLightMode: true, }); expect(wrapper.element).toMatchSnapshot(); }); - it('should apply light mode CSS classes if "isInLightMode" prop is true', () => { - const wrapper = mountNavigation({ - isInLightMode: true, + describe('mobile navigation', () => { + it('should render mobile header if "isResponsive" prop is true', () => { + const wrapper = mountNavigation({ + isResponsive: true, + }); + + expect(wrapper.element).toMatchSnapshot(); }); - expect(wrapper.element).toMatchSnapshot(); + it('should show render the mobile navigation when the mobile header menu button is clicked', async () => { + const wrapper = mountNavigation({ + isResponsive: true, + }); + + expect(wrapper.element).toMatchSnapshot('before'); + await wrapper.findByDataTest('ec-mobile-header__menu').trigger('click'); + expect(wrapper.element).toMatchSnapshot('after'); + }); + + it('should close the mobile navigation when the close menu button is clicked', async () => { + const wrapper = mountNavigation({ + isResponsive: true, + }); + + await wrapper.findByDataTest('ec-mobile-header__menu').trigger('click'); + expect(wrapper.element).toMatchSnapshot('before'); + + await wrapper.findByDataTest('ec-navigation__mobile-menu-close-button').trigger('click'); + expect(wrapper.element).toMatchSnapshot('after'); + }); + + it('should close the mobile navigation when the slot `onNavigationLinkClicked` binding is triggered', async () => { + const wrapper = mountNavigation({ + isResponsive: true, + }, { + slots: { + menu: ``, + }, + }); + + // Open mobile menu first + await wrapper.findByDataTest('ec-mobile-header__menu').trigger('click'); + expect(wrapper.element).toMatchSnapshot('before'); + + // Close navigation when a menu item is clicked + await wrapper.findByDataTest('my-custom-link').trigger('click'); + expect(wrapper.element).toMatchSnapshot('after'); + }); }); }); diff --git a/src/components/ec-navigation/ec-navigation.vue b/src/components/ec-navigation/ec-navigation.vue index 6e7511bbe..e1e51937e 100644 --- a/src/components/ec-navigation/ec-navigation.vue +++ b/src/components/ec-navigation/ec-navigation.vue @@ -1,5 +1,8 @@