UNCLASSIFIED

Commit a674e799 authored by graham.smith's avatar graham.smith
Browse files

more unit tests and refactoring

parent 10a7f324
...@@ -158,7 +158,7 @@ ...@@ -158,7 +158,7 @@
:disabled="!valid" :disabled="!valid"
color="primary" color="primary"
:loading="addBusy" :loading="addBusy"
@click="addClass()" @click="addCourse()"
> >
Add Class Add Class
</v-btn> </v-btn>
...@@ -197,7 +197,7 @@ export default { ...@@ -197,7 +197,7 @@ export default {
this.$emit("cancel"); this.$emit("cancel");
this.init(); this.init();
}, },
addClass() { addCourse() {
this.$emit("add", this.toAdd); this.$emit("add", this.toAdd);
this.init(); this.init();
}, },
......
...@@ -148,7 +148,6 @@ export default { ...@@ -148,7 +148,6 @@ export default {
}, },
async query(val) { async query(val) {
try { try {
console.log("val:", val);
const newItems = await UserService.search({ q: val }); const newItems = await UserService.search({ q: val });
if (this.model) { if (this.model) {
if (Array.isArray(this.model)) { if (Array.isArray(this.model)) {
......
...@@ -363,11 +363,9 @@ export default { ...@@ -363,11 +363,9 @@ export default {
}), }),
computed: { computed: {
getSelectedPocs() { getSelectedPocs() {
console.log(this.selectedPocs);
return this.selectedPocs; return this.selectedPocs;
}, },
getSelectedStudents() { getSelectedStudents() {
console.log(this.selectedStudents);
return this.selectedStudents; return this.selectedStudents;
}, },
}, },
...@@ -376,12 +374,10 @@ export default { ...@@ -376,12 +374,10 @@ export default {
this.trainingCourse = await TrainingService.getCourse( this.trainingCourse = await TrainingService.getCourse(
this.$route.params.trainingId this.$route.params.trainingId
); );
console.log(this.trainingCourse);
this.loading = false; this.loading = false;
}, },
methods: { methods: {
removeSelectedStudent() { removeSelectedStudent() {
console.log(this.getSelectedStudents);
const removeStudentIds = this.getSelectedStudents.map( const removeStudentIds = this.getSelectedStudents.map(
(student) => student.id (student) => student.id
); );
......
...@@ -109,10 +109,10 @@ ...@@ -109,10 +109,10 @@
</v-row> </v-row>
</v-container> </v-container>
<AddClass <AddCourse
v-if="state.isAdding" v-if="state.isAdding"
@cancel="state.isAdding = false" @cancel="state.isAdding = false"
@add="addClass" @add="addCourse"
:add-busy="state.isAddingBusy" :add-busy="state.isAddingBusy"
/> />
</template> </template>
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
<script> <script>
import Vue from "vue"; import Vue from "vue";
import TrainingService from "@/api/services/training"; import TrainingService from "@/api/services/training";
import AddClass from "@/components/AddClass"; import AddCourse from "@/components/AddCourse";
import { defaultSnackbarTimeout, debounceTimeout } from "@/config/config"; import { defaultSnackbarTimeout, debounceTimeout } from "@/config/config";
import { trainingTypes } from "@/config/reference-data"; import { trainingTypes } from "@/config/reference-data";
import isEqual from "lodash/isEqual"; import isEqual from "lodash/isEqual";
...@@ -283,7 +283,7 @@ import { createDefaultPaginationParams } from "@/utils/tableHelpers"; ...@@ -283,7 +283,7 @@ import { createDefaultPaginationParams } from "@/utils/tableHelpers";
export default { export default {
components: { components: {
AddClass, AddCourse,
}, },
data: () => ({ data: () => ({
initialLoad: true, initialLoad: true,
...@@ -387,7 +387,7 @@ export default { ...@@ -387,7 +387,7 @@ export default {
} }
}, },
async addClass(toAdd) { async addCourse(toAdd) {
this.state.isAddingBusy = true; this.state.isAddingBusy = true;
toAdd.seats = { toAdd.seats = {
......
...@@ -38,6 +38,7 @@ describe("Launchboard InitialLoadingApp", () => { ...@@ -38,6 +38,7 @@ describe("Launchboard InitialLoadingApp", () => {
}, },
}, },
}, },
stubs: ["router-view"],
localVue, localVue,
vuetify, vuetify,
}); });
...@@ -58,6 +59,7 @@ describe("Launchboard InitialLoadingApp", () => { ...@@ -58,6 +59,7 @@ describe("Launchboard InitialLoadingApp", () => {
}, },
}, },
}, },
stubs: ["router-view"],
localVue, localVue,
vuetify, vuetify,
}); });
......
import { shallowMount } from "@vue/test-utils"; import { shallowMount } from "@vue/test-utils";
import AddClass from "@/components/AddClass"; import AddCourse from "@/components/AddCourse";
describe("LaunchboardAdmin", () => { describe("AddCourse", () => {
it("should emit cancel", async () => { it("should emit cancel", async () => {
const wrapper = shallowMount(AddClass); const wrapper = shallowMount(AddCourse);
wrapper.vm.cancel(); wrapper.vm.cancel();
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(wrapper.emitted().cancel).toBeTruthy(); expect(wrapper.emitted().cancel).toBeTruthy();
}); });
it("should emit add", async () => { it("should emit add", async () => {
const wrapper = shallowMount(AddClass); const wrapper = shallowMount(AddCourse);
wrapper.vm.addClass(); wrapper.vm.addCourse();
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(wrapper.emitted().add).toBeTruthy(); expect(wrapper.emitted().add).toBeTruthy();
expect(wrapper.emitted().add[0]).toEqual([wrapper.vm.toAdd]); expect(wrapper.emitted().add[0]).toEqual([wrapper.vm.toAdd]);
}); });
describe("input validation rules", () => { describe("input validation rules", () => {
const wrapper = shallowMount(AddClass); const wrapper = shallowMount(AddCourse);
it("should check required", () => { it("should check required", () => {
expect(wrapper.vm.inputRules.required()).toEqual("* Required"); expect(wrapper.vm.inputRules.required()).toEqual("* Required");
expect(wrapper.vm.inputRules.required("aaa")).toEqual(true); expect(wrapper.vm.inputRules.required("aaa")).toEqual(true);
......
...@@ -18,6 +18,7 @@ describe("CurriculumSchedule", () => { ...@@ -18,6 +18,7 @@ describe("CurriculumSchedule", () => {
}); });
it("should set loading to false on error", async () => { it("should set loading to false on error", async () => {
console.error = jest.fn(); // mock console.error when expecting error messages
ScheduleService.getScheduleForUser = jest ScheduleService.getScheduleForUser = jest
.fn() .fn()
.mockRejectedValue("mock error"); .mockRejectedValue("mock error");
......
...@@ -27,6 +27,7 @@ test("NavBar", () => { ...@@ -27,6 +27,7 @@ test("NavBar", () => {
}, },
}, },
}, },
stubs: ["router-link"],
localVue, localVue,
vuetify, vuetify,
}); });
......
...@@ -21,8 +21,6 @@ test("SystemStatusSummary", () => { ...@@ -21,8 +21,6 @@ test("SystemStatusSummary", () => {
vuetify, vuetify,
}); });
wrapper.vm.tempAlert();
// assert the component loads without error // assert the component loads without error
expect(wrapper.find(".error").exists()).toBe(false); expect(wrapper.find(".error").exists()).toBe(false);
}); });
...@@ -135,9 +135,13 @@ describe("LaunchboardAdmin", () => { ...@@ -135,9 +135,13 @@ describe("LaunchboardAdmin", () => {
wrapper.vm.model = null; wrapper.vm.model = null;
await wrapper.vm.query(); await wrapper.vm.query();
expect(wrapper.vm.items).toEqual(["a"]); expect(wrapper.vm.items).toEqual(["a"]);
});
// error it("should set items to empty array on error", async () => {
console.error = jest.fn(); // mock console.error when expecting error messages
UserService.search = jest.fn().mockRejectedValue("mock error"); UserService.search = jest.fn().mockRejectedValue("mock error");
const wrapper = mount(UserSelect, {
vuetify,
});
await wrapper.vm.query(); await wrapper.vm.query();
expect(wrapper.vm.items).toEqual([]); expect(wrapper.vm.items).toEqual([]);
}); });
......
...@@ -46,6 +46,7 @@ describe("initial-load store", () => { ...@@ -46,6 +46,7 @@ describe("initial-load store", () => {
); );
}); });
it("should fail and throw an error", async () => { it("should fail and throw an error", async () => {
console.error = jest.fn(); // mock console.error when expecting error messages
const mockUserResponse = "mock fail"; const mockUserResponse = "mock fail";
const mockUserPreference = { darkMode: true }; const mockUserPreference = { darkMode: true };
UserService.updateUserPreferences = jest UserService.updateUserPreferences = jest
......
...@@ -7,20 +7,30 @@ const vuetify = new Vuetify(); ...@@ -7,20 +7,30 @@ const vuetify = new Vuetify();
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
test("TrainingDetails", () => { describe("TrainingDetails", () => {
// render the component const $route = {
const wrapper = shallowMount(TrainingDetails, { params: {
mocks: { trainingId: 42,
$store: { },
state: { };
error: {},
it("should not show error by default", () => {
// render the component
const wrapper = shallowMount(TrainingDetails, {
mocks: {
$route,
$store: {
state: {
error: {},
},
}, },
}, },
}, stubs: ["router-link"],
localVue, localVue,
vuetify, vuetify,
}); });
// assert the component loads without error // assert the component loads without error
expect(wrapper.find(".error").exists()).toBe(false); expect(wrapper.find(".error").exists()).toBe(false);
});
}); });
...@@ -31,7 +31,6 @@ describe("LaunchboardAdmin", () => { ...@@ -31,7 +31,6 @@ describe("LaunchboardAdmin", () => {
}, },
}); });
UserService.updateUserPersonnelType = jest.fn(() => null); UserService.updateUserPersonnelType = jest.fn(() => null);
window.alert = jest.fn();
wrapper.vm.$refs.userSelect = { wrapper.vm.$refs.userSelect = {
clear: jest.fn(), clear: jest.fn(),
}; };
...@@ -104,21 +103,17 @@ describe("LaunchboardAdmin", () => { ...@@ -104,21 +103,17 @@ describe("LaunchboardAdmin", () => {
// }); // });
it("should get all list items", async () => { it("should get all list items", async () => {
const wrapper = shallowMount(Personnel, { const wrapper = shallowMount(Personnel);
data() {
return {
personnel: {
types: {
executiveLeadership: "Executive Leadership",
pm: "PM",
businessOps: "Business Ops",
instructor: "Instructor",
},
},
};
},
});
wrapper.vm.personnel = {
userSelect: {},
types: {
executiveLeadership: "Executive Leadership",
pm: "PM",
businessOps: "Business Ops",
instructor: "Instructor",
},
};
wrapper.vm.$refs.personnel.getPersonnelListItems = jest.fn(() => { wrapper.vm.$refs.personnel.getPersonnelListItems = jest.fn(() => {
return [{ personnelType: "Executive Leadership" }]; return [{ personnelType: "Executive Leadership" }];
}); });
...@@ -172,6 +167,9 @@ describe("LaunchboardAdmin", () => { ...@@ -172,6 +167,9 @@ describe("LaunchboardAdmin", () => {
}, },
}); });
wrapper.setData({ filterSearchValue: "test", filterSelectedValue: "test" }); wrapper.setData({ filterSearchValue: "test", filterSelectedValue: "test" });
wrapper.vm.$refs.personnel = {
fetchData: jest.fn(),
};
wrapper.vm.getAllListItems = jest.fn(() => { wrapper.vm.getAllListItems = jest.fn(() => {
return [ return [
......
...@@ -4,6 +4,10 @@ import TrainingService from "@/api/services/training"; ...@@ -4,6 +4,10 @@ import TrainingService from "@/api/services/training";
describe("Training", () => { describe("Training", () => {
const mockCoursesResult = { courses: [], meta: { total: 0 } }; const mockCoursesResult = { courses: [], meta: { total: 0 } };
afterEach(() => {
jest.restoreAllMocks();
});
it("should debounce getCourses", async () => { it("should debounce getCourses", async () => {
TrainingService.getCourses = jest.fn().mockResolvedValue(mockCoursesResult); TrainingService.getCourses = jest.fn().mockResolvedValue(mockCoursesResult);
...@@ -50,7 +54,7 @@ describe("Training", () => { ...@@ -50,7 +54,7 @@ describe("Training", () => {
// //
// const wrapper = shallowMount(Training); // const wrapper = shallowMount(Training);
// const mockClass = { name: "mock class", totalSeats: 55 }; // const mockClass = { name: "mock class", totalSeats: 55 };
// await wrapper.vm.addClass(mockClass); // await wrapper.vm.addCourse(mockClass);
// //
// expect(TrainingService.addCourse).toHaveBeenCalledTimes(1); // expect(TrainingService.addCourse).toHaveBeenCalledTimes(1);
// expect(TrainingService.addCourse).toHaveBeenCalledWith(mockClass); // expect(TrainingService.addCourse).toHaveBeenCalledWith(mockClass);
...@@ -59,7 +63,7 @@ describe("Training", () => { ...@@ -59,7 +63,7 @@ describe("Training", () => {
// //
// // error state // // error state
// TrainingService.addCourse = jest.fn().mockRejectedValue("mock error"); // TrainingService.addCourse = jest.fn().mockRejectedValue("mock error");
// await wrapper.vm.addClass(mockClass); // await wrapper.vm.addCourse(mockClass);
// expect(wrapper.vm.state.isAddingBusy).toEqual(false); // expect(wrapper.vm.state.isAddingBusy).toEqual(false);
// expect(wrapper.vm.state.isAdding).toEqual(false); // expect(wrapper.vm.state.isAdding).toEqual(false);
// }); // });
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment