@@ -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
143162describe ( '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