From 9b1d1fbbbd543d72e7d8e89ac22aedd613dffb63 Mon Sep 17 00:00:00 2001 From: SP1556422 Date: Fri, 29 Mar 2024 13:53:09 +0100 Subject: [PATCH 1/7] add optional onTabClick handler for application links --- packages/terra-application-links/src/ApplicationLinks.js | 4 ++++ .../terra-application-links/src/tabs/ApplicationTabs.jsx | 6 ++++++ packages/terra-application-links/src/tabs/_Tab.jsx | 4 +++- .../tests/jest/ApplicationTabs.test.jsx | 5 +++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/terra-application-links/src/ApplicationLinks.js b/packages/terra-application-links/src/ApplicationLinks.js index 32f01c9dd47..3f18c9eba4b 100644 --- a/packages/terra-application-links/src/ApplicationLinks.js +++ b/packages/terra-application-links/src/ApplicationLinks.js @@ -27,6 +27,10 @@ const ApplicationLinksPropType = PropTypes.shape({ */ icon: PropTypes.node, })), + /** + * The click callback of the tab. + */ + onTabClick: PropTypes.func, }); const ApplicationLinks = { diff --git a/packages/terra-application-links/src/tabs/ApplicationTabs.jsx b/packages/terra-application-links/src/tabs/ApplicationTabs.jsx index 35648fcf258..a83c8dd6ab1 100644 --- a/packages/terra-application-links/src/tabs/ApplicationTabs.jsx +++ b/packages/terra-application-links/src/tabs/ApplicationTabs.jsx @@ -35,6 +35,10 @@ const propTypes = { icon: PropTypes.icon, })), + /** + * The click callback of the tab. + */ + onTabClick: PropTypes.func, /** * The location as provided by the `withRouter()` HOC. */ @@ -150,6 +154,7 @@ class ApplicationTabs extends React.Component { history, staticContext, hasIcons, + onTabClick, ...customProps } = this.props; @@ -165,6 +170,7 @@ class ApplicationTabs extends React.Component { externalLink: link.externalLink, icon: link.icon, location, + onTabClick, history, }; diff --git a/packages/terra-application-links/src/tabs/_Tab.jsx b/packages/terra-application-links/src/tabs/_Tab.jsx index 5a5f01b505c..5c8920c8670 100644 --- a/packages/terra-application-links/src/tabs/_Tab.jsx +++ b/packages/terra-application-links/src/tabs/_Tab.jsx @@ -98,7 +98,9 @@ class ApplicationTab extends Component { if (!this.isCurrentPath()) { this.props.history.push(this.props.path); - } else if (this.props.onTabClick) { + } + + if (this.props.onTabClick) { this.props.onTabClick(event); } } diff --git a/packages/terra-application-links/tests/jest/ApplicationTabs.test.jsx b/packages/terra-application-links/tests/jest/ApplicationTabs.test.jsx index f19cb6dedb6..0a9d97069e8 100644 --- a/packages/terra-application-links/tests/jest/ApplicationTabs.test.jsx +++ b/packages/terra-application-links/tests/jest/ApplicationTabs.test.jsx @@ -11,6 +11,11 @@ it('should render ApplicationTabs with links and alignment', () => { expect(wrapper).toMatchSnapshot(); }); +it('should render ApplicationTabs with links and alignment and onTabClick handler', () => { + const wrapper = enzyme.shallow(
{}} />
); + expect(wrapper).toMatchSnapshot(); +}); + it('should render ApplicationTabs with icons', () => { const subject = (
From 9d3d7ffd1a15d18f38aeedf0264241285dea8d44 Mon Sep 17 00:00:00 2001 From: SP1556422 Date: Mon, 1 Apr 2024 15:16:26 +0200 Subject: [PATCH 2/7] update snapshots --- .../ApplicationTabs.test.jsx.snap | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/terra-application-links/tests/jest/__snapshots__/ApplicationTabs.test.jsx.snap b/packages/terra-application-links/tests/jest/__snapshots__/ApplicationTabs.test.jsx.snap index 1ea81841ff1..d88d3fee49b 100644 --- a/packages/terra-application-links/tests/jest/__snapshots__/ApplicationTabs.test.jsx.snap +++ b/packages/terra-application-links/tests/jest/__snapshots__/ApplicationTabs.test.jsx.snap @@ -175,3 +175,40 @@ exports[`should render ApplicationTabs with links and alignment 1`] = ` />
`; + +exports[`should render ApplicationTabs with links and alignment and onTabClick handler 1`] = ` +
+ +
+`; From bf9eb6e6e01de64cad108f40d32de228db0cced6 Mon Sep 17 00:00:00 2001 From: SP1556422 Date: Wed, 3 Apr 2024 13:42:19 +0200 Subject: [PATCH 3/7] update changelog --- packages/terra-application-links/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/terra-application-links/CHANGELOG.md b/packages/terra-application-links/CHANGELOG.md index f93f07dc581..db4537c0eeb 100644 --- a/packages/terra-application-links/CHANGELOG.md +++ b/packages/terra-application-links/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Changed + * onTabClick property added to ApplicationLinks interface + ## 6.79.0 - (March 25, 2024) * Changed From e597ce8f539234cfe7e77d8c6835a3a593829070 Mon Sep 17 00:00:00 2001 From: Saad Adnan <38024451+sdadn@users.noreply.github.com> Date: Wed, 3 Apr 2024 15:42:01 -0500 Subject: [PATCH 4/7] Update CHANGELOG.md --- packages/terra-application-links/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/terra-application-links/CHANGELOG.md b/packages/terra-application-links/CHANGELOG.md index db4537c0eeb..10071ffcf65 100644 --- a/packages/terra-application-links/CHANGELOG.md +++ b/packages/terra-application-links/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unreleased * Changed - * onTabClick property added to ApplicationLinks interface + * `onTabClick` property added to ApplicationLinks interface. ## 6.79.0 - (March 25, 2024) From dbb9b5f0afcf7743c1bcf31fda48266bec4e9218 Mon Sep 17 00:00:00 2001 From: Serhiy Date: Mon, 8 Apr 2024 13:09:05 +0200 Subject: [PATCH 5/7] Update packages/terra-application-links/CHANGELOG.md Co-authored-by: Sydney Combs <42594047+sycombs@users.noreply.github.com> --- packages/terra-application-links/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/terra-application-links/CHANGELOG.md b/packages/terra-application-links/CHANGELOG.md index 10071ffcf65..5ef16a6698b 100644 --- a/packages/terra-application-links/CHANGELOG.md +++ b/packages/terra-application-links/CHANGELOG.md @@ -2,8 +2,8 @@ ## Unreleased -* Changed - * `onTabClick` property added to ApplicationLinks interface. +* Added + * Added `onTabClick` property to ApplicationLinks interface. ## 6.79.0 - (March 25, 2024) From 9ebce0b32ace5f96042e962cfbbc27791b59da0d Mon Sep 17 00:00:00 2001 From: SP1556422 Date: Wed, 10 Apr 2024 11:27:26 +0200 Subject: [PATCH 6/7] update tests for teraa-application-links --- .../tests/jest/ApplicationTabs.test.jsx | 15 ++++++++++++--- .../tests/jest/testLinkConfig.js | 12 ++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/terra-application-links/tests/jest/ApplicationTabs.test.jsx b/packages/terra-application-links/tests/jest/ApplicationTabs.test.jsx index 0a9d97069e8..a65e1674e92 100644 --- a/packages/terra-application-links/tests/jest/ApplicationTabs.test.jsx +++ b/packages/terra-application-links/tests/jest/ApplicationTabs.test.jsx @@ -4,6 +4,7 @@ import ThemeContextProvider from 'terra-theme-context/lib/ThemeContextProvider'; import ApplicationTabs from '../../src/tabs/ApplicationTabs'; import testLinkConfig from './testLinkConfig'; import testLinksWithIconsConfig from './testLinksWithIconsConfig'; +import { BrowserRouter } from 'react-router-dom'; // Snapshot tests it('should render ApplicationTabs with links and alignment', () => { @@ -11,9 +12,17 @@ it('should render ApplicationTabs with links and alignment', () => { expect(wrapper).toMatchSnapshot(); }); -it('should render ApplicationTabs with links and alignment and onTabClick handler', () => { - const wrapper = enzyme.shallow(
{}} />
); - expect(wrapper).toMatchSnapshot(); +it('should trigger onTabClick handler', () => { + const onTabClickHandler = jest.fn(); + const wrapper = enzymeIntl.mountWithIntl( + + + + ); + + wrapper.find('.tab').first().simulate('click'); + + expect(onTabClickHandler).toHaveBeenCalled(); }); it('should render ApplicationTabs with icons', () => { diff --git a/packages/terra-application-links/tests/jest/testLinkConfig.js b/packages/terra-application-links/tests/jest/testLinkConfig.js index 465f3a1fc7f..0bb6098ba8d 100644 --- a/packages/terra-application-links/tests/jest/testLinkConfig.js +++ b/packages/terra-application-links/tests/jest/testLinkConfig.js @@ -1,10 +1,10 @@ const testLinkConfig = [ - { path: '/test1', text: 'test 1' }, - { path: '/test2', text: 'test 2' }, - { path: '/test3', text: 'test 3' }, - { path: '/test4', text: 'test 4' }, - { path: '/test5', text: 'test 5' }, - { path: '/test6', text: 'test 6' }, + { id: 'link1', path: '/test1', text: 'test 1', icon: jest.fn() }, + { id: 'link2', path: '/test2', text: 'test 2', icon: jest.fn() }, + { id: 'link3', path: '/test3', text: 'test 3', icon: jest.fn() }, + { id: 'link4', path: '/test4', text: 'test 4', icon: jest.fn() }, + { id: 'link5', path: '/test5', text: 'test 5', icon: jest.fn() }, + { id: 'link6', path: '/test6', text: 'test 6', icon: jest.fn() }, ]; export default testLinkConfig; From cbcfa8bbf7c37c9b2dc86e4106301b2a3d1d104e Mon Sep 17 00:00:00 2001 From: SP1556422 Date: Wed, 10 Apr 2024 15:14:47 +0200 Subject: [PATCH 7/7] lint fixes, remove redundant snapshot --- .../tests/jest/ApplicationTabs.test.jsx | 4 +- .../ApplicationTabs.test.jsx.snap | 37 ------------------- .../tests/jest/testLinkConfig.js | 12 +++--- 3 files changed, 8 insertions(+), 45 deletions(-) diff --git a/packages/terra-application-links/tests/jest/ApplicationTabs.test.jsx b/packages/terra-application-links/tests/jest/ApplicationTabs.test.jsx index a65e1674e92..6cc48d2d692 100644 --- a/packages/terra-application-links/tests/jest/ApplicationTabs.test.jsx +++ b/packages/terra-application-links/tests/jest/ApplicationTabs.test.jsx @@ -1,10 +1,10 @@ import React from 'react'; import ThemeContextProvider from 'terra-theme-context/lib/ThemeContextProvider'; +import { BrowserRouter } from 'react-router-dom'; import ApplicationTabs from '../../src/tabs/ApplicationTabs'; import testLinkConfig from './testLinkConfig'; import testLinksWithIconsConfig from './testLinksWithIconsConfig'; -import { BrowserRouter } from 'react-router-dom'; // Snapshot tests it('should render ApplicationTabs with links and alignment', () => { @@ -17,7 +17,7 @@ it('should trigger onTabClick handler', () => { const wrapper = enzymeIntl.mountWithIntl( - + , ); wrapper.find('.tab').first().simulate('click'); diff --git a/packages/terra-application-links/tests/jest/__snapshots__/ApplicationTabs.test.jsx.snap b/packages/terra-application-links/tests/jest/__snapshots__/ApplicationTabs.test.jsx.snap index d88d3fee49b..1ea81841ff1 100644 --- a/packages/terra-application-links/tests/jest/__snapshots__/ApplicationTabs.test.jsx.snap +++ b/packages/terra-application-links/tests/jest/__snapshots__/ApplicationTabs.test.jsx.snap @@ -175,40 +175,3 @@ exports[`should render ApplicationTabs with links and alignment 1`] = ` /> `; - -exports[`should render ApplicationTabs with links and alignment and onTabClick handler 1`] = ` -
- -
-`; diff --git a/packages/terra-application-links/tests/jest/testLinkConfig.js b/packages/terra-application-links/tests/jest/testLinkConfig.js index 0bb6098ba8d..465f3a1fc7f 100644 --- a/packages/terra-application-links/tests/jest/testLinkConfig.js +++ b/packages/terra-application-links/tests/jest/testLinkConfig.js @@ -1,10 +1,10 @@ const testLinkConfig = [ - { id: 'link1', path: '/test1', text: 'test 1', icon: jest.fn() }, - { id: 'link2', path: '/test2', text: 'test 2', icon: jest.fn() }, - { id: 'link3', path: '/test3', text: 'test 3', icon: jest.fn() }, - { id: 'link4', path: '/test4', text: 'test 4', icon: jest.fn() }, - { id: 'link5', path: '/test5', text: 'test 5', icon: jest.fn() }, - { id: 'link6', path: '/test6', text: 'test 6', icon: jest.fn() }, + { path: '/test1', text: 'test 1' }, + { path: '/test2', text: 'test 2' }, + { path: '/test3', text: 'test 3' }, + { path: '/test4', text: 'test 4' }, + { path: '/test5', text: 'test 5' }, + { path: '/test6', text: 'test 6' }, ]; export default testLinkConfig;