Skip to content

Commit

Permalink
ZKUI-179: Fix cannot add a third tag
Browse files Browse the repository at this point in the history
  • Loading branch information
JBWatenbergScality committed Jun 3, 2022
1 parent 597bd93 commit dd430eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/react/databrowser/objects/details/Tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ function Properties({ objectMetadata }: Props) {
reset,
handleSubmit,
control,
getValues,
watch,
formState: { isDirty },
} = useForm<FormValues>({
defaultValues,
});

const { tags: tagsFormValues } = getValues();
const tagsFormValues = watch("tags");

const onSubmit = (data: FormValues) => {
const tags = convertToAWSTags(data.tags);
Expand Down
12 changes: 10 additions & 2 deletions src/react/databrowser/objects/details/__tests__/Tags.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ describe('Tags', () => {
'',
);
});
it('should add new key/value tag and should trigger api call when form is submitted', async () => {
it('should add 2 new key/value tag and should trigger api call when form is submitted', async () => {
//S
const key1 = 'key1';
const value1 = 'value1';
const key2 = 'key2';
const value2 = 'value2';
const key3 = 'key3';
const value3 = 'value3';
const mockedRequestBodyInterceptor = jest.fn();
server.use(
rest.put(
Expand Down Expand Up @@ -105,13 +107,19 @@ describe('Tags', () => {
screen.getByRole('textbox', { name: 'Tag 2 value' }),
value2,
);
fireEvent.click(screen.getByRole('button', { name: 'Add' }));
userEvent.type(screen.getByRole('textbox', { name: 'Tag 3 key' }), key3);
userEvent.type(
screen.getByRole('textbox', { name: 'Tag 3 value' }),
value3,
);
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
await waitFor(() =>
expect(mockedRequestBodyInterceptor).toHaveBeenCalled(),
);
expect(mockedRequestBodyInterceptor).toHaveBeenCalledWith(
expect.stringContaining(
`<Tagging xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><TagSet><Tag><Key>${key1}</Key><Value>${value1}</Value></Tag><Tag><Key>${key2}</Key><Value>${value2}</Value></Tag></TagSet></Tagging>`,
`<Tagging xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><TagSet><Tag><Key>${key1}</Key><Value>${value1}</Value></Tag><Tag><Key>${key2}</Key><Value>${value2}</Value></Tag><Tag><Key>${key3}</Key><Value>${value3}</Value></Tag></TagSet></Tagging>`,
),
);
});
Expand Down

0 comments on commit dd430eb

Please sign in to comment.