test: add postActionsBar test cases

This commit is contained in:
Awais Ansari
2022-02-04 18:23:47 +05:00
parent a1b8c69dd6
commit c0f2e305c2
3 changed files with 72 additions and 3 deletions

View File

@@ -56,7 +56,7 @@ describe('DiscussionsHome', () => {
await screen.findByTestId('topics-view');
});
test('full view should show header and footer and hide close button', async () => {
test('full view should show header, footer and feedback button and hide close button', async () => {
renderComponent(`/${courseId}/topics`);
expect(screen.queryByText(navigationBarMessages.allTopics.defaultMessage))
.toBeInTheDocument();
@@ -71,9 +71,11 @@ describe('DiscussionsHome', () => {
// Footer should be visible
expect(screen.queryByRole('contentinfo'))
.toBeInTheDocument();
expect(screen.queryByTestId('feedback').childElementCount).toEqual(1);
});
test('in-context view should hide header and footer and show close button', async () => {
test('in-context view should hide header and footer and show close and feedback button', async () => {
renderComponent(`/${courseId}/topics?inContext`);
expect(screen.queryByText(navigationBarMessages.allTopics.defaultMessage))
@@ -91,5 +93,6 @@ describe('DiscussionsHome', () => {
expect(screen.queryByRole('contentinfo'))
.not
.toBeInTheDocument();
expect(screen.queryByTestId('feedback').childElementCount).toEqual(1);
});
});

View File

@@ -30,7 +30,7 @@ function PostActionsBar({
const handleCloseInContext = () => null;
return (
<div className="d-flex justify-content-end py-1 flex-grow-1">
<div className="mr-3">
<div className="mr-3" data-testid="feedback">
<Feedback />
</div>
{!inContext && (

View File

@@ -0,0 +1,66 @@
import { render, screen } from '@testing-library/react';
import { IntlProvider } from 'react-intl';
import { Context as ResponsiveContext } from 'react-responsive';
import { getConfig, initializeMockApp, setConfig } from '@edx/frontend-platform';
import { AppProvider } from '@edx/frontend-platform/react';
import { initializeStore } from '../../../store';
import messages from './messages';
import PostActionsBar from './PostActionsBar';
let store;
function renderComponent(inContext) {
render(
<IntlProvider locale="en">
<ResponsiveContext.Provider value={{ width: 1280 }}>
<AppProvider store={store}>
<PostActionsBar inContext={inContext} />
</AppProvider>
</ResponsiveContext.Provider>
</IntlProvider>,
);
}
describe.each([
{ inContext: false },
{ inContext: true },
])('PostActionsBar', ({ inContext }) => {
beforeEach(async () => {
setConfig({
...getConfig(),
FEEDER_PROJECT_ID: 'test-id',
});
initializeMockApp({
authenticatedUser: {
userId: 3,
username: 'abc123',
email: 'abc123@example.com',
administrator: true,
roles: [],
},
});
store = initializeStore();
});
test(`'full view should show feedback, add post, ${inContext ? 'close button and title and hide searchbar'
: 'searchbar and hide title and close button'} when inContext is ${inContext}`, () => {
renderComponent(inContext);
expect(screen.queryByTestId('feedback').childElementCount).toEqual(1);
expect(screen.queryByRole('button', { name: 'Add a post' })).toBeInTheDocument();
if (inContext) {
expect(screen.queryByPlaceholderText(messages.searchAllPosts.defaultMessage)).not.toBeInTheDocument();
expect(screen.queryByText(messages.title.defaultMessage)).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Close' })).toBeInTheDocument();
} else {
expect(screen.queryByPlaceholderText(messages.searchAllPosts.defaultMessage)).toBeInTheDocument();
expect(screen.queryByText(messages.title.defaultMessage)).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Close' })).not.toBeInTheDocument();
}
});
});