Commit 7687a5c9 authored by Cornee Traas's avatar Cornee Traas
Browse files

Move tests to platform api

parent 33135328
Pipeline #2529 failed with stages
in 1 minute and 5 seconds
......@@ -30,7 +30,7 @@
<b-button id="filterButton" @click="showFilterModal=true">
<i class="fa fa-filter mr-1"/>Filters
</b-button>
<b-button :disabled="level<2" id="actions-button" @click="showActionsModal=true">
<b-button :disabled="level<3" id="actions-button" @click="showActionsModal=true">
<i class="fa fa-exchange mr-1"/>Changes
</b-button>
<b-navbar-nav class="custom-nav ml-auto">
......@@ -387,7 +387,7 @@ export default {
util.saveAction(this.action).then(response => {
util
.getActions(
"coursera",
this.$store.state.selectedPlatform,
this.currentCourse.course_id,
this.$store.state.filters
)
......@@ -419,7 +419,7 @@ export default {
util.deleteAction(this.actionToDelete.pk).then(response => {
util
.getActions(
"coursera",
this.$store.state.selectedPlatform,
this.currentCourse.course_id,
this.$store.state.filters
)
......@@ -440,7 +440,7 @@ export default {
if (this.currentCourse) {
util
.getActions(
"coursera",
this.$store.state.selectedPlatform,
this.currentCourse.course_id,
this.$store.state.filters
)
......
......@@ -291,7 +291,7 @@ export default {
// Actions API calls
getActions(platformId, courseId, filters) {
return axios
.get(this.apiUrl() + `/actions/${store.state.selectedPlatform}/${courseId}/` + this.getQueryParams(filters), {
.get(this.apiUrl() + `/actions/${platformId}/${courseId}/` + this.getQueryParams(filters), {
headers: this.authHeader(),
})
},
......
......@@ -366,11 +366,11 @@ export default {
* not yet implemented
*/
//
tendFolCourData: []
tendFolCourData: [],
};
},
components: {
Chart
Chart,
},
beforeMount() {
var otherCourses = this.$store.state.user.courses.filter(
......@@ -409,8 +409,12 @@ export default {
if (currentCourse) {
this.courseId = currentCourse.course_id;
Promise.all([
util.getActions("coursera", this.courseId, this.$store.state.filters),
util.getDetailedCourseData(this.courseId, this.$store.state.filters)
util.getActions(
this.$store.state.selectedPlatform,
this.courseId,
this.$store.state.filters
),
util.getDetailedCourseData(this.courseId, this.$store.state.filters),
])
.then(response => {
this.courseData = response[1].data;
......@@ -444,7 +448,7 @@ export default {
this.distEvalRateData[0] = {};
this.distEvalRateData[0].x = [];
this.distEvalRateData[0].y = [];
this.distEvalRateData[0].marker = { color: this.mainColor };
this.distEvalRateData[0].marker = { color: this.mainColor, };
this.distEvalRateData[0].type = "bar";
for (let rating of data.ratings) {
this.distEvalRateData[0].x.push(rating[0]);
......@@ -455,7 +459,7 @@ export default {
this.distEvalLayout.xaxis = {};
this.distEvalLayout.xaxis.nticks = this.distEvalRateData[0].x.length * 2;
this.distEvalLayout.xaxis.title = "Rating";
this.distEvalLayout.yaxis = { title: "Number of ratings" };
this.distEvalLayout.yaxis = { title: "Number of ratings", };
// Progression of finished learners.
this.progFinLearData[0] = {};
......@@ -464,7 +468,7 @@ export default {
this.progFinLearData[0].fill = "tonexty";
this.progFinLearData[0].name = "Progression of completers";
this.progFinLearData[0].fillcolor = colors.lightGrey;
this.progFinLearData[0].marker = { color: this.mainColor };
this.progFinLearData[0].marker = { color: this.mainColor, };
this.progFinLearData[0].type = "scatter";
for (let finished of data.finished_learners_over_time) {
this.progFinLearData[0].x.push(finished[0]);
......@@ -505,14 +509,14 @@ export default {
this.progFinLearLayout = {
xaxis: {
title: "Time"
title: "Time",
// range: [xrangestart, xrangeend,],
},
yaxis: {
title: "Number of learners"
title: "Number of learners",
},
shapes: [],
showlegend: false
showlegend: false,
};
this.progFinLearData[1] = {
x: [],
......@@ -524,8 +528,8 @@ export default {
textposition: "bottom",
marker: {
color: colors.purple,
size: 12
}
size: 12,
},
};
// Add registered actions to the finished learners graph
......@@ -549,7 +553,7 @@ export default {
this.leavLearModData[0] = {};
this.leavLearModData[0].x = [];
this.leavLearModData[0].y = [];
this.leavLearModData[0].marker = { color: this.mainColor };
this.leavLearModData[0].marker = { color: this.mainColor, };
this.leavLearModData[0].type = "bar";
for (let x = 0; x < data.leaving_learners_per_module.length; x++) {
this.leavLearModData[0].x.push(x + 1);
......@@ -561,7 +565,7 @@ export default {
this.leavLearLayout.xaxis.nticks = this.leavLearModData[0].x.length * 2;
this.leavLearLayout.xaxis.title = "Module";
this.leavLearLayout.yaxis = {
title: "Leaving learners"
title: "Leaving learners",
};
// Average time per module.
......@@ -569,7 +573,7 @@ export default {
this.avgTimeModData[0] = {};
this.avgTimeModData[0].x = [];
this.avgTimeModData[0].y = [];
this.avgTimeModData[0].marker = { color: this.mainColor };
this.avgTimeModData[0].marker = { color: this.mainColor, };
this.avgTimeModData[0].type = "bar";
for (let x = 0; x < data.average_time_per_module.length; x++) {
this.avgTimeModData[0].x.push(x + 1);
......@@ -581,10 +585,10 @@ export default {
this.avgTimeLayout = {};
this.avgTimeLayout.xaxis = {
nticks: this.avgTimeModData[0].x.length * 2,
title: "Module"
title: "Module",
};
this.avgTimeLayout.yaxis = {
title: "Average time"
title: "Average time",
};
this.avgTime = (parseFloat(data.average_time) / (3600 * 24)).toFixed(1);
......@@ -595,21 +599,21 @@ export default {
text: util.arrayColumn(data.geo_data, 1),
z: util.arrayColumn(data.geo_data, 2),
colorscale: [
[0, "rgba(0, 169, 212, 0)"],
[0.35, "rgba(0, 169, 212, 50)"],
[0.5, "rgba(0, 169, 212, 100)"],
[0.6, "rgba(0, 169, 212,150)"],
[0.7, "rgba(0, 169, 212, 200)"],
[1, "rgba(0, 169, 212, 255)"]
]
[0, "rgba(0, 169, 212, 0)",],
[0.35, "rgba(0, 169, 212, 50)",],
[0.5, "rgba(0, 169, 212, 100)",],
[0.6, "rgba(0, 169, 212,150)",],
[0.7, "rgba(0, 169, 212, 200)",],
[1, "rgba(0, 169, 212, 255)",],
],
};
this.geoLayout = {
geo: {
projection: {
type: "robinson"
}
}
type: "robinson",
},
},
};
this.cohorts = data.cohort_list;
......@@ -630,8 +634,8 @@ export default {
return parseInt(yArray[i - 1] + (yArray[i] - yArray[i - 1]) * ratio);
}
}
}
}
},
},
};
</script>
......
......@@ -57,7 +57,7 @@ describe('AssignmentDetail.vue', () => {
// TODO Erroring
// it('Test if assignment response data is set in html.', (done) => {
// moxios.stubRequest(util.apiUrl() + '/api/assignment-analytics/1/assignment1/', {
// moxios.stubRequest(util.platformUrl() + '/assignment-analytics/1/assignment1/', {
// status: 200,
// response: {
// id: "dsfdsf",
......@@ -84,7 +84,7 @@ describe('AssignmentDetail.vue', () => {
// })
it('Check if response error is handled.', (done) => {
moxios.stubRequest(util.apiUrl() + '/api/assignment-analytics/1/assignment1/', {
moxios.stubRequest(util.platformUrl() + '/assignment-analytics/1/assignment1/', {
status: 403,
response: {
"error": "error",
......@@ -99,7 +99,7 @@ describe('AssignmentDetail.vue', () => {
// TODO Erroring
// it('Test update on router update.', (done) => {
// moxios.stubRequest(util.apiUrl() + '/api/assignment-analytics/1/assignment1/', {
// moxios.stubRequest(util.platformUrl() + '/assignment-analytics/1/assignment1/', {
// status: 200,
// response: {
// id: "dsfdsf",
......@@ -119,7 +119,7 @@ describe('AssignmentDetail.vue', () => {
// },
// },
// });
// moxios.stubRequest(util.apiUrl() + '/api/assignment-analytics/1/assignment2/', {
// moxios.stubRequest(util.platformUrl() + '/assignment-analytics/1/assignment2/', {
// status: 200,
// response: {
// id: "dsfdsf",
......
import Vuex from 'vuex'
import {
mount,
createLocalVue
mount,
createLocalVue
} from '@vue/test-utils'
import BootstrapVue from 'bootstrap-vue'
import Assignments from '@/views/platforms/coursera/Assignments'
......@@ -15,67 +15,73 @@ localVue.use(BootstrapVue)
localVue.use(Vuex)
describe('Assignments.vue', () => {
let store
let store
beforeEach(function () {
store = mockUtils.mockStore()
moxios.install()
})
afterEach(function () {
moxios.uninstall()
})
beforeEach(function () {
store = mockUtils.mockStore()
moxios.install()
})
afterEach(function () {
moxios.uninstall()
})
let mountComponent = () => {
return mount(Assignments, {
localVue,
store,
mocks: {
$router: {},
$route: {
params: {
courseid: "test",
},
},
},
stubs: [
'Chart',
],
})
}
it('is Vue instance', () => {
const wrapper = mountComponent()
expect(wrapper.isVueInstance()).toBe(true)
})
it('is Register', () => {
const wrapper = mountComponent()
expect(wrapper.is(Assignments)).toBe(true)
let mountComponent = () => {
return mount(Assignments, {
localVue,
store,
mocks: {
$router: {},
$route: {
params: {
courseid: "test",
},
},
},
stubs: [
'Chart',
],
})
}
it('is Vue instance', () => {
const wrapper = mountComponent()
expect(wrapper.isVueInstance()).toBe(true)
})
it('is Register', () => {
const wrapper = mountComponent()
expect(wrapper.is(Assignments)).toBe(true)
})
it('Test if assignment response data is set in html.', (done) => {
moxios.stubRequest(util.apiUrl() + '/api/assignment-analytics/1/', {
status: 200,
response: [{ name: "Assignment 1", }, { name: "Assignment 2", },],
});
const wrapper = mountComponent();
moxios.wait(function () {
expect(wrapper.html()).toContain("Assignment 1");
expect(wrapper.html()).toContain("Assignment 2");
done();
})
it('Test if assignment response data is set in html.', (done) => {
moxios.stubRequest(util.platformUrl() + '/assignment-analytics/1/', {
status: 200,
response: [{
name: "Assignment 1",
}, {
name: "Assignment 2",
}, ],
});
const wrapper = mountComponent();
moxios.wait(function () {
expect(wrapper.html()).toContain("Assignment 1");
expect(wrapper.html()).toContain("Assignment 2");
done();
})
})
it('Check if response error is handled.', (done) => {
moxios.stubRequest(util.apiUrl() + '/api/assignment-analytics/1/', {
status: 403,
response: { "error": "error", },
});
const wrapper = mountComponent();
moxios.wait(function () {
expect(wrapper.html()).toContain(strings.connection_error);
done();
})
it('Check if response error is handled.', (done) => {
moxios.stubRequest(util.platformUrl() + '/assignment-analytics/1/', {
status: 403,
response: {
"error": "error",
},
});
const wrapper = mountComponent();
moxios.wait(function () {
expect(wrapper.html()).toContain(strings.connection_error);
done();
})
})
})
import Vuex from 'vuex'
import {
mount,
createLocalVue
mount,
createLocalVue
} from '@vue/test-utils'
import * as mockUtils from '../mockUtils'
......@@ -17,184 +17,188 @@ localVue.use(BootstrapVue)
localVue.use(Vuex)
describe('CourseComparison.vue', () => {
let store
beforeEach(function () {
store = mockUtils.mockStore()
moxios.install()
})
afterEach(function () {
moxios.uninstall()
let store
beforeEach(function () {
store = mockUtils.mockStore()
moxios.install()
})
afterEach(function () {
moxios.uninstall()
})
let mountComponent = () => {
return mount(CourseComparison, {
localVue,
store,
mocks: {
$router: {
push: {},
},
$route: {
params: {
courseid: "test",
course2id: "test2",
},
},
},
stubs: [
'Chart',
],
})
let mountComponent = () => {
return mount(CourseComparison, {
localVue,
store,
mocks: {
$router: {
push: {},
},
$route: {
params: {
courseid: "test",
course2id: "test2",
},
},
},
stubs: [
'Chart',
],
})
}
it('has a name', () => {
expect(CourseComparison.name).toMatch('CourseComparison')
}
it('has a name', () => {
expect(CourseComparison.name).toMatch('CourseComparison')
})
it('sets the correct default data', (done) => {
expect(typeof CourseComparison.data).toMatch('function');
moxios.stubRequest(util.platformUrl() + '/course-analytics/1/', {
status: 200,
response: {
test: "test",
name: "test_name",
ratings: [
[1, 0, ],
[2, 10, ],
[3, 14, ],
],
finished_learners_over_time: [
[1, 0, ],
[2, 10, ],
[3, 14, ],
],
leaving_learners_per_module: [
[1, 0, ],
[2, 10, ],
[3, 14, ],
],
average_time_per_module: [
[1, 0, ],
[2, 10, ],
[3, 14, ],
],
average_time: 348923048,
},
});
moxios.stubRequest(util.platformUrl() + '/course-analytics/2/', {
status: 200,
response: {
test: "test",
name: "test_2_name",
ratings: [
[1, 0, ],
[2, 10, ],
[3, 14, ],
],
finished_learners_over_time: [
[1, 0, ],
[2, 10, ],
[3, 14, ],
],
leaving_learners_per_module: [
[1, 0, ],
[2, 10, ],
[3, 14, ],
],
average_time_per_module: [
[1, 0, ],
[2, 10, ],
[3, 14, ],
],
average_time: 348923048,
},
});
const wrapper = mountComponent();
moxios.wait(function () {
expect(wrapper.vm.course1.courseName).toBe("test_name")
expect(wrapper.vm.course2.courseName).toBe("test_2_name")
done();
})
it('sets the correct default data', (done) => {
expect(typeof CourseComparison.data).toMatch('function');
moxios.stubRequest(util.apiUrl() + '/api/course-analytics/1/', {
status: 200,
response: {
test: "test",
name: "test_name",
ratings: [
[1, 0,],
[2, 10,],
[3, 14,],
],
finished_learners_over_time: [
[1, 0,],
[2, 10,],
[3, 14,],
],
leaving_learners_per_module: [
[1, 0,],
[2, 10,],
[3, 14,],
],
average_time_per_module: [
[1, 0,],
[2, 10,],
[3, 14,],
],
average_time: 348923048,
},
});
moxios.stubRequest(util.apiUrl() + '/api/course-analytics/2/', {
status: 200,
response: {
test: "test",
name: "test_2_name",
ratings: [
[1, 0,],
[2, 10,],
[3, 14,],
],
finished_learners_over_time: [
[1, 0,],
[2, 10,],
[3, 14,],
],
leaving_learners_per_module: [
[1, 0,],
[2, 10,],
[3, 14,],
],
average_time_per_module: [
[1, 0,],
[2, 10,],
[3, 14,],
],
average_time: 348923048,
},
});
const wrapper = mountComponent();
moxios.wait(function () {
expect(wrapper.vm.course1.courseName).toBe("test_name")
expect(wrapper.vm.course2.courseName).toBe("test_2_name")
done();
})
})
it('test bad request', (done) => {
moxios.stubRequest(util.