Clean up code
This commit is contained in:
parent
09b19b9d22
commit
7da98d9ae7
|
|
@ -28,8 +28,9 @@
|
||||||
computed: {
|
computed: {
|
||||||
contentBlocks() {
|
contentBlocks() {
|
||||||
return this.contents.map(contentBlock => {
|
return this.contents.map(contentBlock => {
|
||||||
|
const contents = contentBlock.value ? [...contentBlock.value] : [];
|
||||||
return Object.assign({}, contentBlock, {
|
return Object.assign({}, contentBlock, {
|
||||||
contents: [...contentBlock.value],
|
contents,
|
||||||
indent: true,
|
indent: true,
|
||||||
bookmarks: this.parent.bookmarks,
|
bookmarks: this.parent.bookmarks,
|
||||||
notes: this.parent.notes,
|
notes: this.parent.notes,
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,30 @@ export default {
|
||||||
const query = ME_QUERY;
|
const query = ME_QUERY;
|
||||||
if (schoolClass) {
|
if (schoolClass) {
|
||||||
this.$log.debug('updating school class', schoolClass);
|
this.$log.debug('updating school class', schoolClass);
|
||||||
const data = store.readQuery({query});
|
const {me} = store.readQuery({query});
|
||||||
if (data) {
|
if (me) {
|
||||||
data.me.schoolClasses.edges = [
|
let edges = [
|
||||||
...data.me.schoolClasses.edges,
|
...me.schoolClasses.edges,
|
||||||
{
|
{
|
||||||
node: schoolClass,
|
node: schoolClass,
|
||||||
__typename: 'SchoolClassNodeEdge'
|
__typename: 'SchoolClassNodeEdge'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
data.me.selectedClass = {
|
// me.schoolClasses.edges
|
||||||
|
const selectedClass = {
|
||||||
id: schoolClass.id,
|
id: schoolClass.id,
|
||||||
__typename: 'SchoolClassNode'
|
__typename: 'SchoolClassNode'
|
||||||
|
};
|
||||||
|
//me.selectedClass
|
||||||
|
const data = {
|
||||||
|
me: {
|
||||||
|
...me,
|
||||||
|
schoolClasses: {
|
||||||
|
...me.schoolClasses,
|
||||||
|
edges
|
||||||
|
},
|
||||||
|
selectedClass
|
||||||
|
}
|
||||||
};
|
};
|
||||||
store.writeQuery({query, data});
|
store.writeQuery({query, data});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import {createLocalVue, mount} from '@vue/test-utils'
|
import {createLocalVue, mount} from '@vue/test-utils';
|
||||||
import { createMockClient } from 'mock-apollo-client'
|
import { createMockClient } from 'mock-apollo-client';
|
||||||
|
|
||||||
import SIDEBAR from '@/graphql/gql/local/sidebar.gql';
|
import SIDEBAR from '@/graphql/gql/local/sidebar.gql';
|
||||||
import ME_QUERY from '@/graphql/gql/queries/meQuery.gql';
|
import ME_QUERY from '@/graphql/gql/queries/meQuery.gql';
|
||||||
|
|
@ -8,7 +8,7 @@ import MY_SCHOOL_CLASS_QUERY from '@/graphql/gql/queries/mySchoolClass.gql';
|
||||||
import DELETE_MODULE_NODES from '@/graphql/gql/local/mutations/deleteModuleNodes.gql';
|
import DELETE_MODULE_NODES from '@/graphql/gql/local/mutations/deleteModuleNodes.gql';
|
||||||
import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
|
import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
|
||||||
|
|
||||||
import VueApollo from 'vue-apollo'
|
import VueApollo from 'vue-apollo';
|
||||||
import ClassSelectionWidget from '@/components/school-class/ClassSelectionWidget';
|
import ClassSelectionWidget from '@/components/school-class/ClassSelectionWidget';
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -93,7 +93,7 @@ const meQueryResponse = {
|
||||||
onboardingVisited: true
|
onboardingVisited: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const mySchoolClassResponse = {
|
const mySchoolClassResponse = {
|
||||||
data: {}
|
data: {}
|
||||||
|
|
@ -127,7 +127,7 @@ describe('ClassSelectionWidget.vue', () => {
|
||||||
deleteModulesHandler: jest.fn().mockResolvedValueOnce(deleteModulesResponse),
|
deleteModulesHandler: jest.fn().mockResolvedValueOnce(deleteModulesResponse),
|
||||||
mySchoolClassHandler: jest.fn().mockResolvedValueOnce(mySchoolClassResponse),
|
mySchoolClassHandler: jest.fn().mockResolvedValueOnce(mySchoolClassResponse),
|
||||||
moduleDetailHandler: jest.fn().mockResolvedValueOnce(moduleDetailResponse),
|
moduleDetailHandler: jest.fn().mockResolvedValueOnce(moduleDetailResponse),
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
const createComponent = () => {
|
const createComponent = () => {
|
||||||
|
|
@ -159,14 +159,14 @@ describe('ClassSelectionWidget.vue', () => {
|
||||||
|
|
||||||
wrapper.vm.me.schoolClass = schoolClasses;
|
wrapper.vm.me.schoolClass = schoolClasses;
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
it('should delete the modules cache and query the current module on a class change', async () => {
|
it('should delete the modules cache and query the current module on a class change', async () => {
|
||||||
|
|
||||||
createComponent();
|
createComponent();
|
||||||
|
|
||||||
wrapper.vm.me.selectedClass = {id: 'abcd123'}
|
wrapper.vm.me.selectedClass = {id: 'abcd123'};
|
||||||
wrapper.vm.updateSelectedClassAndHidePopover(schoolClasses[1]);
|
wrapper.vm.updateSelectedClassAndHidePopover(schoolClasses[1]);
|
||||||
|
|
||||||
expect(requestHandlers.updateSettingsHandler).toHaveBeenCalledWith({
|
expect(requestHandlers.updateSettingsHandler).toHaveBeenCalledWith({
|
||||||
|
|
@ -186,10 +186,10 @@ describe('ClassSelectionWidget.vue', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
wrapper.destroy()
|
wrapper.destroy();
|
||||||
mockClient = null
|
mockClient = null;
|
||||||
apolloProvider = null
|
apolloProvider = null;
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
})
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { shallowMount, createLocalVue } from '@vue/test-utils'
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
||||||
import ContentBlock from '@/components/ContentBlock'
|
import ContentBlock from '@/components/ContentBlock';
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex';
|
||||||
|
|
||||||
const localVue = createLocalVue()
|
const localVue = createLocalVue();
|
||||||
|
|
||||||
localVue.use(Vuex)
|
localVue.use(Vuex);
|
||||||
|
|
||||||
describe('ContentBlock.vue', () => {
|
describe('ContentBlock.vue', () => {
|
||||||
|
|
||||||
|
|
@ -22,8 +22,8 @@ describe('ContentBlock.vue', () => {
|
||||||
state: {},
|
state: {},
|
||||||
getters,
|
getters,
|
||||||
actions: {}
|
actions: {}
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
it('should update index if content list has minimal length', () => {
|
it('should update index if content list has minimal length', () => {
|
||||||
const props = {
|
const props = {
|
||||||
|
|
@ -237,4 +237,4 @@ describe('ContentBlock.vue', () => {
|
||||||
expect(contents3).toEqual(contents);
|
expect(contents3).toEqual(contents);
|
||||||
});
|
});
|
||||||
|
|
||||||
})
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { shallowMount } from '@vue/test-utils'
|
import { shallowMount } from '@vue/test-utils';
|
||||||
import ModuleNavigation from '@/components/modules/ModuleNavigation'
|
import ModuleNavigation from '@/components/modules/ModuleNavigation';
|
||||||
|
|
||||||
describe('ModuleNavigation.vue', () => {
|
describe('ModuleNavigation.vue', () => {
|
||||||
it('should flatten an array', () => {
|
it('should flatten an array', () => {
|
||||||
|
|
@ -11,7 +11,7 @@ describe('ModuleNavigation.vue', () => {
|
||||||
propsData: props
|
propsData: props
|
||||||
});
|
});
|
||||||
|
|
||||||
let arrayToFlatten = [[1], [2, 3], [4, 5, 6], [7]]
|
let arrayToFlatten = [[1], [2, 3], [4, 5, 6], [7]];
|
||||||
let flattenedArray = wrapper.vm.flattenArray(arrayToFlatten);
|
let flattenedArray = wrapper.vm.flattenArray(arrayToFlatten);
|
||||||
expect(flattenedArray).toEqual([1, 2, 3, 4, 5, 6, 7]);
|
expect(flattenedArray).toEqual([1, 2, 3, 4, 5, 6, 7]);
|
||||||
});
|
});
|
||||||
|
|
@ -28,7 +28,7 @@ describe('ModuleNavigation.vue', () => {
|
||||||
let nodeData = {
|
let nodeData = {
|
||||||
type: 'assignment',
|
type: 'assignment',
|
||||||
id: 1
|
id: 1
|
||||||
}
|
};
|
||||||
|
|
||||||
let assignment = wrapper.vm.findAssignment(nodeData);
|
let assignment = wrapper.vm.findAssignment(nodeData);
|
||||||
expect(assignment).toEqual([nodeData]);
|
expect(assignment).toEqual([nodeData]);
|
||||||
|
|
@ -58,10 +58,10 @@ describe('ModuleNavigation.vue', () => {
|
||||||
type: 'content_list_item',
|
type: 'content_list_item',
|
||||||
id: 1,
|
id: 1,
|
||||||
value: assignments
|
value: assignments
|
||||||
}
|
};
|
||||||
|
|
||||||
let foundAssignments = wrapper.vm.findAssignment(nodeData);
|
let foundAssignments = wrapper.vm.findAssignment(nodeData);
|
||||||
expect(foundAssignments).toEqual(assignments);
|
expect(foundAssignments).toEqual(assignments);
|
||||||
});
|
});
|
||||||
|
|
||||||
})
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue