-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrubric.test.jsx
More file actions
91 lines (81 loc) · 3.32 KB
/
rubric.test.jsx
File metadata and controls
91 lines (81 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { shallow, mount } from 'enzyme';
import React from 'react';
import { RawAuthoring } from '../authoring';
import { Draggable } from 'react-beautiful-dnd';
import _ from 'lodash';
jest.mock('../../editable-html', () => () => <div />);
describe('Rubric', () => {
let w;
const points = ['nothing right', 'a teeny bit right', 'mostly right', 'bingo'];
const sampleAnswers = [null, 'just right', 'not left', null];
const wrapper = (value, opts) => {
const props = {
classes: {},
onChange: jest.fn(),
className: 'className',
value: {
excludeZero: false,
points,
sampleAnswers,
...value,
},
};
const fn = opts && opts.mount ? mount : shallow;
return fn(<RawAuthoring {...props} />, opts);
};
describe('render', () => {
it('snapshot', () => {
w = wrapper();
expect(w).toMatchSnapshot();
});
describe('draggable', () => {
it('renders correctly for excluded zeroes', () => {
let w = wrapper({ excludeZero: true }, { mount: true });
expect(w.find(Draggable).length).toEqual(3);
});
it('renders correctly for excluded zeroes', () => {
let w = wrapper({ excludeZero: false }, { mount: true });
expect(w.find(Draggable).length).toEqual(4);
});
});
});
describe('logic', () => {
describe('rendering', () => {});
describe('changeMaxPoints', () => {
const assertChangeMax = (points, excludeZero, expectedPoints, expectedSampleAnswers) => {
it(`${points} calls onChange with: ${expectedPoints} and ${expectedSampleAnswers}`, () => {
let w = wrapper({ excludeZero });
w.instance().changeMaxPoints(points);
expect(w.instance().props.onChange).toHaveBeenCalledWith({
excludeZero,
points: expectedPoints,
sampleAnswers: expectedSampleAnswers,
maxPoints: expectedPoints.length - 1,
});
});
};
assertChangeMax(1, false, _.takeRight(points, 2), _.takeRight(sampleAnswers, 2));
assertChangeMax(1, true, _.takeRight(points, 2), _.takeRight(sampleAnswers, 2));
assertChangeMax(2, true, _.takeRight(points, 3), _.takeRight(sampleAnswers, 3));
assertChangeMax(2, false, _.takeRight(points, 3), _.takeRight(sampleAnswers, 3));
assertChangeMax(5, false, ['', ''].concat(points), [null, null].concat(sampleAnswers));
});
describe('changeSampleResponse', () => {
const assertChangeSample = (index, clickedItem, excludeZero, expectedPoints, expectedSampleAnswers) => {
it(`Point ${index} calls onChange with: ${expectedPoints} and ${expectedSampleAnswers}`, () => {
let w = wrapper({ excludeZero });
w.instance().onPointMenuChange(index, clickedItem);
expect(w.instance().props.onChange).toHaveBeenCalledWith({
excludeZero,
points: expectedPoints,
sampleAnswers: expectedSampleAnswers,
});
});
};
assertChangeSample(0, 'sample', false, points, ['', 'just right', 'not left', null]);
assertChangeSample(3, 'sample', false, points, [null, 'just right', 'not left', '']);
assertChangeSample(1, 'sample', true, points, [null, null, 'not left', null]);
assertChangeSample(3, 'sample', true, points, [null, 'just right', 'not left', '']);
});
});
});