fix: pagination enabled request and test for tab section added again
This commit is contained in:
@@ -26,6 +26,7 @@ import { useStudioHome } from './hooks';
|
||||
import AlertMessage from '../generic/alert-message';
|
||||
|
||||
const StudioHome = ({ intl }) => {
|
||||
const isPaginationCoursesEnabled = getConfig().ENABLE_HOME_PAGE_COURSE_API_V2 === 'true';
|
||||
const {
|
||||
isLoadingPage,
|
||||
isFailedLoadingPage,
|
||||
@@ -39,7 +40,7 @@ const StudioHome = ({ intl }) => {
|
||||
hasAbilityToCreateNewCourse,
|
||||
setShowNewCourseContainer,
|
||||
dispatch,
|
||||
} = useStudioHome();
|
||||
} = useStudioHome(isPaginationCoursesEnabled);
|
||||
|
||||
const {
|
||||
userIsActive,
|
||||
@@ -49,8 +50,6 @@ const StudioHome = ({ intl }) => {
|
||||
redirectToLibraryAuthoringMfe,
|
||||
} = studioHomeData;
|
||||
|
||||
const isPaginationCoursesEnabled = getConfig().ENABLE_HOME_PAGE_COURSE_API_V2 === 'true';
|
||||
|
||||
function getHeaderButtons() {
|
||||
const headerButtons = [];
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
} from './data/selectors';
|
||||
import { updateSavingStatuses } from './data/slice';
|
||||
|
||||
const useStudioHome = () => {
|
||||
const useStudioHome = (isPaginated = false) => {
|
||||
const location = useLocation();
|
||||
const dispatch = useDispatch();
|
||||
const studioHomeData = useSelector(getStudioHomeData);
|
||||
@@ -31,13 +31,17 @@ const useStudioHome = () => {
|
||||
const isFailedLoadingPage = studioHomeLoadingStatus === RequestStatus.FAILED;
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(fetchStudioHomeData(location.search ?? ''));
|
||||
setShowNewCourseContainer(false);
|
||||
if (!isPaginated) {
|
||||
dispatch(fetchStudioHomeData(location.search ?? ''));
|
||||
setShowNewCourseContainer(false);
|
||||
}
|
||||
}, [location.search]);
|
||||
|
||||
useEffect(() => {
|
||||
const { currentPage } = studioHomeCoursesParams;
|
||||
dispatch(fetchStudioHomeData(location.search ?? '', false, { page: currentPage }, true));
|
||||
if (isPaginated) {
|
||||
const { currentPage } = studioHomeCoursesParams;
|
||||
dispatch(fetchStudioHomeData(location.search ?? '', false, { page: currentPage }, true));
|
||||
}
|
||||
}, [studioHomeCoursesParams.currentPage]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -157,6 +157,40 @@ describe('<TabsSection />', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('archived tab', () => {
|
||||
it('should switch to Archived tab and render specific archived course details', async () => {
|
||||
render(<RootWrapper />);
|
||||
axiosMock.onGet(getStudioHomeApiUrl()).reply(200, generateGetStudioHomeDataApiResponse());
|
||||
axiosMock.onGet(courseApiLink).reply(200, generateGetStudioCoursesApiResponse());
|
||||
await executeThunk(fetchStudioHomeData(), store.dispatch);
|
||||
|
||||
const archivedTab = screen.getByText(tabMessages.archivedTabTitle.defaultMessage);
|
||||
fireEvent.click(archivedTab);
|
||||
|
||||
expect(screen.getByText(studioHomeMock.archivedCourses[0].displayName)).toBeVisible();
|
||||
|
||||
expect(screen.getByText(
|
||||
`${studioHomeMock.archivedCourses[0].org} / ${studioHomeMock.archivedCourses[0].number} / ${studioHomeMock.archivedCourses[0].run}`,
|
||||
)).toBeVisible();
|
||||
});
|
||||
|
||||
it('should hide Archived tab when archived courses are empty', async () => {
|
||||
const data = generateGetStudioCoursesApiResponse();
|
||||
data.archivedCourses = [];
|
||||
|
||||
render(<RootWrapper />);
|
||||
axiosMock.onGet(getStudioHomeApiUrl()).reply(200, generateGetStudioHomeDataApiResponse());
|
||||
axiosMock.onGet(courseApiLink).reply(200, data);
|
||||
await executeThunk(fetchStudioHomeData(), store.dispatch);
|
||||
|
||||
expect(screen.getByText(tabMessages.coursesTabTitle.defaultMessage)).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText(tabMessages.librariesTabTitle.defaultMessage)).toBeInTheDocument();
|
||||
|
||||
expect(screen.queryByText(tabMessages.archivedTabTitle.defaultMessage)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('library tab', () => {
|
||||
it('should switch to Libraries tab and render specific library details', async () => {
|
||||
render(<RootWrapper />);
|
||||
|
||||
Reference in New Issue
Block a user