Skip to content

Commit 0737316

Browse files
committed
more tests for getting cons and subjects
1 parent 9dc8b3e commit 0737316

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed

src/main.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,6 @@ ${xhr.responseText}`)
245245
})
246246
},
247247
get_contractor_list () {
248-
// if an error already exists show that and return
249-
if (error !== null) {
250-
return
251-
}
252248
if (this.$route.name === 'index') {
253249
if (this.$route.params.type === 's' && this.$route.params.link) {
254250
this.$set(this, 'selected_subject_id', parseInt(this.$route.params.link.match(/\d+/)[0]))

test/unit/specs/main.js

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ describe('main.js', () => {
118118
server = sinon.fakeServer.create()
119119
server.autoRespond = true
120120
server.respondWith('/public_key/contractors', dft_response)
121+
server.respondWith('/public_key/contractors?subject=123', [200, {}, '[]'])
121122
server.respondWith('/public_key/subjects', [200, {}, '[]'])
122123
server.respondWith('/public_key/enquiry', dft_response) // to prevent errors with get_enquiry
123124
prepare_ga()
@@ -127,7 +128,7 @@ describe('main.js', () => {
127128
teardown_ga()
128129
})
129130

130-
it('should download contractors', async () => {
131+
it('get_contractor_list vanilla download', async () => {
131132
let el = document.createElement('div')
132133
el.setAttribute('id', 'socket')
133134
document.body.appendChild(el)
@@ -138,6 +139,24 @@ describe('main.js', () => {
138139
expect(vm.error).to.equal(null)
139140
expect(vm.contractors).to.deep.equal([{name: 'Foobars', link: '123-foobar'}])
140141
})
142+
143+
it('get_contractor_list subjects filtered', async () => {
144+
let el = document.createElement('div')
145+
el.setAttribute('id', 'socket')
146+
document.body.appendChild(el)
147+
148+
const vm = socket('public_key', {url_root: '/'})
149+
vm.subjects = [{id: 123, name: 'Foo', link: '123-foo'}]
150+
expect(vm.selected_subject_id).to.equal(null)
151+
vm.$router.push({name: 'index', params: {type: 's', link: '123-foo'}})
152+
await sleep(50)
153+
expect(vm.error).to.equal(null)
154+
155+
expect(vm.contractors).to.deep.equal([])
156+
expect(vm.selected_subject_id).to.equal(123)
157+
vm.$router.push({name: 'index'})
158+
await sleep(50)
159+
})
141160
})
142161

143162
describe('main.js', () => {
@@ -194,7 +213,7 @@ describe('main.js', () => {
194213
await sleep(50)
195214
expect(vm.error).to.contain('Connection error')
196215
expect(vm.error).to.contain('response status: 0')
197-
expect(test_console.error_).to.have.lengthOf(3)
216+
expect(test_console.error_).to.have.lengthOf(2)
198217
})
199218
})
200219

@@ -307,3 +326,50 @@ describe('main.js', () => {
307326
})
308327
})
309328
})
329+
330+
describe('main.js', () => {
331+
let server
332+
before(() => {
333+
server = sinon.fakeServer.create()
334+
server.autoRespond = true
335+
server.respondWith('/public-key/contractors', dft_response)
336+
server.respondWith('/public-key/enquiry', [200, {'Content-Type': 'application/json'}, '{"response": "ok"}'])
337+
server.respondWith('/public-key/subjects', [200, {}, '[1, 2, 3]'])
338+
server.respondWith('/foobar', [200, {'Content-Type': 'application/json'}, '{"the": "response"}'])
339+
prepare_ga()
340+
})
341+
after(() => {
342+
server.restore()
343+
teardown_ga()
344+
})
345+
346+
it('get_selected_subject', async () => {
347+
let el = document.createElement('div')
348+
el.setAttribute('id', 'socket')
349+
document.body.appendChild(el)
350+
351+
const vm = socket('public-key', {url_root: '/'})
352+
expect(vm.get_selected_subject()).to.equal(null)
353+
354+
vm.subjects = [{id: 123, name: 'Foo', link: '123-foo'}]
355+
vm.selected_subject_id = 123
356+
expect(vm.get_selected_subject()).to.deep.equal({id: 123, name: 'Foo', link: '123-foo'})
357+
})
358+
359+
it('get_subject_list', async () => {
360+
let el = document.createElement('div')
361+
el.setAttribute('id', 'socket')
362+
document.body.appendChild(el)
363+
364+
const vm = socket('public-key', {url_root: '/'})
365+
vm.get_subject_list()
366+
await sleep(50)
367+
expect(vm.subjects).to.deep.equal([1, 2, 3])
368+
369+
vm.subjects = [{id: 1}]
370+
expect(vm.subjects).to.deep.equal([{id: 1}])
371+
vm.get_subject_list()
372+
await sleep(50)
373+
expect(vm.subjects).to.deep.equal([{id: 1}])
374+
})
375+
})

0 commit comments

Comments
 (0)