11import Vue from 'vue'
22import VueRouter from 'vue-router'
33import grid from 'src/components/grid'
4+ import { tick , sleep } from './_shared'
45
56describe ( '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