Fix vehicles details page + pass test

This commit is contained in:
2020-12-21 22:59:09 +01:00
parent 16a0dc47da
commit add48e09a8
2 changed files with 27 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
import { mount, createLocalVue } from "@vue/test-utils"; import { mount, createLocalVue } from "@vue/test-utils";
import Vuex from "vuex"; import Vuex from "vuex";
import Vehicle from "./_id"; import Vehicle from "./_id";
import mockVehicles from "@/test/fake-vehicles.json";
let $route = { let $route = {
path: "/vehicles", path: "/vehicles",
@@ -22,11 +23,25 @@ describe("Vehicle page", () => {
actions = { actions = {
getVehicle: jest.fn() getVehicle: jest.fn()
}; };
store = new Vuex.Store({ state, actions }); store = new Vuex.Store({
modules: {
vehicles: {
namespaced: true,
state,
actions
}
}
});
}); });
it("should render Vehicle page instance", () => { it("should render Vehicle page instance", () => {
const wrapper = mount(Vehicle, { localVue, store }); const wrapper = mount(Vehicle, {
localVue,
store,
computed: {
vehicle: () => mockVehicles[0]
}
});
expect(wrapper.exists()).toBe(true); expect(wrapper.exists()).toBe(true);
}); });
@@ -47,7 +62,10 @@ describe("Vehicle page", () => {
it("should dispatch getVehicle action", async () => { it("should dispatch getVehicle action", async () => {
let wrapper = mount(Vehicle, { let wrapper = mount(Vehicle, {
localVue, localVue,
store store,
computed: {
vehicle: () => mockVehicles[0]
}
}); });
await wrapper.vm.$options.asyncData({ store, params: $route.params }); await wrapper.vm.$options.asyncData({ store, params: $route.params });

View File

@@ -5,7 +5,7 @@
</template> </template>
<script> <script>
import { mapState } from "vuex"; import { mapGetters } from "vuex";
export default { export default {
name: "Vehicle", name: "Vehicle",
@@ -21,10 +21,13 @@ export default {
return uuid.test(params.id); return uuid.test(params.id);
}, },
async asyncData({ params, store }) { async asyncData({ params, store }) {
await store.dispatch("getVehicle", params.id); if (!store.state.vehicles.vehicle.id !== params.id)
await store.dispatch("vehicles/getVehicle", params.id);
}, },
computed: { computed: {
...mapState(["vehicle"]) ...mapGetters({
vehicle: "vehicles/vehicle"
})
} }
}; };
</script> </script>