Skip to content

Commit

Permalink
Dev: added tests for AircraftModelFilter component
Browse files Browse the repository at this point in the history
  • Loading branch information
lwitkowski committed Aug 2, 2024
1 parent 1919510 commit 75f1ec3
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 15 deletions.
46 changes: 32 additions & 14 deletions ui/src/components/AircraftModelFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export default {
components: {
Multiselect
},
props: {
models: {
type: Object,
default: null
}
},
data() {
return {
aircraft_type: null,
Expand All @@ -39,6 +45,26 @@ export default {
watch: {
$route() {
this.parseAndApplyRoute()
},
selected(val) {
if (val == null) {
return
}
this.$router.push({
name: 'offer_details',
params: { aircraftType: val.aircraft_type, manufacturer: val.manufacturer, model: val.model }
})
}
},
created() {
this.loadAircraftTypes()
},
methods: {
parseAndApplyRoute() {
const pathSegments = this.$route.path.split('/')
switch (pathSegments[1]) {
case 'glider':
Expand All @@ -65,26 +91,18 @@ export default {
this.updateAircraftTypes()
}
},
loadAircraftTypes() {
if (this.models) {
this.all_aircraft_types = this.models
selected(val) {
if (val == null) {
this.parseAndApplyRoute()
this.updateAircraftTypes()
return
}
this.$router.push({
name: 'offer_details',
params: { aircraftType: val.aircraft_type, manufacturer: val.manufacturer, model: val.model }
})
}
},
created() {
this.loadAircraftTypes()
},
methods: {
loadAircraftTypes() {
axios.get(`/models`).then((response) => {
this.all_aircraft_types = response.data
this.parseAndApplyRoute()
this.updateAircraftTypes()
})
},
Expand Down
58 changes: 58 additions & 0 deletions ui/src/components/__tests__/AircraftModelFilter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { describe, it, expect } from 'vitest'
import { mount } from '@vue/test-utils'
import AircraftModelFilter from '../AircraftModelFilter.vue'

const models = {
AlexanderSchleicher: {
models: {
glider: ['ASW 15', 'ASW 17', 'ASW 19', 'ASW 20'],
tmg: ['ASK 14', 'ASK 16']
}
},
Antonov: {
models: {
airplane: ['An-2', 'An-225 Mriya']
}
}
}

const mockRouter = {
push: function () {}
}
const mockRoute = {
path: '/'
}

function mocksWithPath(path) {
mockRoute.path = path
return {
mocks: {
$route: mockRoute,
$router: mockRouter
}
}
}

describe('AircraftModelFilter', () => {
it('should list all categories for homepage', () => {
const wrapper = mount(AircraftModelFilter, {
props: { models: models },
global: mocksWithPath('/')
})

expect(wrapper.text())
.toContain('AlexanderSchleicher', 'ASW 15', 'ASK 16') // both glider and tmg
.toContain('Antonov', 'An-2', 'An-225 Mriya') // airplanes
})

it('should list only gliders on /glider', () => {
const wrapper = mount(AircraftModelFilter, {
props: { models: models },
global: mocksWithPath('/glider')
})

expect(wrapper.text())
.toContain('AlexanderSchleicher', 'ASW 15')
.not.toContain('ASK 16', 'Antonov', 'An-2', 'An-225 Mriya')
})
})
2 changes: 1 addition & 1 deletion ui/src/components/__tests__/OfferThumb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ describe('OfferThumb', () => {

const wrapper = mount(OfferThumb, { props: { offer: offer } })

expect(wrapper.text()).contains('Rolladen Schneider LS4').contains('2020-02-26')
expect(wrapper.text()).toContain('Rolladen Schneider LS4', '2020-02-26')
})
})

0 comments on commit 75f1ec3

Please sign in to comment.