diff --git a/src/discussions/discussions-home/DiscussionsHome.test.jsx b/src/discussions/discussions-home/DiscussionsHome.test.jsx index 243e35b9..a57da1bf 100644 --- a/src/discussions/discussions-home/DiscussionsHome.test.jsx +++ b/src/discussions/discussions-home/DiscussionsHome.test.jsx @@ -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); }); }); diff --git a/src/discussions/posts/post-actions-bar/PostActionsBar.jsx b/src/discussions/posts/post-actions-bar/PostActionsBar.jsx index ff6b13db..50f2336a 100644 --- a/src/discussions/posts/post-actions-bar/PostActionsBar.jsx +++ b/src/discussions/posts/post-actions-bar/PostActionsBar.jsx @@ -30,7 +30,7 @@ function PostActionsBar({ const handleCloseInContext = () => null; return (
-
+
{!inContext && ( diff --git a/src/discussions/posts/post-actions-bar/PostActionsBar.test.jsx b/src/discussions/posts/post-actions-bar/PostActionsBar.test.jsx new file mode 100644 index 00000000..ef73d6b6 --- /dev/null +++ b/src/discussions/posts/post-actions-bar/PostActionsBar.test.jsx @@ -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( + + + + + + + , + ); +} + +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(); + } + }); +});