Skip to content

Commit 1d6abc6

Browse files
authored
Disable planner conflicts in non-current years (#3752)
1 parent 3e1ce70 commit 1d6abc6

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { mount } from 'enzyme';
2+
import { DragDropContextProps, DraggableProps, DroppableProps } from 'react-beautiful-dnd';
3+
import { Provider } from 'react-redux';
4+
import { Router } from 'react-router-dom';
5+
6+
import { PlannerModuleInfo, Conflict } from 'types/planner';
7+
import configureStore from 'bootstrapping/configure-store';
8+
import createHistory from 'test-utils/createHistory';
9+
import config from 'config';
10+
import PlannerSemester from './PlannerSemester';
11+
import plannerModuleStyles from './PlannerModule.scss';
12+
13+
jest.mock('react-beautiful-dnd', () => ({
14+
Droppable: ({ children }: DroppableProps) => children({} as any, {} as any),
15+
Draggable: ({ children }: DraggableProps) => children({} as any, {} as any, {} as any),
16+
DragDropContext: ({ children }: DragDropContextProps) => children,
17+
}));
18+
19+
function makePlannerSemester(year: string, semester: number, modules: PlannerModuleInfo[]) {
20+
const { store } = configureStore();
21+
const { history } = createHistory();
22+
23+
const addModule = jest.fn();
24+
const removeModule = jest.fn();
25+
const addCustomData = jest.fn();
26+
const setPlaceholderModule = jest.fn();
27+
const addModuleToTimetable = jest.fn();
28+
29+
return mount(
30+
<Provider store={store}>
31+
<Router history={history}>
32+
<PlannerSemester
33+
year={year}
34+
semester={semester}
35+
modules={modules}
36+
addModule={addModule}
37+
removeModule={removeModule}
38+
addCustomData={addCustomData}
39+
setPlaceholderModule={setPlaceholderModule}
40+
addModuleToTimetable={addModuleToTimetable}
41+
/>
42+
</Router>
43+
</Provider>,
44+
);
45+
}
46+
47+
test('should show conflicts for current year', () => {
48+
const conflict: Conflict = {
49+
type: 'semester',
50+
semestersOffered: [],
51+
};
52+
53+
const modules: PlannerModuleInfo[] = [
54+
{
55+
id: '0',
56+
moduleCode: 'UTC1702G',
57+
conflict,
58+
},
59+
];
60+
61+
const wrapper = makePlannerSemester(config.academicYear, 1, modules);
62+
expect(wrapper.find(`.${plannerModuleStyles.conflicts}`).exists()).toBe(true);
63+
});
64+
65+
test('should not show conflicts for non-current years', () => {
66+
const conflict: Conflict = {
67+
type: 'semester',
68+
semestersOffered: [],
69+
};
70+
71+
const modules: PlannerModuleInfo[] = [
72+
{
73+
id: '0',
74+
moduleCode: 'UTC1702G',
75+
conflict,
76+
},
77+
];
78+
79+
const wrapper = makePlannerSemester('2015/2016', 1, modules);
80+
expect(wrapper.find(`.${plannerModuleStyles.conflicts}`).exists()).toBe(false);
81+
});

website/src/views/planner/PlannerSemester.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const PlannerSemester: React.FC<Props> = ({
8989
moduleTitle={getModuleTitle(plannerModule)}
9090
examDate={showExamDate && moduleInfo ? getExamDate(moduleInfo, semester) : null}
9191
moduleCredit={showModuleMeta ? getModuleCredit(plannerModule) : null}
92-
conflict={conflict}
92+
conflict={year === config.academicYear ? conflict : null}
9393
semester={semester}
9494
isInTimetable={isInTimetable}
9595
removeModule={removeModule}

0 commit comments

Comments
 (0)