-
-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'PalisadoesFoundation:develop' into develop
- Loading branch information
Showing
9 changed files
with
161 additions
and
20 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
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
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
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
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
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
127 changes: 127 additions & 0 deletions
127
src/components/UserPortal/PromotedPost/PromotedPost.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,127 @@ | ||
import React from 'react'; | ||
import { act, render, waitFor } from '@testing-library/react'; | ||
import { MockedProvider } from '@apollo/react-testing'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
|
||
import { BrowserRouter } from 'react-router-dom'; | ||
import { Provider } from 'react-redux'; | ||
import { store } from 'state/store'; | ||
import i18nForTest from 'utils/i18nForTest'; | ||
import { StaticMockLink } from 'utils/StaticMockLink'; | ||
import PromotedPost from './PromotedPost'; | ||
|
||
const link = new StaticMockLink([], true); | ||
|
||
async function wait(ms = 100): Promise<void> { | ||
await act(() => { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
}); | ||
} | ||
|
||
let props = { | ||
id: '1', | ||
image: '', | ||
title: 'Test Post', | ||
}; | ||
|
||
describe('Testing PromotedPost Test', () => { | ||
test('Component should be rendered properly', async () => { | ||
render( | ||
<MockedProvider addTypename={false} link={link}> | ||
<BrowserRouter> | ||
<Provider store={store}> | ||
<I18nextProvider i18n={i18nForTest}> | ||
<PromotedPost {...props} /> | ||
</I18nextProvider> | ||
</Provider> | ||
</BrowserRouter> | ||
</MockedProvider> | ||
); | ||
|
||
await wait(); | ||
}); | ||
|
||
test('Component should be rendered properly if prop image is not undefined', async () => { | ||
props = { | ||
...props, | ||
image: 'promotedPostImage', | ||
}; | ||
|
||
render( | ||
<MockedProvider addTypename={false} link={link}> | ||
<BrowserRouter> | ||
<Provider store={store}> | ||
<I18nextProvider i18n={i18nForTest}> | ||
<PromotedPost {...props} /> | ||
</I18nextProvider> | ||
</Provider> | ||
</BrowserRouter> | ||
</MockedProvider> | ||
); | ||
|
||
await wait(); | ||
}); | ||
}); | ||
|
||
test('Component should display the icon correctly', async () => { | ||
const { queryByTestId } = render( | ||
<MockedProvider addTypename={false} link={link}> | ||
<BrowserRouter> | ||
<Provider store={store}> | ||
<I18nextProvider i18n={i18nForTest}> | ||
<PromotedPost {...props} /> | ||
</I18nextProvider> | ||
</Provider> | ||
</BrowserRouter> | ||
</MockedProvider> | ||
); | ||
|
||
await waitFor(() => { | ||
const icon = queryByTestId('StarPurple500Icon'); | ||
expect(icon).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('Component should display the text correctly', async () => { | ||
const { queryAllByText } = render( | ||
<MockedProvider addTypename={false} link={link}> | ||
<BrowserRouter> | ||
<Provider store={store}> | ||
<I18nextProvider i18n={i18nForTest}> | ||
<PromotedPost {...props} /> | ||
</I18nextProvider> | ||
</Provider> | ||
</BrowserRouter> | ||
</MockedProvider> | ||
); | ||
|
||
await waitFor(() => { | ||
const title = queryAllByText('Test Post') as HTMLElement[]; | ||
expect(title[0]).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('Component should display the image correctly', async () => { | ||
props = { | ||
...props, | ||
image: 'promotedPostImage', | ||
}; | ||
const { queryByRole } = render( | ||
<MockedProvider addTypename={false} link={link}> | ||
<BrowserRouter> | ||
<Provider store={store}> | ||
<I18nextProvider i18n={i18nForTest}> | ||
<PromotedPost {...props} /> | ||
</I18nextProvider> | ||
</Provider> | ||
</BrowserRouter> | ||
</MockedProvider> | ||
); | ||
|
||
await waitFor(() => { | ||
const image = queryByRole('img'); | ||
expect(image).toHaveAttribute('src', 'promotedPostImage'); | ||
}); | ||
}); |
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
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