Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caleballdrin committed Jun 13, 2024
1 parent d3b01f1 commit 2df653f
Showing 1 changed file with 52 additions and 54 deletions.
106 changes: 52 additions & 54 deletions src/components/Tool/TntConnect/TntConnect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ import TntConnect from './TntConnect';
import { uploadTnt, validateTnt } from './uploadTntConnect';

const mockEnqueue = jest.fn();
const accountListId = '123';
const file1 = new File(['contents1'], 'tnt1.xml', {
type: 'text/xml',
});
const file2 = new File(['contents2'], 'tnt2.xml', {
type: 'application/xml',
});

jest.mock('./uploadTntConnect');

const accountListId = '123';

jest.mock('notistack', () => ({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand All @@ -28,14 +33,7 @@ jest.mock('notistack', () => ({
},
}));

const file1 = new File(['contents1'], 'tnt1.xml', {
type: 'text/xml',
});
const file2 = new File(['contents2'], 'tnt2.xml', {
type: 'application/xml',
});

describe('Updating', () => {
describe('TntConnect Import', () => {
const createObjectURL = jest
.fn()
.mockReturnValueOnce('blob:1')
Expand All @@ -48,50 +46,6 @@ describe('Updating', () => {
window.URL.revokeObjectURL = revokeObjectURL;
});

it('should save tags and radio buttons', async () => {
const { getByRole, getByText, getByTestId } = render(
<SnackbarProvider>
<LocalizationProvider dateAdapter={AdapterLuxon}>
<ThemeProvider theme={theme}>
<GqlMockedProvider>
<TntConnect accountListId={accountListId} />
</GqlMockedProvider>
</ThemeProvider>
</LocalizationProvider>
</SnackbarProvider>,
);

const input = getByRole('combobox') as HTMLInputElement;
userEvent.type(input, 'tag123');
expect(input.value).toBe('tag123');
userEvent.type(input, '{enter}');

userEvent.click(
getByText(
'This import should override all fields in current contacts (contact info, notes) and add new contacts.',
),
);

userEvent.upload(getByTestId('TntUpload'), file2);
userEvent.click(getByRole('button', { name: 'Import' }));

await waitFor(() =>
expect(uploadTnt).toHaveBeenCalledWith(
expect.objectContaining({
accountListId,
selectedTags: ['tag123'],
override: 'true',
file: file2,
}),
),
);
await waitFor(() =>
expect(mockEnqueue).toHaveBeenCalledWith('Upload Complete', {
variant: 'success',
}),
);
});

it('should handle uploading a file', async () => {
const {
getByRole,
Expand Down Expand Up @@ -155,6 +109,50 @@ describe('Updating', () => {
expect(revokeObjectURL).toHaveBeenCalledWith('blob:2');
});

it('should save tags and radio buttons', async () => {
const { getByRole, getByText, getByTestId } = render(
<SnackbarProvider>
<LocalizationProvider dateAdapter={AdapterLuxon}>
<ThemeProvider theme={theme}>
<GqlMockedProvider>
<TntConnect accountListId={accountListId} />
</GqlMockedProvider>
</ThemeProvider>
</LocalizationProvider>
</SnackbarProvider>,
);

const input = getByRole('combobox') as HTMLInputElement;
userEvent.type(input, 'tag123');
expect(input.value).toBe('tag123');
userEvent.type(input, '{enter}');

userEvent.click(
getByText(
'This import should override all fields in current contacts (contact info, notes) and add new contacts.',
),
);

userEvent.upload(getByTestId('TntUpload'), file1);
userEvent.click(getByRole('button', { name: 'Import' }));

await waitFor(() =>
expect(uploadTnt).toHaveBeenCalledWith(
expect.objectContaining({
accountListId,
selectedTags: ['tag123'],
override: 'true',
file: file1,
}),
),
);
await waitFor(() =>
expect(mockEnqueue).toHaveBeenCalledWith('Upload Complete', {
variant: 'success',
}),
);
});

it('should notify the user about validation errors', () => {
(validateTnt as jest.Mock).mockReturnValue({
success: false,
Expand Down

0 comments on commit 2df653f

Please sign in to comment.