Skip to content

Commit 65789d4

Browse files
committed
test: Tests added for new added/deleted states on sync modal
1 parent eb855cb commit 65789d4

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

src/container-comparison/CompareContainersWidget.test.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,48 @@ describe('CompareContainersWidget', () => {
8787
expect(await screen.findByRole('button', { name: 'subsection block 0' })).toBeInTheDocument();
8888
});
8989

90+
test('should show removed container diff state', async () => {
91+
// mocks title
92+
axiosMock.onGet(getLibraryContainerApiUrl(mockGetContainerMetadata.sectionId)).reply(200, { publishedDisplayName: 'Test Title' });
93+
axiosMock.onGet(
94+
getLibraryContainerApiUrl('lct:org1:Demo_course_generated:subsection:subsection-0'),
95+
).reply(200, { publishedDisplayName: 'subsection block 0' });
96+
97+
const user = userEvent.setup();
98+
render(<CompareContainersWidget
99+
upstreamBlockId={mockGetContainerMetadata.sectionId}
100+
downstreamBlockId={mockGetCourseContainerChildren.sectionId}
101+
/>);
102+
expect((await screen.findAllByText('Test Title')).length).toEqual(2);
103+
// left i.e. before side block
104+
const block = await screen.findByText('subsection block 00');
105+
await user.click(block);
106+
107+
const removedRows = await screen.findAllByText('This unit was removed');
108+
await user.click(removedRows[0]);
109+
110+
expect(await screen.findByText('This unit has been removed')).toBeInTheDocument();
111+
});
112+
113+
test('should show new added container diff state', async () => {
114+
// mocks title
115+
axiosMock.onGet(getLibraryContainerApiUrl(mockGetContainerMetadata.sectionId)).reply(200, { publishedDisplayName: 'Test Title' });
116+
axiosMock.onGet(
117+
getLibraryContainerApiUrl('lct:org1:Demo_course_generated:subsection:subsection-0'),
118+
).reply(200, { publishedDisplayName: 'subsection block 0' });
119+
120+
const user = userEvent.setup();
121+
render(<CompareContainersWidget
122+
upstreamBlockId={mockGetContainerMetadata.sectionId}
123+
downstreamBlockId="block-v1:UNIX+UX1+2025_T3+type@section+block@0-new"
124+
/>);
125+
const blocks = await screen.findAllByText('This subsection will be added in the new version');
126+
await user.click(blocks[0]);
127+
128+
screen.logTestingPlaygroundURL();
129+
expect(await screen.findByText(/this subsection is new/i)).toBeInTheDocument();
130+
});
131+
90132
test('should show alert if the only change is a single text component with local overrides', async () => {
91133
const url = getLibraryContainerApiUrl(mockGetContainerMetadata.sectionId);
92134
axiosMock.onGet(url).reply(200, { publishedDisplayName: 'Test Title' });

src/container-comparison/data/api.mock.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as unitApi from '@src/course-unit/data/api';
88
* This mock returns a fixed response for the given container ID.
99
*/
1010
export async function mockGetCourseContainerChildren(containerId: string): Promise<CourseContainerChildrenData> {
11-
const numChildren: number = 3;
11+
let numChildren: number = 3;
1212
let blockType: string;
1313
let displayName: string;
1414
let upstreamReadyToSyncChildrenInfo: UpstreamReadyToSyncChildrenInfo[] = [];
@@ -61,8 +61,9 @@ export async function mockGetCourseContainerChildren(containerId: string): Promi
6161
case mockGetCourseContainerChildren.subsectionIdLoading:
6262
return new Promise(() => { });
6363
default:
64-
blockType = 'unit';
65-
displayName = 'subsection block 00';
64+
blockType = 'section';
65+
displayName = 'section block 00';
66+
numChildren = 0;
6667
break;
6768
}
6869
const children = Array(numChildren).fill(mockGetCourseContainerChildren.childTemplate).map((child, idx) => (

0 commit comments

Comments
 (0)