Migrate DuplicatedServersModal to tailwind

This commit is contained in:
Alejandro Celaya
2025-04-05 11:15:42 +02:00
parent 7879476739
commit d8a42b4c3a
6 changed files with 92 additions and 77 deletions

View File

@@ -65,9 +65,9 @@ describe('<ImportServersBtn />', () => {
});
it.each([
{ btnName: 'Save anyway',savesDuplicatedServers: true },
{ btnName: 'Save duplicate', savesDuplicatedServers: true },
{ btnName: 'Discard', savesDuplicatedServers: false },
])('creates expected servers depending on selected option in modal', async ({ btnName, savesDuplicatedServers }) => {
])('creates duplicated servers depending on selected option in modal', async ({ btnName, savesDuplicatedServers }) => {
const existingServerData: ServerData = {
name: 'existingServer',
url: 'http://s.test/existingUrl',
@@ -84,14 +84,20 @@ describe('<ImportServersBtn />', () => {
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
await user.upload(screen.getByTestId('csv-file-input'), csvFile);
// Once the file is uploaded, non-duplicated servers are immediately created
expect(createServersMock).toHaveBeenCalledExactlyOnceWith([expect.objectContaining(newServer)]);
expect(screen.getByRole('dialog')).toBeInTheDocument();
await user.click(screen.getByRole('button', { name: btnName }));
expect(createServersMock).toHaveBeenCalledWith(
savesDuplicatedServers
? [expect.objectContaining(existingServerData), expect.objectContaining(newServer)]
: [expect.objectContaining(newServer)],
);
expect(onImportMock).toHaveBeenCalledTimes(1);
// If duplicated servers are saved, there's one extra call
if (savesDuplicatedServers) {
expect(createServersMock).toHaveBeenLastCalledWith([expect.objectContaining(existingServerData)]);
}
// On import is called only once, no matter what
expect(onImportMock).toHaveBeenCalledOnce();
expect(createServersMock).toHaveBeenCalledTimes(savesDuplicatedServers ? 2 : 1);
});
});