diff --git a/dashboard/components/dashboard/components/resources-manager/hooks/useResourcesManagerChart.tsx b/dashboard/components/dashboard/components/resources-manager/hooks/useResourcesManagerChart.tsx index 629035795..7eb21a90a 100644 --- a/dashboard/components/dashboard/components/resources-manager/hooks/useResourcesManagerChart.tsx +++ b/dashboard/components/dashboard/components/resources-manager/hooks/useResourcesManagerChart.tsx @@ -60,9 +60,7 @@ function useResourcesManagerChart({ labels: sortByDescendingCosts?.map(item => item.label), datasets: [ { - data: sortByDescendingCosts?.map(item => - item.total - ) as number[], + data: sortByDescendingCosts?.map(item => item.total) as number[], backgroundColor: colors, borderColor: '#FFFFFF', borderWidth: 3, diff --git a/dashboard/components/select-checkbox/SelectCheckbox.test.tsx b/dashboard/components/select-checkbox/SelectCheckbox.test.tsx new file mode 100644 index 000000000..cc433cc00 --- /dev/null +++ b/dashboard/components/select-checkbox/SelectCheckbox.test.tsx @@ -0,0 +1,130 @@ +import { render, fireEvent } from '@testing-library/react'; +import SelectCheckbox from './SelectCheckbox'; + +jest.mock('./hooks/useSelectCheckbox', () => ({ + __esModule: true, + default: jest.fn(() => ({ + listOfExcludableItems: ['Item 1', 'Item 2', 'Item 3'], + error: null + })) +})); + +describe('SelectCheckbox', () => { + it('renders the label correctly', () => { + const { getByText } = render( + {}} + /> + ); + + expect(getByText('Test Label')).toBeInTheDocument(); + }); + + it('opens the dropdown when clicked', () => { + const { getByRole, getByText } = render( + {}} + /> + ); + + fireEvent.click(getByRole('button')); + + expect(getByText('Item 1')).toBeInTheDocument(); + expect(getByText('Item 2')).toBeInTheDocument(); + expect(getByText('Item 3')).toBeInTheDocument(); + }); + + it('closes the dropdown when clicked outside', () => { + const { getByRole, queryByText, getByTestId } = render( + {}} + /> + ); + + fireEvent.click(getByRole('button')); + expect(queryByText('Item 1')).toBeInTheDocument(); + + fireEvent.click(getByTestId('overlay')); + expect(queryByText('Item 1')).toBeNull(); + }); + + it('selects and excludes items', () => { + const setExcludeMock = jest.fn(); + const { getByRole, getByText } = render( + + ); + + fireEvent.click(getByRole('button')); + fireEvent.click(getByRole('checkbox', { name: 'Item 1' })); + fireEvent.click(getByRole('checkbox', { name: 'Item 3' })); + fireEvent.click(getByText('Apply')); + + expect(setExcludeMock).toHaveBeenCalledWith(['Item 1', 'Item 3']); + }); + + it('selects and deselects all items with "Exclude All" checkbox', () => { + const setExcludeMock = jest.fn(); + const { getByRole, getByText } = render( + + ); + + fireEvent.click(getByRole('button')); + fireEvent.click(getByRole('checkbox', { name: 'Exclude All' })); + fireEvent.click(getByText('Apply')); + + expect(setExcludeMock).toHaveBeenCalledWith(['Item 1', 'Item 2', 'Item 3']); + + fireEvent.click(getByRole('checkbox', { name: 'Exclude All' })); + fireEvent.click(getByText('Apply')); + + expect(setExcludeMock).toHaveBeenCalledWith([]); + }); + + it('filters the list of items based on search input', () => { + const { getByRole, getByPlaceholderText, queryByText } = render( + {}} + /> + ); + + fireEvent.click(getByRole('button')); + const searchInput = getByPlaceholderText('Search'); + + fireEvent.change(searchInput, { target: { value: 'Item 1' } }); + expect(queryByText('Item 2')).toBeNull(); + expect(queryByText('Item 3')).toBeNull(); + expect(queryByText('Item 1')).toBeInTheDocument(); + + fireEvent.change(searchInput, { target: { value: 'Item' } }); + expect(queryByText('Item 1')).toBeInTheDocument(); + expect(queryByText('Item 2')).toBeInTheDocument(); + expect(queryByText('Item 3')).toBeInTheDocument(); + + fireEvent.change(searchInput, { target: { value: 'Non-matching' } }); + expect(queryByText('Item 1')).toBeNull(); + expect(queryByText('Item 2')).toBeNull(); + expect(queryByText('Item 3')).toBeNull(); + }); +}); diff --git a/dashboard/components/select-checkbox/SelectCheckbox.tsx b/dashboard/components/select-checkbox/SelectCheckbox.tsx index c91fd92c0..ad98026c7 100644 --- a/dashboard/components/select-checkbox/SelectCheckbox.tsx +++ b/dashboard/components/select-checkbox/SelectCheckbox.tsx @@ -3,6 +3,7 @@ import Button from '../button/Button'; import Checkbox from '../checkbox/Checkbox'; import { ResourcesManagerQuery } from '../dashboard/components/resources-manager/hooks/useResourcesManager'; import useSelectCheckbox from './hooks/useSelectCheckbox'; +import ChevronDownIcon from '../icons/ChevronDownIcon'; export type SelectCheckboxProps = { label: string; @@ -41,6 +42,14 @@ function SelectCheckbox({ } } + function handleCheckAll(e: ChangeEvent) { + if (e.currentTarget.checked) { + setCheckedItems(listOfExcludableItems); + } else { + setCheckedItems([]); + } + } + function submit() { setExclude(checkedItems); } @@ -55,6 +64,12 @@ function SelectCheckbox({ return (
+
+ +
diff --git a/dashboard/styles/globals.css b/dashboard/styles/globals.css index 3d7941693..c5eaec72d 100644 --- a/dashboard/styles/globals.css +++ b/dashboard/styles/globals.css @@ -3,3 +3,24 @@ @tailwind base; @tailwind components; @tailwind utilities; + +@layer utilities { + .scrollbar::-webkit-scrollbar { + width: 6px; + height: 6px; + } + + .scrollbar::-webkit-scrollbar-track { + border-radius: 100vh; + background: #edebee; + } + + .scrollbar::-webkit-scrollbar-thumb { + background: #95a3a3; + border-radius: 100vh; + } + + .scrollbar::-webkit-scrollbar-thumb:hover { + background: #95a3a3; + } +}