UNCLASSIFIED - NO CUI

Skip to content
Snippets Groups Projects
Commit efc7c5bd authored by Graham Smith's avatar Graham Smith
Browse files

updating tests

parent 91a95624
No related branches found
No related tags found
No related merge requests found
import { shallowMount, createLocalVue } from "@vue/test-utils";
import { BootstrapVue, IconsPlugin } from "bootstrap-vue";
import Breadcrumb from "@/components/Breadcrumb.vue";
import VueRouter from "vue-router";
import Router from "@/router";
// vue-easy-lightbox doesn't play nice in tests, so we have to mock it
jest.mock("vue-easy-lightbox", () => {
return {
install: jest.fn()
};
});
const localVue = createLocalVue();
localVue.use(VueRouter);
localVue.use(BootstrapVue);
localVue.use(IconsPlugin);
describe("Breadcrumb.vue", () => {
let wrapper;
beforeEach(() => {
wrapper = shallowMount(Breadcrumb, { localVue, router: Router });
});
afterEach(() => {
jest.clearAllMocks();
});
it("should compute crumbs", async () => {
window.scrollTo = jest.fn();
await Router.push("/services");
expect(wrapper.vm.crumbs).toStrictEqual([
{ path: "", to: "/", text: "Home" },
{
path: "/services",
to: "/services",
text: "Services",
active: true
}
]);
await Router.push("/products/abms-adce");
expect(wrapper.vm.crumbs).toStrictEqual([
{ path: "", to: "/", text: "Home" },
{ path: "/products", to: "/products", text: "Products" },
{
path: "/products/abms-adce",
to: "/products/abms-adce",
text: "The Party Bus",
active: true
}
]);
await Router.push("/mock-path");
expect(wrapper.vm.crumbs).toStrictEqual([
{ path: "", to: "/", text: "Home", active: true }
]);
});
});
...@@ -34,23 +34,43 @@ describe("router", () => { ...@@ -34,23 +34,43 @@ describe("router", () => {
expect(router.currentRoute.path).toBe("/"); expect(router.currentRoute.path).toBe("/");
}); });
it("should route to /services", async () => { it("should do routing", async () => {
router.push("/services"); await router.push("/services");
await wrapper.vm.$nextTick();
expect(router.currentRoute.name).toBe("Services"); expect(router.currentRoute.name).toBe("Services");
expect(router.currentRoute.path).toBe("/services"); expect(router.currentRoute.path).toBe("/services");
});
it("should route to /who-we-are", async () => { await router.push({ path: "/who-we-are" });
router.push("/who-we-are");
await wrapper.vm.$nextTick();
expect(router.currentRoute.name).toBe("WhoWeAre"); expect(router.currentRoute.name).toBe("WhoWeAre");
expect(router.currentRoute.path).toBe("/who-we-are"); expect(router.currentRoute.path).toBe("/who-we-are");
});
it("should route to /products", async () => { await router.push("/products");
router.push("/products");
await wrapper.vm.$nextTick();
expect(router.currentRoute.name).toBe("Products"); expect(router.currentRoute.name).toBe("Products");
expect(router.currentRoute.path).toBe("/products"); expect(router.currentRoute.path).toBe("/products");
await router.push("/contact-us");
expect(router.currentRoute.name).toBe("ContactUs");
expect(router.currentRoute.path).toBe("/contact-us");
await router.push("/products/abms-adce");
expect(router.currentRoute.name).toBe("ADCE");
expect(router.currentRoute.path).toBe("/products/abms-adce");
});
it("should respect savedPosition", async () => {
const savedPosition = { x: 42, y: 24 };
const result = await Router.options.scrollBehavior({}, {}, savedPosition);
expect(result).toStrictEqual(savedPosition);
});
it("should respect hash", async () => {
const to = { hash: "#test-hash" };
const result = await Router.options.scrollBehavior(to);
expect(result).toStrictEqual({ selector: to.hash });
});
it("should default scroll to 0,0", async () => {
const to = {};
const result = await Router.options.scrollBehavior(to);
expect(result).toStrictEqual({ x: 0, y: 0 });
}); });
}); });
import { shallowMount, RouterLinkStub } from "@vue/test-utils";
import ADCE from "@/views/ADCE.vue";
// vue-easy-lightbox doesn't play nice in tests, so we have to mock it
jest.mock("vue-easy-lightbox", () => {
return {
install: jest.fn()
};
});
describe("ADCE.vue", () => {
let wrapper;
beforeEach(() => {
wrapper = shallowMount(ADCE, {
stubs: {
RouterLink: RouterLinkStub
}
});
});
afterEach(() => {
jest.clearAllMocks();
});
it("should show lightbox", () => {
expect(wrapper.vm.lightbox.visible).toBe(false);
expect(wrapper.vm.lightbox.index).toBe(0);
wrapper.vm.showImg(1);
expect(wrapper.vm.lightbox.visible).toBe(true);
expect(wrapper.vm.lightbox.index).toBe(1);
});
it("should show lightbox", () => {
wrapper.vm.showImg(0);
wrapper.vm.handleHide();
expect(wrapper.vm.lightbox.visible).toBe(false);
});
});
import { shallowMount, RouterLinkStub } from "@vue/test-utils";
import { iframeResizer } from "iframe-resizer";
import ContactUs from "@/views/ContactUs.vue";
describe("ContactUs.vue", () => {
let wrapper;
beforeEach(() => {
process.env.BASE_URL = "test";
wrapper = shallowMount(ContactUs, {
stubs: {
RouterLink: RouterLinkStub
},
directives: {
resize: {
bind: function(el, { value = {} }) {
el.addEventListener("load", () => iframeResizer(value, el));
}
}
}
});
});
afterEach(() => {
jest.clearAllMocks();
});
it("should respect BASE_URL", () => {
expect(wrapper.find("iframe").attributes("src")).toBe(
"test/static/p1-intake-form.html"
);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment