Skip to content

Commit

Permalink
test: add test for new section functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Nov 24, 2023
1 parent 5f00467 commit 22ded92
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/course-outline/CourseOutline.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getXBlockBaseApiUrl,
} from './data/api';
import {
addNewCourseSectionQuery,
deleteCourseSectionQuery,
duplicateCourseSectionQuery,
editCourseSectionQuery,
Expand All @@ -37,6 +38,7 @@ import {
courseOutlineIndexWithoutSections,
courseBestPracticesMock,
courseLaunchMock,
courseSectionMock,
} from './__mocks__';
import { executeThunk } from '../utils';
import CourseOutline from './CourseOutline';
Expand Down Expand Up @@ -111,6 +113,25 @@ describe('<CourseOutline />', () => {
expect(getByText(messages.alertSuccessDescription.defaultMessage)).toBeInTheDocument();
});

it('adds new section correctly', async () => {
const { findAllByTestId } = render(<RootWrapper />);
let element = await findAllByTestId('section-card');
expect(element.length).toBe(4);

axiosMock
.onPost(getXBlockBaseApiUrl())
.reply(200, {
"locator": courseSectionMock.id,
});
axiosMock
.onGet(getXBlockApiUrl(courseSectionMock.id))
.reply(200, courseSectionMock);
await executeThunk(addNewCourseSectionQuery(courseId), store.dispatch);

element = await findAllByTestId('section-card');
expect(element.length).toBe(5);
});

it('render error alert after failed reindex correctly', async () => {
const { getByText } = render(<RootWrapper />);

Expand Down
93 changes: 93 additions & 0 deletions src/course-outline/__mocks__/courseSection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
module.exports = {
id: "block-v1:edX+DemoX+Demo_Course+type@chapter+block@d0e78d363a424da6be5c22704c34f7a7",
display_name: "Section",
category: "chapter",
has_children: true,
edited_on: "Nov 22, 2023 at 07:45 UTC",
published: true,
published_on: "Nov 22, 2023 at 07:45 UTC",
studio_url: "/course/course-v1:edX+DemoX+Demo_Course?show=block-v1%3AedX%2BDemoX%2BDemo_Course%2Btype%40chapter%2Bblock%40d0e78d363a424da6be5c22704c34f7a7",
released_to_students: true,
release_date: "Feb 05, 2013 at 05:00 UTC",
visibility_state: "live",
has_explicit_staff_lock: false,
start: "2013-02-05T05:00:00Z",
graded: false,
due_date: "",
due: null,
relative_weeks_due: null,
format: null,
course_graders: [
"Homework",
"Exam"
],
has_changes: false,
actions: {
deletable: true,
draggable: true,
childAddable: true,
duplicable: true
},
explanatory_message: null,
group_access: {},
user_partitions: [
{
id: 50,
name: "Enrollment Track Groups",
scheme: "enrollment_track",
groups: [
{
id: 2,
name: "Verified Certificate",
selected: false,
deleted: false
},
{
id: 1,
name: "Audit",
selected: false,
deleted: false
}
]
}
],
show_correctness: "always",
highlights: [],
highlights_enabled: true,
highlights_preview_only: false,
highlights_doc_url: "http://edx.readthedocs.io/projects/open-edx-building-and-running-a-course/en/latest/developing_course/course_sections.html#set-section-highlights-for-weekly-course-highlight-messages",
child_info: {
category: "sequential",
display_name: "Subsection",
children: []
},
ancestor_has_staff_lock: false,
staff_only_message: false,
enable_copy_paste_units: false,
has_partition_group_components: false,
user_partition_info: {
selectable_partitions: [
{
id: 50,
name: "Enrollment Track Groups",
scheme: "enrollment_track",
groups: [
{
id: 2,
name: "Verified Certificate",
selected: false,
deleted: false
},
{
id: 1,
name: "Audit",
selected: false,
deleted: false
}
]
}
],
selected_partition_index: -1,
selected_groups_label: ""
}
}
1 change: 1 addition & 0 deletions src/course-outline/__mocks__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as courseOutlineIndexMock } from './courseOutlineIndex';
export { default as courseOutlineIndexWithoutSections } from './courseOutlineIndexWithoutSections';
export { default as courseBestPracticesMock } from './courseBestPractices';
export { default as courseLaunchMock } from './courseLaunch';
export { default as courseSectionMock } from './courseSection';

0 comments on commit 22ded92

Please sign in to comment.