diff --git a/kolibri/plugins/management/assets/test/app.js b/kolibri/plugins/management/assets/test/app.js deleted file mode 100644 index 159182e7322..00000000000 --- a/kolibri/plugins/management/assets/test/app.js +++ /dev/null @@ -1,232 +0,0 @@ -/* eslint-env mocha */ -// The following two rules are disabled so that we can use anonymous functions with mocha -// This allows the test instance to be properly referenced with `this` -/* eslint prefer-arrow-callback: "off", func-names: "off" */ -const Vue = require('vue'); -const Vuex = require('vuex'); -const assert = require('assert'); -const rewire = require('rewire'); - -const actions = rewire('../src/vuex/actions.js'); -const { fetch } = actions; -const { store, mutations, constants } = require('../src/vuex/store.js'); -const Management = require('../src/vue'); -const fixture1 = require('./fixtures/fixture1.js'); - -/* -Neat little snippet for testing actions, modified from the vuex docs. -Asserts that the expectedMutations (an array of objects with name & payload attributes) -occurs in the given order. At least one expected mutation must be given. -Does not fail if *more* mutations than expected occur -- it will simply terminate -successfully as soon as the *expected* mutations finish up. - */ -function testAction(action, args, state, expectedMutations, done, errors) { - let count = 0; - - return new Promise((resolve) => { - // mock dispatch - const dispatch = (name, ...payload) => { - const mutation = expectedMutations[count]; - assert.equal(name, mutation.name); - if (payload) { - try { - assert.deepEqual(payload, mutation.payload, - `Mutation ${name} not given right payload.`); - } catch (e) { - errors.push(e); - } - } - count++; - if (count >= expectedMutations.length) { - resolve(); - } - }; - // call the action with mocked store and arguments - action({ dispatch, state }, ...args); - }).then(done); -} - -describe('The management module', () => { - it('defines a Management vue', () => { - // A sanity check - assert(Management !== undefined); - }); - - describe('has the following components:', function () { - before(function () { - const container = new Vue({ - template: '
', - components: { Management }, - store, - }).$mount(); - this.vm = container.$refs.main; - }); - - after(function () { - this.vm.$destroy(); - }); - - it('a classroom selector', function (done) { - Vue.nextTick(() => { - const child = this.vm.$refs.classroomSelector; - assert.notStrictEqual(child, undefined); - done(); - }); - }); - - it('a learner group selector', function (done) { - Vue.nextTick(() => { - const child = this.vm.$refs.learnerGroupSelector; - assert.notStrictEqual(child, undefined); - done(); - }); - }); - - it('a learner roster', function (done) { - Vue.nextTick(() => { - const child = this.vm.$refs.learnerRoster; - assert.notStrictEqual(child, undefined); - done(); - }); - }); - - describe('a "fetch" action', function () { - before(function () { - const responses = require('./fixtures/responseFixtures.js'); - const classroomCollection = { models: responses.classroom }; - const learnerGroupCollection = { models: responses.learnergroup }; - const learnerCollection = { models: responses.facilityuser }; - const memberCollection = { models: responses.membership }; - [ - classroomCollection, - learnerGroupCollection, - learnerCollection, - memberCollection, - ].forEach((arr) => { - arr.fetch = function () { // eslint-disable-line no-param-reassign - return new Promise(function (resolve) { - resolve(arr); - }); - }; - }); - actions.__set__('classroomCollection', classroomCollection); - actions.__set__('learnerGroupCollection', learnerGroupCollection); - actions.__set__('learnerCollection', learnerCollection); - actions.__set__('memberCollection', memberCollection); - this.errors = []; - }); - - after(function () { - this.errors.forEach(function (e) { - throw e; - }); - }); - - it('that mutates the state in a particular way', function (done) { - const expectedMutations = [ // The order is significant in this case - /* eslint-disable */ - { - name: 'ADD_LEARNER_GROUPS', - payload: [[ - {"id":4,"name":"Foo's group","parent":2,"learners":[1]}, - {"id":5,"name":"Bar's group","parent":3,"learners":[3]}, - ]], - }, - { - name: 'ADD_CLASSROOMS', - payload: [[ - {"id":2,"name":"Foo","parent":1,"learnerGroups":[4],"ungroupedLearners":[2]}, - {"id":3,"name":"Bar","parent":1,"learnerGroups":[5],"ungroupedLearners":[]}, - ]], - }, - { - name: 'ADD_LEARNERS', - payload: [[ - {"id":1,"username":"mike","first_name":"mike","last_name":"gallaspy","facility":1}, - {"id":2,"username":"jessica","first_name":"Jessica","last_name":"Aceret","facility":1}, - {"id":3,"username":"jduck","first_name":"John","last_name":"Duck","facility":1}]], - }, - /* eslint-enable */ - ]; - // call the action with mocked store and arguments - testAction(fetch, [], {}, expectedMutations, done, this.errors); - }); - }); - }); - - describe('changes the list of students in the roster when you select a classroom.', function () { - beforeEach(function () { - const testStore = new Vuex.Store({ - state: fixture1, - mutations, - }); - const container = new Vue({ - template: '
', - components: { Management }, - store: testStore, - }).$mount(); - this.vm = container.$refs.main; - this.store = testStore; - }); - - afterEach(function () { - this.vm.$destroy(); - }); - - it('The roster shows only John Duck when you select "Classroom C".', function (done) { - // Look at the fixture file for the magic numbers here. - this.store.dispatch('SET_SELECTED_CLASSROOM_ID', 3); - Vue.nextTick(() => { - assert.deepStrictEqual(this.vm.$refs.learnerRoster.learners, [{ - id: 2, - first_name: 'John', - last_name: 'Duck', - username: 'jduck', - }]); - done(); - }); - }); - - it('The roster shows all learners when you select "All classrooms".', function (done) { - this.store.dispatch('SET_SELECTED_CLASSROOM_ID', constants.ALL_CLASSROOMS_ID); - Vue.nextTick(() => { - assert.deepStrictEqual(this.vm.$refs.learnerRoster.learners, fixture1.learners); - done(); - }); - }); - - it('The roster shows two students when you select "Classroom A" and "Group 1".', function (done) { // eslint-disable-line max-len - this.store.dispatch('SET_SELECTED_CLASSROOM_ID', 1); - Vue.nextTick(() => { - this.store.dispatch('SET_SELECTED_GROUP_ID', 1); - Vue.nextTick(() => { - const expectedIds = [1, 2]; - assert.deepStrictEqual(this.vm.$refs.learnerRoster.learners.map(learner => - learner.id - ), expectedIds); - done(); - }); - }); - }); - - it('The roster shows no students when you select "Classroom B".', function (done) { - this.store.dispatch('SET_SELECTED_CLASSROOM_ID', 2); - Vue.nextTick(() => { - assert.deepStrictEqual(this.vm.$refs.learnerRoster.learners, []); - done(); - }); - }); - - it('The roster shows one student when you select "Classroom with ungrouped learners" and "Ungrouped".', function (done) { // eslint-disable-line max-len - this.store.dispatch('SET_SELECTED_CLASSROOM_ID', 4); - Vue.nextTick(() => { - this.store.dispatch('SET_SELECTED_GROUP_ID', constants.UNGROUPED_ID); - Vue.nextTick(() => { - const expectedIds = [4]; - assert.deepStrictEqual(this.vm.$refs.learnerRoster.learners.map(learner => learner.id), expectedIds); // eslint-disable-line max-len - done(); - }); - }); - }); - }); -}); diff --git a/kolibri/plugins/management/assets/test/fixtures/fixture1.js b/kolibri/plugins/management/assets/test/fixtures/fixture1.js deleted file mode 100644 index e6dbeeabced..00000000000 --- a/kolibri/plugins/management/assets/test/fixtures/fixture1.js +++ /dev/null @@ -1,76 +0,0 @@ -module.exports = { - learners: [ - { - id: 1, - first_name: 'Mike', - last_name: 'G', - username: 'mike', - }, - { - id: 2, - first_name: 'John', - last_name: 'Duck', - username: 'jduck', - }, - { - id: 3, - first_name: 'Abe', - last_name: 'Lincoln', - username: 'abe', - }, - { - id: 4, - first_name: 'Harriet', - last_name: 'Tubman', - username: 'htub', - }, - ], - classrooms: [ - { - id: 1, - name: 'Classroom A', - learnerGroups: [1, 3], - ungroupedLearners: [], - // learners: [1, 2, 3], - }, - { - id: 2, - name: 'Classroom B', - learnerGroups: [], - ungroupedLearners: [], - }, - { - id: 3, - name: 'Classroom C', - learnerGroups: [2], - ungroupedLearners: [], - // learners: [2], - }, - { - id: 4, - name: 'Classroom with ungrouped learners', - learnerGroups: [], - ungroupedLearners: [4], - // learners: [4], - }, - ], - learnerGroups: [ - { - id: 1, - name: 'Group 1', - learners: [1, 2], - }, - { - id: 2, - name: 'Group 2', - learners: [2], - }, - { - id: 3, - name: 'Group 3', - learners: [3], - }, - ], - selectedClassroomId: null, // `null` a special meaning for this app. - selectedGroupId: 'nogroups', // also has a special meaning for this app -}; diff --git a/kolibri/plugins/management/assets/test/fixtures/responseFixtures.js b/kolibri/plugins/management/assets/test/fixtures/responseFixtures.js deleted file mode 100644 index 3597ab7e16c..00000000000 --- a/kolibri/plugins/management/assets/test/fixtures/responseFixtures.js +++ /dev/null @@ -1,71 +0,0 @@ -/* eslint-disable */ -module.exports = { - classroom: [ - { - "id": 2, - "name": "Foo", - "parent": 1 - }, - { - "id": 3, - "name": "Bar", - "parent": 1 - } - ], - learnergroup: [ - { - "id": 4, - "name": "Foo's group", - "parent": 2}, - { - "id": 5, - "name": "Bar's group", - "parent": 3 - } - ], - facilityuser: [ - { - "id": 1, - "username": "mike", - "first_name": "mike", - "last_name": "gallaspy", - "facility": 1 - }, - { - "id": 2, - "username": "jessica", - "first_name": "Jessica", - "last_name": "Aceret", - "facility": 1 - }, - { - "id": 3, - "username": "jduck", - "first_name": "John", - "last_name": "Duck", - "facility": 1 - } - ], - membership: [ - { - "id": 1, - "user": 1, - "collection": 2 - }, - { - "id": 2, - "user": 1, - "collection": 4 - }, - { - "id": 3, - "user": 2, - "collection": 2 - }, - { - "id": 4, - "user": 3, - "collection": 5 - } - ], -};