/* eslint-disable @angular-eslint/use-component-selector */ import { render, screen } from '@testing-library/angular'; import { SlaveCheckboxComponent } from './slave-checkbox.component'; import { MasterCheckboxComponent } from './master-checkbox.component'; describe('SlaveCheckboxComponent', () => { async function createSlaveCheckboxComponent( override: { template?: string; componentProperties?: Record } = {}, ) { override.template ||= ` `; const mockMasterCheckbox = { id: () => 'master', selectionChanged: vi.fn(), } as unknown as MasterCheckboxComponent; const rendered = await render(override.template, { imports: [SlaveCheckboxComponent], componentProperties: { masterCheckbox: mockMasterCheckbox, checkable: { checked: false }, ...override.componentProperties, }, }); return rendered; } it('should create the component', async () => { const { fixture } = await createSlaveCheckboxComponent(); expect(fixture.componentInstance).toBeTruthy(); expect(screen.getByRole('checkbox')).toBeDefined(); }); it('should render unchecked checkbox by default', async () => { await createSlaveCheckboxComponent(); const checkbox = screen.getByRole('checkbox') as HTMLInputElement; expect(checkbox.checked).toBe(false); }); it('should render checked checkbox when checkable.checked is true', async () => { await createSlaveCheckboxComponent({ componentProperties: { checkable: { checked: true }, }, }); const checkbox = screen.getByRole('checkbox') as HTMLInputElement; expect(checkbox.checked).toBe(true); }); it('should have correct id attribute', async () => { const mockMasterCheckbox = { id: () => 'queue', selectionChanged: vi.fn(), } as unknown as MasterCheckboxComponent; await createSlaveCheckboxComponent({ componentProperties: { masterCheckbox: mockMasterCheckbox, checkable: { checked: false }, }, template: ` `, }); const checkbox = screen.getByRole('checkbox') as HTMLInputElement; expect(checkbox.id).toBe('queue-url123-select'); }); });