feat(cv): structure custom section entries
This commit is contained in:
@@ -133,3 +133,43 @@ test('internal navigation warns and can be cancelled before discarding a pending
|
||||
expect(screen.getByDisplayValue('Backend CV')).toBeInTheDocument();
|
||||
confirm.mockRestore();
|
||||
});
|
||||
|
||||
test('custom entries can be added, edited, reordered and deleted with confirmation', async () => {
|
||||
routeGet(() => Promise.resolve({ data: variant } as any));
|
||||
mockedApi.put.mockResolvedValue({ data: variant } as any);
|
||||
const confirm = jest.spyOn(window, 'confirm');
|
||||
renderAt(3);
|
||||
|
||||
await screen.findByLabelText('Headline override');
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add' }));
|
||||
fireEvent.change(screen.getByLabelText('Custom section title'), { target: { value: 'Selected projects' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add entry' }));
|
||||
fireEvent.change(screen.getByLabelText('Entry 1'), { target: { value: 'First project' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add entry' }));
|
||||
fireEvent.change(screen.getByLabelText('Entry 2'), { target: { value: 'Second project' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Move custom entry 2 up' }));
|
||||
|
||||
expect(screen.getByLabelText('Entry 1')).toHaveValue('Second project');
|
||||
expect(screen.getByLabelText('Entry 2')).toHaveValue('First project');
|
||||
|
||||
confirm.mockReturnValueOnce(false).mockReturnValueOnce(true);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Delete custom entry 1' }));
|
||||
expect(screen.getAllByLabelText(/^Entry /)).toHaveLength(2);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Delete custom entry 1' }));
|
||||
expect(screen.getAllByLabelText(/^Entry /)).toHaveLength(1);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save now' }));
|
||||
expect(await screen.findByText('Saved')).toBeInTheDocument();
|
||||
expect(mockedApi.put).toHaveBeenLastCalledWith('/cv/variants/3', expect.objectContaining({
|
||||
settings: expect.objectContaining({
|
||||
customSections: [expect.objectContaining({ title: 'Selected projects', items: ['First project'] })],
|
||||
}),
|
||||
}));
|
||||
|
||||
confirm.mockReturnValueOnce(false).mockReturnValueOnce(true);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Remove custom section' }));
|
||||
expect(screen.getByLabelText('Custom section title')).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Remove custom section' }));
|
||||
expect(screen.queryByLabelText('Custom section title')).not.toBeInTheDocument();
|
||||
confirm.mockRestore();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user