Skip to content

Commit fc33a80

Browse files
committed
testing grid subject filter changes
1 parent 36cf94e commit fc33a80

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

src/components/grid.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</div>
99
<div class="tcs-flex">
1010
<div v-for="contractor in contractors" class="tcs-col">
11-
<router-link :to="{name: 'con-modal', params: {link: contractor.link}}" class="tcs-box">
11+
<router-link v-if="contractor" :to="{name: 'con-modal', params: {link: contractor.link}}" class="tcs-box">
1212
<img :src="contractor.photo" :alt="contractor.name" class="tcs-thumb">
1313
<h3 class="tcs-name">{{ contractor.name }}</h3>
1414
</router-link>
@@ -32,9 +32,10 @@ export default {
3232
description () {
3333
if (this.$root.selected_subject_id) {
3434
const msg_id_suffix = this.$root.contractors.length === 1 ? 'single' : 'plural'
35+
const subject = this.$root.get_selected_subject()
3536
return this.$root.get_text('subject_filter_summary_' + msg_id_suffix, {
3637
count: this.$root.contractors.length,
37-
subject: this.$root.get_selected_subject().name,
38+
subject: subject && subject.name,
3839
})
3940
}
4041
}

src/components/subject-select.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@select="changed">
1010
<div slot="carret">
1111
<div @mousedown.prevent="" class="multiselect__select"></div>
12-
<div class="cross" @mousedown.prevent="changed()">
12+
<div class="cross" @click="changed()" @mousedown.prevent>
1313
<cross></cross>
1414
</div>
1515
</div>

test/unit/karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module.exports = function (config) {
4343
// http://karma-runner.github.io/0.13/config/browsers.html
4444
// 2. add it to the `browsers` array below.
4545
browsers: ['PhantomJS'],
46+
// browsers: ['Chrome'],
4647
frameworks: ['mocha', 'sinon-chai'],
4748
reporters: ['spec', 'coverage'],
4849
files: ['./index.js'],

test/unit/specs/grid.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue'
22
import VueRouter from 'vue-router'
33
import grid from 'src/components/grid'
4+
import {tick, sleep} from './_shared'
45

56
describe('grid.vue', () => {
67
it('should render contractors', () => {
@@ -15,7 +16,7 @@ describe('grid.vue', () => {
1516
data: {
1617
contractors: [{name: 'Fred Bloggs', link: '123-fred-bloggs', photo: 'http://path/to/img.jpg'}],
1718
subjects: [],
18-
config: {subject_filter: true},
19+
config: {subject_filter: false},
1920
},
2021
methods: {
2122
get_contractor_list: () => null,
@@ -27,5 +28,58 @@ describe('grid.vue', () => {
2728
expect(vm.$el.querySelector('h3').textContent).to.equal('Fred Bloggs')
2829
expect(vm.$el.querySelector('a').attributes['href'].value).to.equal('#/123-fred-bloggs')
2930
expect(vm.$el.querySelector('img').attributes['src'].value).to.equal('http://path/to/img.jpg')
31+
expect(vm.$el.querySelectorAll('.tcs-select-container')).to.have.lengthOf(0)
32+
})
33+
})
34+
35+
describe('grid.vue', () => {
36+
it('should filter contractors', async () => {
37+
Vue.use(VueRouter)
38+
const router = new VueRouter({routes: [
39+
{path: '/:type(s|q)?/:link(\\d+-[\\w-]+)?', name: 'index', component: {render: h => '-'}},
40+
{path: '/:link', name: 'con-modal', component: {render: h => '-'}},
41+
]})
42+
const routes_visited = []
43+
const vm = new Vue({
44+
el: document.createElement('div'),
45+
router: router,
46+
render: (h) => h(grid),
47+
data: {
48+
contractors: [{name: 'Fred Bloggs', link: '123-fred-bloggs', photo: 'http://path/to/img.jpg'}],
49+
subjects: [],
50+
config: {subject_filter: true},
51+
},
52+
watch: {
53+
'$route' (to) {
54+
routes_visited.push(to.path)
55+
}
56+
},
57+
methods: {
58+
get_contractor_list: () => null,
59+
get_subject_list () {
60+
this.subjects.push({id: 1, name: 'Maths', link: '1-maths'})
61+
this.subjects.push({id: 2, name: 'English', link: '2-english'})
62+
this.subjects.push({id: 3, name: 'Science', link: '3-science'})
63+
},
64+
get_selected_subject: () => null,
65+
get_text: () => null,
66+
}
67+
})
68+
expect(routes_visited).to.deep.equal([])
69+
expect(vm.$el.querySelector('h3').textContent).to.equal('Fred Bloggs')
70+
expect(vm.$el.querySelectorAll('.tcs-select-container')).to.have.lengthOf(1)
71+
expect(vm.$el.querySelectorAll('input')).to.have.lengthOf(1)
72+
73+
vm.$el.querySelector('.multiselect').dispatchEvent(new window.Event('focus'))
74+
await tick()
75+
const s = vm.$el.querySelectorAll('.multiselect__element')[2].querySelector('span')
76+
expect(s.innerText).to.equal('Science')
77+
s.dispatchEvent(new window.Event('mousedown'))
78+
await tick()
79+
expect(routes_visited).to.deep.equal(['/s/3-science'])
80+
81+
vm.$el.querySelector('.cross').click()
82+
await tick()
83+
expect(routes_visited).to.deep.equal(['/s/3-science', '/'])
3084
})
3185
})

0 commit comments

Comments
 (0)