82 lines
1.7 KiB
JavaScript
82 lines
1.7 KiB
JavaScript
import { mount, createLocalVue } from "@vue/test-utils";
|
|
import Vuex from "vuex";
|
|
import Film from "./_id";
|
|
import mockFilms from "@/test/fake-films.json";
|
|
|
|
let $route = {
|
|
path: "/films",
|
|
params: {
|
|
id: "2baf70d1-42bb-4437-b551-e5fed5a87abe"
|
|
}
|
|
};
|
|
|
|
const localVue = createLocalVue();
|
|
localVue.use(Vuex);
|
|
|
|
describe("Film page", () => {
|
|
let state, actions, store;
|
|
|
|
beforeEach(() => {
|
|
state = {
|
|
film: {}
|
|
};
|
|
actions = {
|
|
getFilm: jest.fn()
|
|
};
|
|
|
|
store = new Vuex.Store({
|
|
modules: {
|
|
films: {
|
|
namespaced: true,
|
|
state,
|
|
actions
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
it("should render Film page instance", () => {
|
|
const wrapper = mount(Film, {
|
|
localVue,
|
|
store,
|
|
computed: {
|
|
film: () => mockFilms[0],
|
|
people: () => jest.fn(),
|
|
vehicles: () => jest.fn(),
|
|
locations: () => jest.fn()
|
|
}
|
|
});
|
|
expect(wrapper.exists()).toBe(true);
|
|
});
|
|
|
|
it("tests params validation", () => {
|
|
expect(Film.validate({ params: $route.params })).toBe(true);
|
|
expect(
|
|
Film.validate({
|
|
params: { id: "2baf70d1-42bb-4437-b551-e5fed5a87abe-1234" }
|
|
})
|
|
).toBe(false);
|
|
expect(
|
|
Film.validate({
|
|
params: { id: "2baf7e0d1-42bb-4437-b551-e5fed5a87abe" }
|
|
})
|
|
).toBe(false);
|
|
});
|
|
|
|
it("should dispatch getFilm action", async () => {
|
|
let wrapper = mount(Film, {
|
|
localVue,
|
|
store,
|
|
computed: {
|
|
film: () => mockFilms[0],
|
|
people: () => jest.fn(),
|
|
vehicles: () => jest.fn(),
|
|
locations: () => jest.fn()
|
|
}
|
|
});
|
|
|
|
await wrapper.vm.$options.asyncData({ store, params: $route.params });
|
|
expect(actions.getFilm).toHaveBeenCalled();
|
|
});
|
|
});
|