|
| 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 | +}); |
0 commit comments