From cf9381309e9e9a0ce9bb79937906595232ae1105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Viricel?= Date: Mon, 21 Dec 2020 22:36:16 +0100 Subject: [PATCH] Create Vehicle component + tests --- components/Vehicle/Vehicle.spec.js | 30 +++++++++++++++++++++++++++ components/Vehicle/index.vue | 33 ++++++++++++++++++++++++++++++ pages/films/_id.spec.js | 6 ++++-- pages/films/_id.vue | 17 ++++++++++----- store/vehicles/index.js | 5 ++++- test/fake-vehicles.json | 32 +++++++++++++++++++++++++++++ 6 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 components/Vehicle/Vehicle.spec.js create mode 100644 components/Vehicle/index.vue create mode 100644 test/fake-vehicles.json diff --git a/components/Vehicle/Vehicle.spec.js b/components/Vehicle/Vehicle.spec.js new file mode 100644 index 0000000..864ed0d --- /dev/null +++ b/components/Vehicle/Vehicle.spec.js @@ -0,0 +1,30 @@ +import { mount, RouterLinkStub } from "@vue/test-utils"; +import Vehicle from "./"; +import mockVehicles from "@/test/fake-vehicles.json"; + +describe("Vehicle", () => { + it("tests props", () => { + expect(Vehicle.props).toMatchObject({ + vehicle: { + type: Object, + default: {}, + required: true + } + }); + }); + + it("renders proper link to details", () => { + const wrapper = mount(Vehicle, { + propsData: { + vehicle: mockVehicles[0] + }, + stubs: { + RouterLink: RouterLinkStub + } + }); + + expect(wrapper.findComponent(RouterLinkStub).props().to).toBe( + `/vehicles/${mockVehicles[0].id}` + ); + }); +}); diff --git a/components/Vehicle/index.vue b/components/Vehicle/index.vue new file mode 100644 index 0000000..e8b05db --- /dev/null +++ b/components/Vehicle/index.vue @@ -0,0 +1,33 @@ + + + + + diff --git a/pages/films/_id.spec.js b/pages/films/_id.spec.js index 27725a3..7b501d0 100644 --- a/pages/films/_id.spec.js +++ b/pages/films/_id.spec.js @@ -41,7 +41,8 @@ describe("Film page", () => { store, computed: { film: () => mockFilms[0], - people: () => jest.fn() + people: () => jest.fn(), + vehicles: () => jest.fn() } }); expect(wrapper.exists()).toBe(true); @@ -67,7 +68,8 @@ describe("Film page", () => { store, computed: { film: () => mockFilms[0], - people: () => jest.fn() + people: () => jest.fn(), + vehicles: () => jest.fn() } }); diff --git a/pages/films/_id.vue b/pages/films/_id.vue index e073754..adfa4df 100644 --- a/pages/films/_id.vue +++ b/pages/films/_id.vue @@ -40,15 +40,18 @@ -