Skip to content

Commit

Permalink
Advertisement Date Issue While editing is Solved. (#1553)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitSharma512 authored Feb 7, 2024
1 parent 12d6cdb commit 7d26438
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,65 @@ describe('Testing Advertisement Register Component', () => {
);
});
});
test('Throws error when the end date is less than the start date while editing the advertisement', async () => {
const { getByText, getByLabelText, queryByText } = render(
<MockedProvider addTypename={false} link={link}>
<Provider store={store}>
<BrowserRouter>
<I18nextProvider i18n={i18n}>
{
<AdvertisementRegister
formStatus="edit"
endDate={new Date()}
startDate={new Date()}
type="BANNER"
name="Advert1"
orgId="1"
link="google.com"
/>
}
</I18nextProvider>
</BrowserRouter>
</Provider>
</MockedProvider>
);

fireEvent.click(getByText(translations.edit));
expect(queryByText(translations.editAdvertisement)).toBeInTheDocument();
fireEvent.change(getByLabelText(translations.Rname), {
target: { value: 'Test Advertisement' },
});
expect(getByLabelText(translations.Rname)).toHaveValue(
'Test Advertisement'
);

fireEvent.change(getByLabelText(translations.Rlink), {
target: { value: 'http://example.com' },
});
expect(getByLabelText(translations.Rlink)).toHaveValue(
'http://example.com'
);

fireEvent.change(getByLabelText(translations.Rtype), {
target: { value: 'BANNER' },
});
expect(getByLabelText(translations.Rtype)).toHaveValue('BANNER');

fireEvent.change(getByLabelText(translations.RstartDate), {
target: { value: '2023-02-02' },
});
expect(getByLabelText(translations.RstartDate)).toHaveValue('2023-02-02');

fireEvent.change(getByLabelText(translations.RendDate), {
target: { value: '2023-01-01' },
});
expect(getByLabelText(translations.RendDate)).toHaveValue('2023-01-01');

fireEvent.click(getByText(translations.saveChanges));
await waitFor(() => {
expect(toast.error).toBeCalledWith(
'End date must be greater than or equal to start date'
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ function advertisementRegister({
if (formState.type !== typeEdit) {
updatedFields.type = formState.type;
}
if (formState.endDate < formState.startDate) {
toast.error('End date must be greater than or equal to start date');
return;
}
const startDateFormattedString = dayjs(formState.startDate).format(
'YYYY-MM-DD'
);
Expand Down

0 comments on commit 7d26438

Please sign in to comment.