Skip to content

Commit 7629f42

Browse files
committed
test: add tests
1 parent d7cd6b1 commit 7629f42

4 files changed

Lines changed: 33 additions & 6 deletions

File tree

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useSelector } from 'react-redux';
22
import { getConfig, setConfig } from '@edx/frontend-platform';
33
import { renderHook } from '@testing-library/react';
44
import messages from './messages';
5-
import { useContentMenuItems, useToolsMenuItems, useSettingMenuItems } from './hooks';
5+
import { useContentMenuItems, useToolsMenuItems, useSettingMenuItems, useLibrarySettingsMenuItems, useLibraryToolsMenuItems } from './hooks';
66
import { mockWaffleFlags } from '../data/apiHooks.mock';
77

88
jest.mock('@edx/frontend-platform/i18n', () => ({
@@ -28,7 +28,7 @@ jest.mock('react-redux', () => ({
2828
describe('header utils', () => {
2929
describe('getContentMenuItems', () => {
3030
it('when video upload page enabled should include Video Uploads option', () => {
31-
useSelector.mockReturnValue({
31+
jest.mocked(useSelector).mockReturnValue({
3232
librariesV2Enabled: false,
3333
});
3434
setConfig({
@@ -39,7 +39,7 @@ describe('header utils', () => {
3939
expect(actualItems).toHaveLength(5);
4040
});
4141
it('when video upload page disabled should not include Video Uploads option', () => {
42-
useSelector.mockReturnValue({
42+
jest.mocked(useSelector).mockReturnValue({
4343
librariesV2Enabled: false,
4444
});
4545
setConfig({
@@ -50,7 +50,7 @@ describe('header utils', () => {
5050
expect(actualItems).toHaveLength(4);
5151
});
5252
it('adds course libraries link to content menu when libraries v2 is enabled', () => {
53-
useSelector.mockReturnValue({
53+
jest.mocked(useSelector).mockReturnValue({
5454
librariesV2Enabled: true,
5555
});
5656
const actualItems = renderHook(() => useContentMenuItems('course-123')).result.current;
@@ -60,7 +60,7 @@ describe('header utils', () => {
6060

6161
describe('getSettingsMenuitems', () => {
6262
beforeEach(() => {
63-
useSelector.mockReturnValue({
63+
jest.mocked(useSelector).mockReturnValue({
6464
canAccessAdvancedSettings: true,
6565
});
6666
});
@@ -86,7 +86,7 @@ describe('header utils', () => {
8686
expect(actualItemsTitle).toContain('Advanced Settings');
8787
});
8888
it('when user has no access to advanced settings should not include advanced settings option', () => {
89-
useSelector.mockReturnValue({ canAccessAdvancedSettings: false });
89+
jest.mocked(useSelector).mockReturnValue({ canAccessAdvancedSettings: false });
9090
const actualItemsTitle = renderHook(() => useSettingMenuItems('course-123')).result.current.map((item) => item.title);
9191
expect(actualItemsTitle).not.toContain('Advanced Settings');
9292
});
@@ -137,4 +137,22 @@ describe('header utils', () => {
137137
expect(actualItemsTitle).not.toContain(messages['header.links.optimizer'].defaultMessage);
138138
});
139139
});
140+
141+
describe('useLibrarySettingsMenuItems', () => {
142+
it('should contain team access url', () => {
143+
const items = renderHook(() => useLibrarySettingsMenuItems()).result.current;
144+
expect(items).toContainEqual({ title: 'Team Access', href: 'http://localhost/?sa=manage-team' });
145+
});
146+
});
147+
148+
describe('useLibraryToolsMenuItems', () => {
149+
it('should contain backup and import url', () => {
150+
const items = renderHook(() => useLibraryToolsMenuItems('course-123')).result.current;
151+
expect(items).toContainEqual({
152+
href: '/library/course-123/backup',
153+
title: 'Backup to local archive'
154+
});
155+
expect(items).toContainEqual({ href: '/library/course-123/import', title: 'Import' });
156+
});
157+
});
140158
});

src/header/hooks.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ export const useLibraryToolsMenuItems = (itemId: string) => {
136136
href: `/library/${itemId}/backup`,
137137
title: intl.formatMessage(messages['header.links.exportLibrary']),
138138
},
139+
{
140+
href: `/library/${itemId}/import`,
141+
title: intl.formatMessage(messages['header.links.lib.import']),
142+
},
139143
];
140144

141145
return items;
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ const messages = defineMessages({
9696
defaultMessage: 'Import',
9797
description: 'Link to Studio Import page',
9898
},
99+
'header.links.lib.import': {
100+
id: 'header.links.lib.import',
101+
defaultMessage: 'Import',
102+
description: 'Link to Course Import page in library',
103+
},
99104
'header.links.exportCourse': {
100105
id: 'header.links.exportCourse',
101106
defaultMessage: 'Export Course',

0 commit comments

Comments
 (0)