-
-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f91b130
commit acc9067
Showing
4 changed files
with
164 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React from 'react'; | ||
import { getByTestId, getByText, render, screen } from '@testing-library/react'; | ||
import { MockedProvider } from '@apollo/client/testing'; | ||
import { | ||
ApolloClient, | ||
ApolloProvider, | ||
InMemoryCache, | ||
ApolloLink, | ||
HttpLink, | ||
} from '@apollo/client'; | ||
|
||
import type { NormalizedCacheObject } from '@apollo/client'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import Advertisement from './Advertisements'; | ||
import { Provider } from 'react-redux'; | ||
import { store } from 'state/store'; | ||
import { BACKEND_URL } from 'Constant/constant'; | ||
import i18nForTest from 'utils/i18nForTest'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
import { ADVERTISEMENTS_GET } from 'GraphQl/Queries/Queries'; | ||
|
||
const httpLink = new HttpLink({ | ||
uri: BACKEND_URL, | ||
headers: { | ||
authorization: 'Bearer ' + localStorage.getItem('token') || '', | ||
}, | ||
}); | ||
|
||
const client: ApolloClient<NormalizedCacheObject> = new ApolloClient({ | ||
cache: new InMemoryCache(), | ||
link: ApolloLink.from([httpLink]), | ||
}); | ||
describe('Testing Advertisement Component', () => { | ||
test('Temporary test for Advertisement', () => { | ||
expect(true).toBe(true); | ||
const { getByTestId } = render( | ||
<ApolloProvider client={client}> | ||
<Provider store={store}> | ||
<BrowserRouter> | ||
<I18nextProvider i18n={i18nForTest}> | ||
{<Advertisement />} | ||
</I18nextProvider> | ||
</BrowserRouter> | ||
</Provider> | ||
</ApolloProvider> | ||
); | ||
expect(getByTestId('AdEntryStore')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders advertisement data', async () => { | ||
const mocks = [ | ||
{ | ||
request: { | ||
query: ADVERTISEMENTS_GET, | ||
variables: { | ||
name: 'Test', | ||
}, | ||
}, | ||
result: { | ||
data: { | ||
getAdvertisements: [ | ||
{ | ||
_id: '1', | ||
name: 'Advertisement', | ||
type: 'POPUP', | ||
orgId: 'org1', | ||
link: 'http://example.com', | ||
endDate: new Date(), | ||
startDate: new Date(), | ||
}, | ||
// Add more mock data if needed | ||
], | ||
}, | ||
loading: false, | ||
}, | ||
}, | ||
]; | ||
|
||
const { getByTestId } = render( | ||
<ApolloProvider client={client}> | ||
<Provider store={store}> | ||
<BrowserRouter> | ||
<I18nextProvider i18n={i18nForTest}> | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<Advertisement /> | ||
</MockedProvider> | ||
</I18nextProvider> | ||
</BrowserRouter> | ||
</Provider> | ||
</ApolloProvider> | ||
); | ||
|
||
expect(getByTestId('AdEntryStore')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/components/Advertisements/core/AdvertisementEntry/AdvertisementEntry.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import { getByTestId, getByText, render, screen } from '@testing-library/react'; | ||
|
||
import { | ||
ApolloClient, | ||
ApolloProvider, | ||
InMemoryCache, | ||
ApolloLink, | ||
HttpLink, | ||
} from '@apollo/client'; | ||
|
||
import type { NormalizedCacheObject } from '@apollo/client'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import AdvertisementEntry from './AdvertisementEntry'; | ||
import { Provider } from 'react-redux'; | ||
import { store } from 'state/store'; | ||
import { BACKEND_URL } from 'Constant/constant'; | ||
import i18nForTest from 'utils/i18nForTest'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
|
||
const httpLink = new HttpLink({ | ||
uri: BACKEND_URL, | ||
headers: { | ||
authorization: 'Bearer ' + localStorage.getItem('token') || '', | ||
}, | ||
}); | ||
|
||
const client: ApolloClient<NormalizedCacheObject> = new ApolloClient({ | ||
cache: new InMemoryCache(), | ||
link: ApolloLink.from([httpLink]), | ||
}); | ||
describe('Testing Advertisement Entry Component', () => { | ||
test('Temporary test for Advertisement Entry', () => { | ||
const { getByTestId, getByText, getAllByText } = render( | ||
<ApolloProvider client={client}> | ||
<Provider store={store}> | ||
<BrowserRouter> | ||
<I18nextProvider i18n={i18nForTest}> | ||
{ | ||
<AdvertisementEntry | ||
endDate={new Date()} | ||
startDate={new Date()} | ||
id="1" | ||
key={1} | ||
link="google.com" | ||
name="Advert1" | ||
orgId="1" | ||
type="POPUP" | ||
/> | ||
} | ||
</I18nextProvider> | ||
</BrowserRouter> | ||
</Provider> | ||
</ApolloProvider> | ||
); | ||
expect(getByTestId('AdEntry')).toBeInTheDocument(); | ||
expect(getAllByText('POPUP')[0]).toBeInTheDocument(); | ||
expect(getAllByText('Advert1')[0]).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters