From 406ec28e0bcc83460e0bece6f537b44995e6f05c Mon Sep 17 00:00:00 2001 From: dhanu Date: Fri, 11 Oct 2024 12:12:35 +0530 Subject: [PATCH 1/9] LinkWithPill.vue, link-with-pill.spec.ts, ProfilePicture.vue, ProfilePic.vue, profile-pic.spec.ts, ListSkeleton.story.vue - add onclick event to prevent default behaviour of link and execute a function --- .../CardTable/Cell/LinkWithPill.vue | 13 ++++- .../CardTable/Cell/ProfilePicture.vue | 12 +++++ .../Cell/__tests__/link-with-pill.spec.ts | 50 +++++++++++++++++++ .../core/components/ProfilePic/ProfilePic.vue | 19 ++++++- .../ProfilePic/__tests__/profile-pic.spec.ts | 41 +++++++++++++++ .../ListTable/ListSkeleton.story.vue | 44 ++++++++++++++++ 6 files changed, 177 insertions(+), 2 deletions(-) diff --git a/components/src/core/components/CardTable/Cell/LinkWithPill.vue b/components/src/core/components/CardTable/Cell/LinkWithPill.vue index 5423c2bb4..2ecc81650 100644 --- a/components/src/core/components/CardTable/Cell/LinkWithPill.vue +++ b/components/src/core/components/CardTable/Cell/LinkWithPill.vue @@ -6,7 +6,7 @@ @@ -52,6 +54,14 @@ export default defineComponent({ type: Boolean, default: false, }, + header: { + type: Object, + default: () => ({}), + }, + rowItem: { + type: Object, + default: () => ({}), + }, }, setup(props) { const imgSrc = ref(null); @@ -82,6 +92,8 @@ export default defineComponent({ ? props.rowItem[props.link] : null, target: props.target ?? TARGET_SELF, + header: props.header, + rowItem: props.rowItem, }; }); diff --git a/components/src/core/components/CardTable/Cell/__tests__/link-with-pill.spec.ts b/components/src/core/components/CardTable/Cell/__tests__/link-with-pill.spec.ts index 34e59f7c4..56cc8a049 100644 --- a/components/src/core/components/CardTable/Cell/__tests__/link-with-pill.spec.ts +++ b/components/src/core/components/CardTable/Cell/__tests__/link-with-pill.spec.ts @@ -109,4 +109,54 @@ describe('CardTable > Cell > LinkWithPill.vue', () => { .trim(), ).toEqual('external'); }); + + it('should trigger handleLinkClick on link click', async () => { + const mockOnClick = jest.fn(); + const rowItem = { + url1: 'https://orangehrm.com', + tag: 'external', + }; + + const wrapper = mount(LinkWithPill, { + global: GLOBAL, + props: { + item: 'This is a link', + target: '_parent', + link: 'url1', + rowItem: rowItem, + header: { + cellConfig: { + onClick: mockOnClick, + }, + }, + }, + }); + + const link = wrapper.find('a'); + await link.trigger('click'); + + expect(mockOnClick).toHaveBeenCalledWith(rowItem, expect.any(MouseEvent)); + }); + + it('should not prevent default behavior if no onClick handler is present', async () => { + const wrapper = mount(LinkWithPill, { + global: GLOBAL, + props: { + item: 'This is a link', + target: '_blank', + link: 'url1', + rowItem: { + url1: 'https://orangehrm.com', + tag: 'external', + }, + }, + }); + + const link = wrapper.find('a'); + const event = { preventDefault: jest.fn() }; + + await link.trigger('click', event); + + expect(event.preventDefault).not.toHaveBeenCalled(); + }); }); diff --git a/components/src/core/components/ProfilePic/ProfilePic.vue b/components/src/core/components/ProfilePic/ProfilePic.vue index bfa90154e..9b01aa123 100644 --- a/components/src/core/components/ProfilePic/ProfilePic.vue +++ b/components/src/core/components/ProfilePic/ProfilePic.vue @@ -1,7 +1,7 @@