|
| 1 | +import React from 'react'; |
| 2 | + |
| 3 | +import { initializeMocks, render } from '@src/testUtils'; |
| 4 | +import { teamGroupsMock } from '@src/group-configurations/__mocks__'; |
| 5 | +import TeamGroupsSection from '.'; |
| 6 | + |
| 7 | +const renderComponent = ( |
| 8 | + props: Partial<React.ComponentProps<typeof TeamGroupsSection>> = {}, |
| 9 | +) => { |
| 10 | + initializeMocks(); |
| 11 | + return render( |
| 12 | + <TeamGroupsSection |
| 13 | + availableGroup={teamGroupsMock} |
| 14 | + {...props} |
| 15 | + />, |
| 16 | + ); |
| 17 | +}; |
| 18 | + |
| 19 | +describe('<TeamGroupsSection />', () => { |
| 20 | + it('renders component correctly', () => { |
| 21 | + const { getByText, getAllByTestId } = renderComponent(); |
| 22 | + |
| 23 | + expect(getByText(teamGroupsMock.name)).toBeInTheDocument(); |
| 24 | + expect(getAllByTestId('content-group-card')).toHaveLength( |
| 25 | + teamGroupsMock.groups.length, |
| 26 | + ); |
| 27 | + }); |
| 28 | + |
| 29 | + it('renders the team group name as a heading', () => { |
| 30 | + const { getByRole } = renderComponent(); |
| 31 | + |
| 32 | + const heading = getByRole('heading', { name: teamGroupsMock.name }); |
| 33 | + expect(heading).toBeInTheDocument(); |
| 34 | + expect(heading).toHaveClass('configuration-section-name'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('renders all team groups from the availableGroup prop', () => { |
| 38 | + const { getByText } = renderComponent(); |
| 39 | + |
| 40 | + teamGroupsMock.groups.forEach((group) => { |
| 41 | + expect(getByText(group.name)).toBeInTheDocument(); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + it('renders content group cards as read-only', () => { |
| 46 | + const { getAllByTestId } = renderComponent(); |
| 47 | + |
| 48 | + const cards = getAllByTestId('content-group-card'); |
| 49 | + expect(cards).toHaveLength(teamGroupsMock.groups.length); |
| 50 | + |
| 51 | + // Verify that no edit or delete buttons are present (read-only mode) |
| 52 | + const editButtons = document.querySelectorAll('[data-testid="content-group-card-header-edit"]'); |
| 53 | + const deleteButtons = document.querySelectorAll('[data-testid="content-group-card-header-delete"]'); |
| 54 | + |
| 55 | + expect(editButtons).toHaveLength(0); |
| 56 | + expect(deleteButtons).toHaveLength(0); |
| 57 | + }); |
| 58 | + |
| 59 | + it('renders with custom availableGroup prop', () => { |
| 60 | + const customGroup = { |
| 61 | + ...teamGroupsMock, |
| 62 | + name: 'Custom Team Group', |
| 63 | + groups: [ |
| 64 | + { |
| 65 | + id: 100, |
| 66 | + name: 'Custom Team 1', |
| 67 | + usage: [], |
| 68 | + version: 1, |
| 69 | + }, |
| 70 | + ], |
| 71 | + }; |
| 72 | + |
| 73 | + const { getByText, getAllByTestId } = renderComponent({ |
| 74 | + availableGroup: customGroup, |
| 75 | + }); |
| 76 | + |
| 77 | + expect(getByText('Custom Team Group')).toBeInTheDocument(); |
| 78 | + expect(getByText('Custom Team 1')).toBeInTheDocument(); |
| 79 | + expect(getAllByTestId('content-group-card')).toHaveLength(1); |
| 80 | + }); |
| 81 | +}); |
0 commit comments