Skip to content

Commit 5b199ff

Browse files
committed
Fix tests
1 parent 6db61a0 commit 5b199ff

5 files changed

Lines changed: 101 additions & 49 deletions

File tree

contentcuration/contentcuration/frontend/channelEdit/components/QuickEditModal/__tests__/EditBooleanMapModal.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ const makeWrapper = ({
7575
confirmationMessage: 'edited',
7676
...restOptions,
7777
},
78+
scopedSlots: {
79+
input: function (props) {
80+
return this.$createElement(CategoryOptions, {
81+
props: {
82+
...props,
83+
expanded: true,
84+
hideLabel: true,
85+
nodeIds,
86+
}
87+
});
88+
}
89+
}
7890
});
7991
};
8092

contentcuration/contentcuration/frontend/shared/views/contentNodeFields/__tests__/categoryOptions.spec.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@ import CategoryOptions from '../CategoryOptions.vue';
55

66
Vue.use(Vuetify);
77

8+
function makeWrapper({ value = {}, nodeIds = ["node1"] } = {}) {
9+
return shallowMount(CategoryOptions, {
10+
propsData: {
11+
value,
12+
nodeIds,
13+
},
14+
});
15+
};
16+
817
describe('CategoryOptions', () => {
918
it('smoke test', () => {
10-
const wrapper = shallowMount(CategoryOptions);
19+
const wrapper = makeWrapper();
1120
expect(wrapper.isVueInstance()).toBe(true);
1221
});
1322
it('emits expected data', () => {
14-
const wrapper = shallowMount(CategoryOptions);
23+
const wrapper = makeWrapper();
1524
const value = 'string';
1625
wrapper.vm.$emit('input', value);
1726

@@ -22,14 +31,14 @@ describe('CategoryOptions', () => {
2231

2332
describe('display', () => {
2433
it('has a tooltip that displays the tree for value of an item', () => {
25-
const wrapper = shallowMount(CategoryOptions);
34+
const wrapper = makeWrapper();
2635
const item = 'd&WXdXWF.5QAjgfv7.BUMJJBnS'; // 'Dance'
2736
const expectedToolTip = 'School - Arts - Dance';
2837

2938
expect(wrapper.vm.tooltipText(item)).toEqual(expectedToolTip);
3039
});
3140
it(`dropdown has 'levels' key necessary to display the nested structure of categories`, () => {
32-
const wrapper = shallowMount(CategoryOptions);
41+
const wrapper = makeWrapper();
3342
const dropdown = wrapper.vm.categoriesList;
3443
const everyCategoryHasLevelsKey = dropdown.every(item => 'level' in item);
3544

@@ -39,37 +48,37 @@ describe('CategoryOptions', () => {
3948

4049
describe('interactions', () => {
4150
it('when user checks an item, that is emitted to the parent component', () => {
42-
const wrapper = shallowMount(CategoryOptions);
51+
const wrapper = makeWrapper();
4352
const item = 'abcd';
4453
wrapper.vm.$emit = jest.fn();
4554
wrapper.vm.add(item);
4655

4756
expect(wrapper.vm.$emit.mock.calls[0][0]).toBe('input');
48-
expect(wrapper.vm.$emit.mock.calls[0][1]).toEqual([item]);
57+
expect(wrapper.vm.$emit.mock.calls[0][1]).toEqual({ abcd: ["node1"] });
4958
});
5059
it('when user unchecks an item, that is emitted to the parent component', () => {
51-
const wrapper = shallowMount(CategoryOptions);
60+
const wrapper = makeWrapper();
5261
const item = 'defj';
5362
wrapper.vm.$emit = jest.fn();
5463
wrapper.vm.remove(item);
5564

5665
expect(wrapper.vm.$emit.mock.calls[0][0]).toBe('input');
57-
expect(wrapper.vm.$emit.mock.calls[0][1]).toEqual([]);
66+
expect(wrapper.vm.$emit.mock.calls[0][1]).toEqual({});
5867
});
5968
});
6069

6170
describe('close button on chip interactions', () => {
62-
it('in the autocomplete bar, the chip is removed when user clicks on its close button', () => {
63-
const wrapper = shallowMount(CategoryOptions, {
64-
data() {
65-
return { selected: ['remove me', 'abc', 'def', 'abc.'] };
66-
},
71+
it('in the autocomplete bar, the chip is removed when user clicks on its close button', async () => {
72+
const wrapper = makeWrapper({
73+
value: {
74+
'remove me': ['node1'],
75+
'keep me': ['node1'],
76+
}
6777
});
68-
const originalChipsLength = wrapper.vm.selected.length;
78+
const originalChipsLength = Object.keys(wrapper.vm.selected).length;
6979
wrapper.vm.remove('remove me');
70-
const chips = wrapper.vm.selected;
7180

72-
expect(chips.length).toEqual(originalChipsLength - 1);
81+
expect(wrapper.emitted().input.length).toEqual(originalChipsLength - 1);
7382
});
7483
});
7584
});

contentcuration/contentcuration/frontend/shared/views/contentNodeFields/__tests__/learningActivityOptions.spec.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import { LearningActivities } from 'shared/constants';
66

77
Vue.use(Vuetify);
88

9-
function makeWrapper(value) {
9+
function makeWrapper({ value = {}, nodeIds = ['node1'] } = {}) {
1010
return mount(LearningActivityOptions, {
1111
propsData: {
1212
value,
13+
nodeIds,
1314
},
1415
});
1516
}
@@ -21,7 +22,7 @@ describe('LearningActivityOptions', () => {
2122
});
2223

2324
it('number of items in the dropdown should be equal to number of items available in ', async () => {
24-
const wrapper = makeWrapper([]);
25+
const wrapper = makeWrapper();
2526
await wrapper.find('.v-input__slot').trigger('click');
2627

2728
const numberOfDropdownItems = Object.keys(LearningActivities).length;
@@ -32,27 +33,35 @@ describe('LearningActivityOptions', () => {
3233

3334
describe('updating state', () => {
3435
it('should update learning_activity field with new values received from a parent', () => {
35-
const learningActivity = ['activity_1', 'activity_2'];
36-
const wrapper = makeWrapper(learningActivity);
36+
const learningActivity = {
37+
activity_1: ['node1'],
38+
activity_2: ['node1'],
39+
};
40+
const wrapper = makeWrapper({ value: learningActivity, nodeIds: ["node1"] });
3741
const dropdown = wrapper.find({ name: 'v-select' });
3842

39-
expect(dropdown.props('value')).toEqual(learningActivity);
43+
expect(dropdown.props('value')).toEqual(['activity_1', 'activity_2']);
4044

4145
wrapper.setProps({
42-
value: ['activity_4'],
46+
value: {
47+
activity_4: ['node1'],
48+
}
4349
});
4450
expect(dropdown.props('value')).toEqual(['activity_4']);
4551
});
4652

4753
it('should emit new input values', () => {
48-
const learningActivity = ['activity_1', 'activity_2', 'activity_3'];
49-
const wrapper = makeWrapper({});
54+
const learningActivity = ['activity_1', 'activity_2'];
55+
const wrapper = makeWrapper();
5056
const dropdown = wrapper.find({ name: 'v-select' });
5157
dropdown.vm.$emit('input', learningActivity);
5258

5359
return Vue.nextTick().then(() => {
5460
const emittedLevels = wrapper.emitted('input').pop()[0];
55-
expect(emittedLevels).toEqual(learningActivity);
61+
expect(emittedLevels).toEqual({
62+
activity_1: ['node1'],
63+
activity_2: ['node1'],
64+
});
5665
});
5766
});
5867
});

contentcuration/contentcuration/frontend/shared/views/contentNodeFields/__tests__/levelsOptions.spec.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import { ContentLevels } from 'shared/constants';
66

77
Vue.use(Vuetify);
88

9-
function makeWrapper(value) {
9+
function makeWrapper({ value = {}, nodeIds = ['node1'] } = {}) {
1010
return mount(LevelsOptions, {
1111
propsData: {
1212
value,
13+
nodeIds,
1314
},
1415
});
1516
}
@@ -22,7 +23,7 @@ describe('LevelsOptions', () => {
2223
});
2324

2425
it('number of items in the dropdown should be equal to number of items available in ContentLevels', async () => {
25-
const wrapper = makeWrapper([]);
26+
const wrapper = makeWrapper();
2627
await wrapper.find('.v-input__slot').trigger('click');
2728

2829
const numberOfAvailableLevels = Object.keys(ContentLevels).length;
@@ -33,27 +34,37 @@ describe('LevelsOptions', () => {
3334

3435
describe('updating state', () => {
3536
it('should update levels field with new values received from a parent', () => {
36-
const levels = ['abc', 'gefo'];
37-
const wrapper = makeWrapper(levels);
37+
const value = {
38+
abc: ['node1'],
39+
gefo: ['node1'],
40+
};
41+
const wrapper = makeWrapper({ value, nodeIds: ["node1"] });
3842
const dropdown = wrapper.find({ name: 'v-select' });
3943

40-
expect(dropdown.props('value')).toEqual(levels);
44+
expect(dropdown.props('value')).toEqual(['abc', 'gefo']);
4145

4246
wrapper.setProps({
43-
value: ['def'],
47+
value: {
48+
def: ['node1'],
49+
}
4450
});
4551
expect(dropdown.props('value')).toEqual(['def']);
4652
});
4753

4854
it('should emit new input values', () => {
49-
const levels = ['abc', 'gefo', '8hw'];
50-
const wrapper = makeWrapper({});
55+
const value = {
56+
abc: ['node1'],
57+
};
58+
const wrapper = makeWrapper({ value, nodeIds: ["node1"] });
5159
const dropdown = wrapper.find({ name: 'v-select' });
52-
dropdown.vm.$emit('input', levels);
60+
dropdown.vm.$emit('input', ['abc', 'gefo']);
5361

5462
return Vue.nextTick().then(() => {
5563
const emittedLevels = wrapper.emitted('input').pop()[0];
56-
expect(emittedLevels).toEqual(levels);
64+
expect(emittedLevels).toEqual({
65+
abc: ['node1'],
66+
gefo: ['node1'],
67+
});
5768
});
5869
});
5970
});

contentcuration/contentcuration/frontend/shared/views/contentNodeFields/__tests__/resourcesNeededOptions.spec.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,55 @@ import ResourcesNeededOptions from '../ResourcesNeededOptions.vue';
55

66
Vue.use(Vuetify);
77

8-
function makeWrapper(value) {
8+
function makeWrapper({ value = {}, nodeIds = ['node1'] } = {}) {
99
return mount(ResourcesNeededOptions, {
1010
propsData: {
1111
value,
12+
nodeIds,
1213
},
1314
});
1415
}
1516

1617
describe('ResourcesNeededOptions', () => {
1718
it('smoke test', () => {
18-
const wrapper = shallowMount(ResourcesNeededOptions);
19+
const wrapper = makeWrapper();
1920

2021
expect(wrapper.isVueInstance()).toBe(true);
2122
});
2223

2324
describe('updating state', () => {
2425
it('should update resources field with new values received from a parent', () => {
25-
const resourcesNeeded = ['person', 'book'];
26-
const wrapper = makeWrapper(resourcesNeeded);
26+
const value = {
27+
person: ['node1'],
28+
book: ['node1'],
29+
};
30+
const wrapper = makeWrapper({ value, nodeIds: ["node1"] });
2731
const dropdown = wrapper.find({ name: 'v-select' });
2832

29-
expect(dropdown.props('value')).toEqual(resourcesNeeded);
33+
expect(dropdown.props('value')).toEqual(['person', 'book']);
3034

3135
wrapper.setProps({
32-
value: ['cat'],
36+
value: {
37+
train: ['node1'],
38+
}
3339
});
34-
expect(dropdown.props('value')).toEqual(['cat']);
40+
expect(dropdown.props('value')).toEqual(['train']);
3541
});
3642

37-
it('should emit new input values', () => {
38-
const resourcesNeeded = ['person', 'book', 'train'];
39-
const wrapper = makeWrapper([]);
43+
it('should emit new input values', async () => {
44+
const resourcesNeeded = {
45+
person: ['node1'],
46+
};
47+
const wrapper = makeWrapper({ value: resourcesNeeded, nodeIds: ["node1"] });
4048
const dropdown = wrapper.find({ name: 'v-select' });
41-
dropdown.vm.$emit('input', resourcesNeeded);
49+
dropdown.vm.$emit('input', ['person', 'book']);
4250

43-
return Vue.nextTick().then(() => {
44-
const emittedLevels = wrapper.emitted('input').pop()[0];
45-
expect(emittedLevels).toEqual(resourcesNeeded);
51+
await wrapper.vm.$nextTick();
52+
53+
const emittedLevels = wrapper.emitted('input').pop()[0];
54+
expect(emittedLevels).toEqual({
55+
person: ['node1'],
56+
book: ['node1'],
4657
});
4758
});
4859
});

0 commit comments

Comments
 (0)