Create Vehicle component + tests

This commit is contained in:
2020-12-21 22:36:16 +01:00
parent 21f3ed77a4
commit cf9381309e
6 changed files with 115 additions and 8 deletions

View File

@@ -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}`
);
});
});

View File

@@ -0,0 +1,33 @@
<template>
<router-link
class="vehicle flex items-center cursor-pointer p-3 mb-2 rounded bg-gray-300 hover:bg-gray-400"
:to="`/vehicles/${vehicle.id}`"
tag="article"
>
<span
class="mr-2 text-sm rounded-xl px-2 py-1"
:class="{
'bg-teal-400': vehicle.vehicle_class === 'Airship',
'bg-red-400': vehicle.vehicle_class === 'Airplane',
'bg-orange-400': vehicle.vehicle_class === 'Boat'
}"
>{{ vehicle.vehicle_class }}</span
>
<h4>{{ vehicle.name }}</h4>
</router-link>
</template>
<script>
export default {
name: "Vehicle",
props: {
vehicle: {
type: Object,
default: {},
required: true
}
}
};
</script>
<style lang="css" scoped></style>