Create Vehicle component + tests
This commit is contained in:
30
components/Vehicle/Vehicle.spec.js
Normal file
30
components/Vehicle/Vehicle.spec.js
Normal 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}`
|
||||
);
|
||||
});
|
||||
});
|
||||
33
components/Vehicle/index.vue
Normal file
33
components/Vehicle/index.vue
Normal 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>
|
||||
Reference in New Issue
Block a user