diff --git a/src/components/Advertisements/core/AdvertisementEntry/AdvertisementEntry.test.tsx b/src/components/Advertisements/core/AdvertisementEntry/AdvertisementEntry.test.tsx index aae41000bf..6148c5bf50 100644 --- a/src/components/Advertisements/core/AdvertisementEntry/AdvertisementEntry.test.tsx +++ b/src/components/Advertisements/core/AdvertisementEntry/AdvertisementEntry.test.tsx @@ -54,16 +54,18 @@ describe('Testing Advertisement Entry Component', () => { - + { + + } @@ -131,7 +133,7 @@ describe('Testing Advertisement Entry Component', () => { startDate={new Date()} id="1" key={1} - mediaUrl="google.com" + mediaUrl="" name="Advert1" organizationId="1" type="POPUP" @@ -173,7 +175,7 @@ describe('Testing Advertisement Entry Component', () => { advertisement: { _id: '1', name: 'Updated Advertisement', - mediaUrl: 'google.com', + mediaUrl: '', startDate: dayjs(new Date()).add(1, 'day').format('YYYY-MM-DD'), endDate: dayjs(new Date()).add(2, 'days').format('YYYY-MM-DD'), type: 'BANNER', @@ -196,7 +198,7 @@ describe('Testing Advertisement Entry Component', () => { type="POPUP" name="Advert1" organizationId="1" - mediaUrl="google.com" + mediaUrl="" id="1" /> } @@ -218,13 +220,6 @@ describe('Testing Advertisement Entry Component', () => { 'Updated Advertisement' ); - fireEvent.change(screen.getByLabelText(translations.Rlink), { - target: { value: 'http://example.com' }, - }); - expect(screen.getByLabelText(translations.Rlink)).toHaveValue( - 'http://example.com' - ); - fireEvent.change(screen.getByLabelText(translations.Rtype), { target: { value: 'BANNER' }, }); @@ -244,7 +239,6 @@ describe('Testing Advertisement Entry Component', () => { variables: { id: '1', name: 'Updated Advertisement', - link: 'http://example.com', type: 'BANNER', startDate: dayjs().add(1, 'day').format('YYYY-MM-DD'), endDate: dayjs().add(2, 'days').format('YYYY-MM-DD'), @@ -275,7 +269,7 @@ describe('Testing Advertisement Entry Component', () => { type="POPUP" name="Advert1" organizationId="1" - mediaUrl="google.com" + mediaUrl="" id="1" /> } @@ -332,7 +326,7 @@ describe('Testing Advertisement Entry Component', () => { startDateEdit={new Date()} typeEdit="POPUP" organizationId="1" - advertisementMediaEdit="google.com" + advertisementMediaEdit="" /> } @@ -343,19 +337,11 @@ describe('Testing Advertisement Entry Component', () => { fireEvent.click(screen.getByTestId('editBtn')); - fireEvent.change(screen.getByLabelText(translations.Rlink), { - target: { value: 'http://example.com' }, - }); - expect(screen.getByLabelText(translations.Rlink)).toHaveValue( - 'http://example.com' - ); - fireEvent.click(screen.getByTestId('addonupdate')); expect(updateAdByIdMock).toHaveBeenCalledWith({ variables: { id: '-100', - link: 'http://example.com', }, }); }); @@ -400,13 +386,6 @@ describe('Testing Advertisement Entry Component', () => { 'Updated Advertisement' ); - fireEvent.change(screen.getByLabelText(translations.Rlink), { - target: { value: 'http://example.com' }, - }); - expect(screen.getByLabelText(translations.Rlink)).toHaveValue( - 'http://example.com' - ); - fireEvent.change(screen.getByLabelText(translations.Rtype), { target: { value: 'BANNER' }, }); @@ -432,7 +411,7 @@ describe('Testing Advertisement Entry Component', () => { variables: { organizationId: '1', name: 'Updated Advertisement', - link: 'http://example.com', + file: '', type: 'BANNER', startDate: dayjs(new Date('2023-01-01')).format('YYYY-MM-DD'), endDate: dayjs(new Date('2023-02-01')).format('YYYY-MM-DD'), diff --git a/src/components/Advertisements/core/AdvertisementRegister/AdvertisementRegister.test.tsx b/src/components/Advertisements/core/AdvertisementRegister/AdvertisementRegister.test.tsx index 77a6ce9f18..e2afc213ff 100644 --- a/src/components/Advertisements/core/AdvertisementRegister/AdvertisementRegister.test.tsx +++ b/src/components/Advertisements/core/AdvertisementRegister/AdvertisementRegister.test.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { render, fireEvent, waitFor, screen } from '@testing-library/react'; +import { render, fireEvent, waitFor, screen, getByTestId } from '@testing-library/react'; import { ApolloClient, @@ -24,6 +24,7 @@ import { ADD_ADVERTISEMENT_MUTATION } from 'GraphQl/Mutations/mutations'; import dayjs from 'dayjs'; import { StaticMockLink } from 'utils/StaticMockLink'; import userEvent from '@testing-library/user-event'; +import AdvertisementEntry from '../AdvertisementEntry/AdvertisementEntry'; jest.mock('react-toastify', () => ({ toast: { @@ -253,6 +254,81 @@ describe('Testing Advertisement Register Component', () => { expect(queryByText(translations.close)).not.toBeInTheDocument(); }); + test('advertisement update', async () => { + const setTimeoutSpy = jest.spyOn(global, 'setTimeout'); + + const { getByLabelText, queryByText } = render( + + + + + { + + } + + + + + ); + + await waitFor(async () => { + const optionsButton = screen.getByTestId('moreiconbtn'); + fireEvent.click(optionsButton); + fireEvent.click(screen.getByTestId('editBtn')); + + fireEvent.change(screen.getByLabelText('Enter name of Advertisement'), { + target: { value: 'Updated Advertisement' }, + }); + + expect(getByLabelText(translations.Rname)).toHaveValue( + 'Updated Advertisement' + ); + + const mediaFile = new File(['media content'], 'test.png', { + type: 'image/png', + }); + + const mediaInput = getByLabelText(translations.Rmedia); + fireEvent.change(mediaInput, { + target: { + files: [mediaFile], + }, + }); + + const mediaPreview = await screen.findByTestId('mediaPreview'); + expect(mediaPreview).toBeInTheDocument(); + + fireEvent.change(getByLabelText(translations.Rtype), { + target: { value: 'BANNER' }, + }); + expect(getByLabelText(translations.Rtype)).toHaveValue('BANNER'); + + fireEvent.change(getByLabelText(translations.RstartDate), { + target: { value: '2023-01-01' }, + }); + expect(getByLabelText(translations.RstartDate)).toHaveValue('2023-01-01'); + + fireEvent.change(getByLabelText(translations.RendDate), { + target: { value: '2023-02-01' }, + }); + expect(getByLabelText(translations.RendDate)).toHaveValue('2023-02-01'); + + fireEvent.click(screen.getByTestId('addonupdate')); + + expect(setTimeoutSpy).toHaveBeenCalled(); + }); + + expect(queryByText(translations.close)).not.toBeInTheDocument(); + }); + test('Logs error to the console and shows error toast when advertisement creation fails', async () => { const { getByText, queryByText } = render( diff --git a/src/components/Advertisements/core/AdvertisementRegister/AdvertisementRegister.tsx b/src/components/Advertisements/core/AdvertisementRegister/AdvertisementRegister.tsx index 4145da7f16..61e97a1d5c 100644 --- a/src/components/Advertisements/core/AdvertisementRegister/AdvertisementRegister.tsx +++ b/src/components/Advertisements/core/AdvertisementRegister/AdvertisementRegister.tsx @@ -33,19 +33,13 @@ interface InterfaceFormStateTypes { endDate: Date; organizationId: string; } -// eslint-disable-next-line @typescript-eslint/no-unused-vars function advertisementRegister({ - /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ - createdBy, formStatus, idEdit, nameEdit, typeEdit, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - orgIdEdit, advertisementMediaEdit, endDateEdit, - // eslint-disable-next-line @typescript-eslint/no-unused-vars startDateEdit, }: InterfaceAddOnRegisterProps): JSX.Element { const { t } = useTranslation('translation', { keyPrefix: 'advertisement' });