Fix people details page + pass test
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { mount, createLocalVue } from "@vue/test-utils";
|
||||
import Vuex from "vuex";
|
||||
import Person from "./_id";
|
||||
import mockPeople from "@/test/fake-people.json";
|
||||
|
||||
let $route = {
|
||||
path: "/people",
|
||||
@@ -22,11 +23,25 @@ describe("Person page", () => {
|
||||
actions = {
|
||||
getPerson: jest.fn()
|
||||
};
|
||||
store = new Vuex.Store({ state, actions });
|
||||
store = new Vuex.Store({
|
||||
modules: {
|
||||
people: {
|
||||
namespaced: true,
|
||||
state,
|
||||
actions
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("should render Person page instance", () => {
|
||||
const wrapper = mount(Person, { localVue, store });
|
||||
const wrapper = mount(Person, {
|
||||
localVue,
|
||||
store,
|
||||
computed: {
|
||||
person: () => mockPeople[0]
|
||||
}
|
||||
});
|
||||
expect(wrapper.exists()).toBe(true);
|
||||
});
|
||||
|
||||
@@ -47,7 +62,10 @@ describe("Person page", () => {
|
||||
it("should dispatch getPerson action", async () => {
|
||||
let wrapper = mount(Person, {
|
||||
localVue,
|
||||
store
|
||||
store,
|
||||
computed: {
|
||||
person: () => mockPeople[0]
|
||||
}
|
||||
});
|
||||
|
||||
await wrapper.vm.$options.asyncData({ store, params: $route.params });
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapState } from "vuex";
|
||||
import { mapGetters } from "vuex";
|
||||
|
||||
export default {
|
||||
name: "Person",
|
||||
@@ -21,10 +21,13 @@ export default {
|
||||
return uuid.test(params.id);
|
||||
},
|
||||
async asyncData({ params, store }) {
|
||||
await store.dispatch("getPerson", params.id);
|
||||
if (!store.state.people.person.id !== params.id)
|
||||
await store.dispatch("people/getPerson", params.id);
|
||||
},
|
||||
computed: {
|
||||
...mapState(["person"])
|
||||
...mapGetters({
|
||||
person: "people/person"
|
||||
})
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -25,7 +25,9 @@ export const actions = {
|
||||
},
|
||||
async getPerson({ commit }, id) {
|
||||
try {
|
||||
const person = await this.$axios.$get(`/api/people/${id}`);
|
||||
const person = await this.$axios.$get(
|
||||
`/api/people/${id}?fields=id,name,gender,age,eye_color,hair_color,films`
|
||||
);
|
||||
commit("setPerson", person);
|
||||
} catch (e) {
|
||||
throw Error(`API Error occurred: ${e.message}`);
|
||||
|
||||
Reference in New Issue
Block a user