refactor: open review tab in course libraries if out of sync (#1743)
This commit is contained in:
@@ -76,11 +76,16 @@ describe('<CourseLibraries />', () => {
|
|||||||
|
|
||||||
it('shows alert when out of sync components are present', async () => {
|
it('shows alert when out of sync components are present', async () => {
|
||||||
await renderCourseLibrariesPage(mockGetEntityLinks.courseKey);
|
await renderCourseLibrariesPage(mockGetEntityLinks.courseKey);
|
||||||
|
const allTab = await screen.findByRole('tab', { name: 'Libraries' });
|
||||||
|
const reviewTab = await screen.findByRole('tab', { name: 'Review Content Updates 5' });
|
||||||
|
// review tab should be open by default as outOfSyncCount is greater than 0
|
||||||
|
expect(reviewTab).toHaveAttribute('aria-selected', 'true');
|
||||||
|
|
||||||
|
userEvent.click(allTab);
|
||||||
const alert = await screen.findByRole('alert');
|
const alert = await screen.findByRole('alert');
|
||||||
expect(await within(alert).findByText(
|
expect(await within(alert).findByText(
|
||||||
'5 library components are out of sync. Review updates to accept or ignore changes',
|
'5 library components are out of sync. Review updates to accept or ignore changes',
|
||||||
)).toBeInTheDocument();
|
)).toBeInTheDocument();
|
||||||
const allTab = await screen.findByRole('tab', { name: 'Libraries' });
|
|
||||||
expect(allTab).toHaveAttribute('aria-selected', 'true');
|
expect(allTab).toHaveAttribute('aria-selected', 'true');
|
||||||
|
|
||||||
const reviewBtn = await screen.findByRole('button', { name: 'Review' });
|
const reviewBtn = await screen.findByRole('button', { name: 'Review' });
|
||||||
@@ -104,16 +109,21 @@ describe('<CourseLibraries />', () => {
|
|||||||
|
|
||||||
it('hide alert on dismiss', async () => {
|
it('hide alert on dismiss', async () => {
|
||||||
await renderCourseLibrariesPage(mockGetEntityLinks.courseKey);
|
await renderCourseLibrariesPage(mockGetEntityLinks.courseKey);
|
||||||
|
const reviewTab = await screen.findByRole('tab', { name: 'Review Content Updates 5' });
|
||||||
|
// review tab should be open by default as outOfSyncCount is greater than 0
|
||||||
|
expect(reviewTab).toHaveAttribute('aria-selected', 'true');
|
||||||
|
const allTab = await screen.findByRole('tab', { name: 'Libraries' });
|
||||||
|
userEvent.click(allTab);
|
||||||
|
expect(allTab).toHaveAttribute('aria-selected', 'true');
|
||||||
|
|
||||||
const alert = await screen.findByRole('alert');
|
const alert = await screen.findByRole('alert');
|
||||||
expect(await within(alert).findByText(
|
expect(await within(alert).findByText(
|
||||||
'5 library components are out of sync. Review updates to accept or ignore changes',
|
'5 library components are out of sync. Review updates to accept or ignore changes',
|
||||||
)).toBeInTheDocument();
|
)).toBeInTheDocument();
|
||||||
const dismissBtn = await screen.findByRole('button', { name: 'Dismiss' });
|
const dismissBtn = await screen.findByRole('button', { name: 'Dismiss' });
|
||||||
userEvent.click(dismissBtn);
|
userEvent.click(dismissBtn);
|
||||||
const allTab = await screen.findByRole('tab', { name: 'Libraries' });
|
|
||||||
expect(allTab).toHaveAttribute('aria-selected', 'true');
|
expect(allTab).toHaveAttribute('aria-selected', 'true');
|
||||||
|
waitFor(() => expect(alert).not.toBeInTheDocument());
|
||||||
expect(alert).not.toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, {
|
import React, {
|
||||||
useCallback, useMemo, useState,
|
useCallback, useEffect, useMemo, useState,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { Helmet } from 'react-helmet';
|
import { Helmet } from 'react-helmet';
|
||||||
import { getConfig } from '@edx/frontend-platform';
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
@@ -105,7 +105,7 @@ export const CourseLibraries: React.FC<Props> = ({ courseId }) => {
|
|||||||
const courseDetails = useModel('courseDetails', courseId);
|
const courseDetails = useModel('courseDetails', courseId);
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const [tabKey, setTabKey] = useState<CourseLibraryTabs>(
|
const [tabKey, setTabKey] = useState<CourseLibraryTabs>(
|
||||||
() => searchParams.get('tab') as CourseLibraryTabs || CourseLibraryTabs.all,
|
() => searchParams.get('tab') as CourseLibraryTabs,
|
||||||
);
|
);
|
||||||
const [showReviewAlert, setShowReviewAlert] = useState(false);
|
const [showReviewAlert, setShowReviewAlert] = useState(false);
|
||||||
const { data: libraries, isLoading } = useEntityLinksSummaryByDownstreamContext(courseId);
|
const { data: libraries, isLoading } = useEntityLinksSummaryByDownstreamContext(courseId);
|
||||||
@@ -124,6 +124,19 @@ export const CourseLibraries: React.FC<Props> = ({ courseId }) => {
|
|||||||
setTabKey(selectedTab);
|
setTabKey(selectedTab);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTabKey((prev) => {
|
||||||
|
if (outOfSyncCount > 0) {
|
||||||
|
return CourseLibraryTabs.review;
|
||||||
|
}
|
||||||
|
if (prev) {
|
||||||
|
return prev;
|
||||||
|
}
|
||||||
|
/* istanbul ignore next */
|
||||||
|
return CourseLibraryTabs.all;
|
||||||
|
});
|
||||||
|
}, [outOfSyncCount]);
|
||||||
|
|
||||||
const renderLibrariesTabContent = useCallback(() => {
|
const renderLibrariesTabContent = useCallback(() => {
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
|
|||||||
Reference in New Issue
Block a user