Create Location component + tests

This commit is contained in:
2020-12-21 22:43:29 +01:00
parent cf9381309e
commit c3bb17f863
6 changed files with 472 additions and 8 deletions

View File

@@ -0,0 +1,30 @@
import { mount, RouterLinkStub } from "@vue/test-utils";
import Location from "./";
import mockLocation from "@/test/fake-locations.json";
describe("Location", () => {
it("tests props", () => {
expect(Location.props).toMatchObject({
location: {
type: Object,
default: {},
required: true
}
});
});
it("renders proper link to details", () => {
const wrapper = mount(Location, {
propsData: {
location: mockLocation[0]
},
stubs: {
RouterLink: RouterLinkStub
}
});
expect(wrapper.findComponent(RouterLinkStub).props().to).toBe(
`/locations/${mockLocation[0].id}`
);
});
});

View File

@@ -0,0 +1,27 @@
<template>
<router-link
class="location flex items-center cursor-pointer p-3 mb-2 rounded bg-gray-300 hover:bg-gray-400"
:to="`/locations/${location.id}`"
tag="article"
>
<span class="mr-2 text-sm rounded-xl px-2 py-1">{{
location.terrain
}}</span>
<h4>{{ location.name }}</h4>
</router-link>
</template>
<script>
export default {
name: "Location",
props: {
location: {
type: Object,
default: {},
required: true
}
}
};
</script>
<style lang="css" scoped></style>