Skip to content

Commit 4be4c73

Browse files
JuliRossiclaude
andcommitted
test(drive-integration): add integration test for Save wire in AddEntryForm
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7b03cbf commit 4be4c73

1 file changed

Lines changed: 53 additions & 7 deletions

File tree

apps/drive-integration/test/locations/Page/components/modals/EditModal.spec.tsx

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ const contentTypes = [
3333
];
3434

3535
const existingEntries = [
36-
{ tempId: 'entry-1', label: 'Blog post' },
37-
{ tempId: 'entry-2', label: 'Landing page' },
36+
{ tempId: 'entry-1', label: 'Blog post', contentTypeId: 'article' },
37+
{ tempId: 'entry-2', label: 'Landing page', contentTypeId: 'page' },
3838
];
3939

4040
const baseNewLocation = {
@@ -188,7 +188,9 @@ describe('EditModal', () => {
188188
expect(screen.getByRole('button', { name: 'Back' })).toBeTruthy();
189189
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled();
190190
expect(screen.queryByRole('button', { name: 'Next' })).toBeNull();
191-
expect(screen.queryByText('Should this entry be a reference entry?')).toBeNull();
191+
expect(
192+
screen.queryByText('Should this new entry be a reference of an existing entry?')
193+
).toBeNull();
192194
});
193195

194196
it('shows radios and field multiselect together after content type is selected', async () => {
@@ -197,16 +199,20 @@ describe('EditModal', () => {
197199
fireEvent.change(screen.getByRole('combobox'), { target: { value: 'page' } });
198200

199201
await waitFor(() => {
200-
expect(screen.getByText('Should this entry be a reference entry?')).toBeTruthy();
202+
expect(
203+
screen.getByText('Should this new entry be a reference of an existing entry?')
204+
).toBeTruthy();
201205
expect(screen.getByLabelText('Yes')).toBeTruthy();
202206
expect(screen.getByLabelText('No')).toBeTruthy();
203207
expect(screen.getByText('Select the field(s) the content should map to')).toBeTruthy();
204208
});
205209

206-
expect(screen.queryByText('Select the entry this should reference')).toBeNull();
210+
expect(
211+
screen.queryByText('Which existing entry should this new entry be a reference to?')
212+
).toBeNull();
207213
});
208214

209-
it('shows reference entry select when Yes is chosen', async () => {
215+
it('shows parent entry select when Yes is chosen', async () => {
210216
await openAddEntryForm();
211217

212218
fireEvent.change(screen.getByRole('combobox'), { target: { value: 'article' } });
@@ -218,11 +224,51 @@ describe('EditModal', () => {
218224
fireEvent.click(screen.getByLabelText('Yes'));
219225

220226
await waitFor(() => {
221-
expect(screen.getByText('Select the entry this should reference')).toBeTruthy();
227+
expect(
228+
screen.getByText('Which existing entry should this new entry be a reference to?')
229+
).toBeTruthy();
222230
expect(screen.getByText('Blog post')).toBeTruthy();
223231
});
224232
});
225233

234+
it('calls onAddEntry with the correct params when Save is clicked after filling the form', async () => {
235+
await openAddEntryForm();
236+
237+
fireEvent.change(screen.getByRole('combobox'), { target: { value: 'page' } });
238+
239+
await waitFor(() => {
240+
expect(screen.getByLabelText('No')).toBeTruthy();
241+
});
242+
243+
fireEvent.click(screen.getByLabelText('No'));
244+
245+
await waitFor(() => {
246+
expect(screen.getByRole('button', { name: 'Toggle Multiselect' })).toBeTruthy();
247+
});
248+
249+
fireEvent.click(screen.getByRole('button', { name: 'Toggle Multiselect' }));
250+
251+
await waitFor(() => {
252+
expect(screen.getByText('Title')).toBeTruthy();
253+
});
254+
255+
fireEvent.click(screen.getByText('Title'));
256+
257+
await waitFor(() => {
258+
expect(screen.getByRole('button', { name: 'Save' })).not.toBeDisabled();
259+
});
260+
261+
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
262+
263+
expect(onAddEntry).toHaveBeenCalledWith({
264+
contentTypeId: 'page',
265+
isReference: false,
266+
referenceEntryId: null,
267+
referenceFieldId: null,
268+
fieldIds: ['title'],
269+
});
270+
});
271+
226272
it('exits the form when Back is clicked', async () => {
227273
await openAddEntryForm();
228274

0 commit comments

Comments
 (0)