From 65382f8800365c61b67ffc6dc50d8d657dc7369d Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Thu, 17 Oct 2024 11:41:29 +0200 Subject: [PATCH] rename toggle icon component Signed-off-by: Huong Nguyen --- .../node-list-row-toggle.test.js | 44 --------- src/components/node-list/filter-row.js | 4 +- src/components/node-list/node-list-row.js | 6 +- src/components/node-list/row.js | 10 +- .../toggle-icon/toggle-icon.js} | 6 +- .../toggle-icon/toggle-icon.scss} | 10 +- .../ui/toggle-icon/toggle-icon.test.js | 94 +++++++++++++++++++ 7 files changed, 112 insertions(+), 62 deletions(-) delete mode 100644 src/components/node-list-row-toggle/node-list-row-toggle.test.js rename src/components/{node-list-row-toggle/node-list-row-toggle.js => ui/toggle-icon/toggle-icon.js} (92%) rename src/components/{node-list-row-toggle/node-list-row-toggle.scss => ui/toggle-icon/toggle-icon.scss} (96%) create mode 100644 src/components/ui/toggle-icon/toggle-icon.test.js diff --git a/src/components/node-list-row-toggle/node-list-row-toggle.test.js b/src/components/node-list-row-toggle/node-list-row-toggle.test.js deleted file mode 100644 index a4e117afe..000000000 --- a/src/components/node-list-row-toggle/node-list-row-toggle.test.js +++ /dev/null @@ -1,44 +0,0 @@ -import React from 'react'; -import { shallow } from 'enzyme'; -import { NodeListRowToggle } from './node-list-row-toggle'; - -describe('NodeListRowToggle', () => { - const baseProps = { - name: 'Test Node', - onChange: jest.fn(), - onToggleHoveredFocusMode: jest.fn(), - }; - - it('applies "all-unchecked" class when allUnchecked is true', () => { - const props = { ...baseProps, allUnchecked: true }; - const wrapper = shallow(); - expect(wrapper.hasClass('node-list-row-toggle--icon--all-unchecked')).toBe(true); - }); - - it('applies "disabled" class when disabled is true', () => { - const props = { ...baseProps, disabled: true }; - const wrapper = shallow(); - expect(wrapper.hasClass('node-list-row-toggle--disabled')).toBe(true); - }); - - it('applies "checked" class when isChecked is true', () => { - const props = { ...baseProps, isChecked: true }; - const wrapper = shallow(); - expect(wrapper.hasClass('node-list-row-toggle--icon--checked')).toBe(true); - }); - - it('applies "parent" class when isParent is true', () => { - const props = { ...baseProps, isParent: true }; - const wrapper = shallow(); - expect(wrapper.hasClass('node-list-row-toggle--icon--parent')).toBe(true); - }); - - it('applies correct class for kind prop', () => { - const kinds = ['modularPipeline', 'data', 'task']; - kinds.forEach(kind => { - const props = { ...baseProps, kind }; - const wrapper = shallow(); - expect(wrapper.hasClass(`node-list-row-toggle--kind-${kind}`)).toBe(true); - }); - }); -}); \ No newline at end of file diff --git a/src/components/node-list/filter-row.js b/src/components/node-list/filter-row.js index 347dc0ec1..7c0f76c32 100755 --- a/src/components/node-list/filter-row.js +++ b/src/components/node-list/filter-row.js @@ -3,7 +3,7 @@ import classnames from 'classnames'; import { replaceAngleBracketMatches } from '../../utils'; import VisibleIcon from '../icons/visible'; import InvisibleIcon from '../icons/invisible'; -import { NodeListRowToggle } from '../node-list-row-toggle/node-list-row-toggle'; +import { ToggleIcon } from '../ui/toggle-icon/toggle-icon'; // The exact fixed height of a row as measured by getBoundingClientRect() export const nodeListRowHeight = 32; @@ -66,7 +66,7 @@ export const FilterRow = ({ {count} {VisibilityIcon && ( - )} {VisibilityIcon && ( - )} {FocusIcon && ( - {VisibilityIcon && ( - )} {FocusIcon && ( - { + const baseProps = { + name: 'Test Node', + onChange: jest.fn(), + onToggleHoveredFocusMode: jest.fn(), + }; + + it('applies "all-unchecked" class when allUnchecked is true', () => { + const props = { ...baseProps, allUnchecked: true }; + const wrapper = shallow(); + expect(wrapper.hasClass('node-list-row-toggle--icon--all-unchecked')).toBe( + true + ); + }); + + it('applies "disabled" class when disabled is true', () => { + const props = { ...baseProps, disabled: true }; + const wrapper = shallow(); + expect(wrapper.hasClass('node-list-row-toggle--disabled')).toBe(true); + }); + + it('applies "checked" class when isChecked is true', () => { + const props = { ...baseProps, isChecked: true }; + const wrapper = shallow(); + expect(wrapper.hasClass('node-list-row-toggle--icon--checked')).toBe(true); + }); + + it('applies "parent" class when isParent is true', () => { + const props = { ...baseProps, isParent: true }; + const wrapper = shallow(); + expect(wrapper.hasClass('node-list-row-toggle--icon--parent')).toBe(true); + }); + + it('applies correct class for kind prop', () => { + const kinds = ['modularPipeline', 'data', 'task']; + kinds.forEach((kind) => { + const props = { ...baseProps, kind }; + const wrapper = shallow(); + expect(wrapper.hasClass(`node-list-row-toggle--kind-${kind}`)).toBe(true); + }); + }); + + it('does not apply "all-unchecked" class when allUnchecked is false', () => { + const props = { ...baseProps, allUnchecked: false }; + const wrapper = shallow(); + expect(wrapper.hasClass('node-list-row-toggle--icon--all-unchecked')).toBe( + false + ); + }); + + it('does not apply "disabled" class when disabled is false', () => { + const props = { ...baseProps, disabled: false }; + const wrapper = shallow(); + expect(wrapper.hasClass('node-list-row-toggle--disabled')).toBe(false); + }); + + it('does not apply "checked" class when isChecked is false', () => { + const props = { ...baseProps, isChecked: false }; + const wrapper = shallow(); + expect(wrapper.hasClass('node-list-row-toggle--icon--checked')).toBe(false); + }); + + it('does not apply "parent" class when isParent is false', () => { + const props = { ...baseProps, isParent: false }; + const wrapper = shallow(); + expect(wrapper.hasClass('node-list-row-toggle--icon--parent')).toBe(false); + }); + + it('triggers onChange callback when clicked', () => { + const props = { ...baseProps }; + const wrapper = shallow(); + wrapper.simulate('click'); + expect(props.onChange).toHaveBeenCalled(); + }); + + it('does not trigger onToggleHoveredFocusMode when not provided', () => { + const props = { ...baseProps, onToggleHoveredFocusMode: undefined }; + const wrapper = shallow(); + wrapper.simulate('click'); + // Since onToggleHoveredFocusMode is not provided, it should not throw an error + expect(() => wrapper.simulate('click')).not.toThrow(); + }); + + it('triggers onToggleHoveredFocusMode when provided and clicked', () => { + const props = { ...baseProps }; + const wrapper = shallow(); + wrapper.simulate('click'); + expect(props.onToggleHoveredFocusMode).toHaveBeenCalled(); + }); +});