@@ -12,165 +12,161 @@ chai.use(chaiAsPromised);
1212chai . use ( chaiArrays ) ;
1313const expect = chai . expect ;
1414
15- describe ( 'Libraries' , function ( ) {
16- before ( utils . launchBrowser ) ;
17-
18- after ( utils . closeBrowser ) ;
19-
20- it ( 'Displays libraries when clicking on navbar' , async function ( ) {
21- await this . page . click ( 'a[href="#libraries-io"]' ) ;
22- // Wait for scroll
23- await this . page . waitFor ( 3000 ) ;
24- expect ( await this . page . $eval ( '#libraries-io' , isVisible ) ) . to . be . true ;
25- } ) ;
26-
27- it ( 'Displays a sorted library filter' , async function ( ) {
28- const libraries = await this . page . $eval ( '#libraries-select' , select => {
29- const result = [ ] ;
30-
31- Array . prototype . forEach . call ( select . children , element => {
32- result . push ( element . value ) ;
33- } ) ;
34-
35- return result ;
15+ describe . only ( 'Libraries' , function ( ) {
16+ before ( utils . launchBrowser )
17+ before ( async function ( ) {
18+ await this . page . goto ( `http://localhost:8000/libraries` ) ;
3619 } ) ;
3720
38- expect ( libraries ) . to . be . sorted ;
39- } ) ;
21+ after ( utils . closeBrowser ) ;
4022
41- it ( 'Should all have a valid logo' , async function ( ) {
42- const imgs = await this . page . $$eval ( '.panel-heading img' , imgs => {
43- return Array . prototype . map . call ( imgs , img => img . src ) ;
44- } ) ;
23+ it ( 'Displays a sorted library filter' , async function ( ) {
24+ const libraries = await this . page . $eval ( '#libraries-select' , select => {
25+ const result = [ ] ;
4526
46- const uniqueImgs = new Set ( imgs ) ;
47-
48- const promises = [ ] ;
49- for ( src of uniqueImgs ) {
50- promises . push ( request ( src ) ) ;
51- }
52-
53- return expect ( Promise . all ( promises ) ) . to . be . fulfilled ;
54- } ) ;
55-
56- it ( 'Hides and displays libraries using filters' , async function ( ) {
57- await this . page . select ( '#libraries-select' , '.php' ) ;
58- // Wait for animation
59- await this . page . waitFor ( 2000 ) ;
60-
61- expect ( await this . page . $eval ( '.php' , isVisible ) ) . to . be . true ;
62- expect ( await this . page . $eval ( '.net' , isVisible ) ) . to . be . false ;
63- expect ( await this . page . $eval ( '.python' , isVisible ) ) . to . be . false ;
64-
65- await this . page . waitForSelector ( '.net' , {
66- hidden : true
67- } ) ;
68- await this . page . waitForSelector ( '.python' , {
69- hidden : true
70- } ) ;
27+ Array . prototype . forEach . call ( select . children , element => {
28+ result . push ( element . value ) ;
29+ } ) ;
7130
72- await this . page . select ( '#libraries-select' , '*' ) ;
73- // Wait for animation
74- await this . page . waitFor ( 2000 ) ;
31+ return result ;
32+ } ) ;
7533
76- await this . page . waitForSelector ( '.net' , {
77- visible : true
34+ expect ( libraries ) . to . be . sorted ;
7835 } ) ;
79- await this . page . waitForSelector ( '.php' , {
80- visible : true
81- } ) ;
82- await this . page . waitForSelector ( '.python' , {
83- visible : true
84- } ) ;
85- } ) ;
86-
87- it ( 'Shows a repo link for each library' , async function ( ) {
88- expect ( await this . page . $$eval ( '.repository a' , elements => {
89- return Array . prototype . every . call ( elements , e => {
90- return ! ! e . href ;
91- } ) ;
92- } ) ) . to . be . true ;
93- } ) ;
94-
95- // skipped since we're pulling these on the server now
96- it . skip ( 'Has a data-repo attribute for star counts if repo ' +
97- 'is in GitHub' , async function ( ) {
98- const repos = await this . page . $$eval ( '.panel-wrap' , bodies => {
99- const result = [ ] ;
100- for ( let i = 0 ; i < bodies . length ; ++ i ) {
101- const spanStars = bodies [ i ] . querySelector ( 'span.stars' ) ;
102- const repoUrl = bodies [ i ] . querySelector ( '.repository a' ) . href ;
103-
104- if ( repoUrl . indexOf ( 'github' ) !== - 1 ) {
105- result . push ( {
106- url : repoUrl ,
107- dataRepo : spanStars ? spanStars . getAttribute ( 'data-repo' ) : null
108- } ) ;
36+
37+ it ( 'Should all have a valid logo' , async function ( ) {
38+ const imgs = await this . page . $$eval ( '.panel-heading img' , imgs => {
39+ return Array . prototype . map . call ( imgs , img => img . src ) ;
40+ } ) ;
41+
42+ const uniqueImgs = new Set ( imgs ) ;
43+
44+ const promises = [ ] ;
45+ for ( src of uniqueImgs ) {
46+ promises . push ( request ( src ) ) ;
10947 }
110- }
11148
112- return result ;
49+ return expect ( Promise . all ( promises ) ) . to . be . fulfilled ;
11350 } ) ;
11451
115- for ( const repo of repos ) {
116- expect ( repo . dataRepo , repo . url ) . to . exist . and . not . be . empty ;
117- }
118- } ) ;
119-
120- it ( 'Displays libraries stacked on top of each other ' +
121- 'for small screens' , async function ( ) {
122- try {
123- await this . page . setViewport ( {
124- width : 375 ,
125- height : 1080
126- } ) ;
127-
128- const libraries = await this . page . $$ ( 'article.accordion' ) ;
129-
130- let last = await libraries [ 0 ] . boundingBox ( ) ;
131- const result = await Promise . all ( libraries . slice ( 1 ) . map ( async element => {
132- const box = await element . boundingBox ( ) ;
133- const result = box . x === last . x && box . y > last . y ;
134- last = box ;
135- return result ;
136- } ) ) ;
137-
138- expect ( result . every ( value => value ) ) . to . be . true ;
139- } finally {
140- await this . page . setViewport ( {
141- width : 1920 ,
142- height : 1080
143- } ) ;
144- }
145- } ) ;
146-
147- it ( 'Sets the right classes when the vulnerability is and ' +
148- 'is not displayed ' , async function ( ) {
149- expect ( await this . page . $$eval ( '.panel-wrap' , elements => {
150- function getLibraryName ( panelWrapElement ) {
151- return panelWrapElement . parentNode
152- . querySelector ( 'h3' )
153- . firstChild
154- . textContent ;
155- }
156-
157- const result = [ ] ;
158-
159- Array . prototype . forEach . call ( elements , el => {
160- const versionPresent = ! ! el . querySelector ( '.version' ) ;
161- const panelBodyElement = el . querySelector ( '.panel-body' ) ;
162- const mversionPresent = panelBodyElement . classList . contains ( 'mversion' ) ;
163-
164- if ( ( versionPresent && mversionPresent ) ||
165- ( ! versionPresent && ! mversionPresent ) ) {
166- // All good
167- return ;
168- }
52+ it ( 'Hides and displays libraries using filters' , async function ( ) {
53+ await this . page . select ( '#libraries-select' , '.php' ) ;
54+ // Wait for animation
55+ await this . page . waitFor ( 2000 ) ;
56+
57+ expect ( await this . page . $eval ( '.php' , isVisible ) ) . to . be . true ;
58+ expect ( await this . page . $eval ( '.net' , isVisible ) ) . to . be . false ;
59+ expect ( await this . page . $eval ( '.python' , isVisible ) ) . to . be . false ;
60+
61+ await this . page . waitForSelector ( '.net' , {
62+ hidden : true
63+ } ) ;
64+ await this . page . waitForSelector ( '.python' , {
65+ hidden : true
66+ } ) ;
67+
68+ await this . page . select ( '#libraries-select' , '*' ) ;
69+ // Wait for animation
70+ await this . page . waitFor ( 2000 ) ;
71+
72+ await this . page . waitForSelector ( '.net' , {
73+ visible : true
74+ } ) ;
75+ await this . page . waitForSelector ( '.php' , {
76+ visible : true
77+ } ) ;
78+ await this . page . waitForSelector ( '.python' , {
79+ visible : true
80+ } ) ;
81+ } ) ;
16982
170- result . push ( getLibraryName ( el ) ) ;
171- } ) ;
83+ it ( 'Shows a repo link for each library' , async function ( ) {
84+ expect ( await this . page . $$eval ( '.repository a' , elements => {
85+ return Array . prototype . every . call ( elements , e => {
86+ return ! ! e . href ;
87+ } ) ;
88+ } ) ) . to . be . true ;
89+ } ) ;
17290
173- return result ;
174- } ) ) . to . be . empty ;
175- } ) ;
176- } ) ;
91+ // skipped since we're pulling these on the server now
92+ it . skip ( 'Has a data-repo attribute for star counts if repo ' +
93+ 'is in GitHub' , async function ( ) {
94+ const repos = await this . page . $$eval ( '.panel-wrap' , bodies => {
95+ const result = [ ] ;
96+ for ( let i = 0 ; i < bodies . length ; ++ i ) {
97+ const spanStars = bodies [ i ] . querySelector ( 'span.stars' ) ;
98+ const repoUrl = bodies [ i ] . querySelector ( '.repository a' ) . href ;
99+
100+ if ( repoUrl . indexOf ( 'github' ) !== - 1 ) {
101+ result . push ( {
102+ url : repoUrl ,
103+ dataRepo : spanStars ? spanStars . getAttribute ( 'data-repo' ) : null
104+ } ) ;
105+ }
106+ }
107+
108+ return result ;
109+ } ) ;
110+
111+ for ( const repo of repos ) {
112+ expect ( repo . dataRepo , repo . url ) . to . exist . and . not . be . empty ;
113+ }
114+ } ) ;
115+
116+ it ( 'Displays libraries stacked on top of each other ' +
117+ 'for small screens' , async function ( ) {
118+ try {
119+ await this . page . setViewport ( {
120+ width : 375 ,
121+ height : 1080
122+ } ) ;
123+
124+ const libraries = await this . page . $$ ( 'article.accordion' ) ;
125+
126+ let last = await libraries [ 0 ] . boundingBox ( ) ;
127+ const result = await Promise . all ( libraries . slice ( 1 ) . map ( async element => {
128+ const box = await element . boundingBox ( ) ;
129+ const result = box . x === last . x && box . y > last . y ;
130+ last = box ;
131+ return result ;
132+ } ) ) ;
133+
134+ expect ( result . every ( value => value ) ) . to . be . true ;
135+ } finally {
136+ await this . page . setViewport ( {
137+ width : 1920 ,
138+ height : 1080
139+ } ) ;
140+ }
141+ } ) ;
142+
143+ it ( 'Sets the right classes when the vulnerability is and ' +
144+ 'is not displayed ' , async function ( ) {
145+ expect ( await this . page . $$eval ( '.panel-wrap' , elements => {
146+ function getLibraryName ( panelWrapElement ) {
147+ return panelWrapElement . parentNode
148+ . querySelector ( 'h3' )
149+ . firstChild
150+ . textContent ;
151+ }
152+
153+ const result = [ ] ;
154+
155+ Array . prototype . forEach . call ( elements , el => {
156+ const versionPresent = ! ! el . querySelector ( '.version' ) ;
157+ const panelBodyElement = el . querySelector ( '.panel-body' ) ;
158+ const mversionPresent = panelBodyElement . classList . contains ( 'mversion' ) ;
159+
160+ if ( ( versionPresent && mversionPresent ) ||
161+ ( ! versionPresent && ! mversionPresent ) ) {
162+ // All good
163+ return ;
164+ }
165+
166+ result . push ( getLibraryName ( el ) ) ;
167+ } ) ;
168+
169+ return result ;
170+ } ) ) . to . be . empty ;
171+ } ) ;
172+ } ) ;
0 commit comments