1+ //IMPORTS:
2+ import 'expect-puppeteer' ;
3+ import { click } from './utils' ;
4+ import { toMatchImageSnapshot } from 'jest-image-snapshot'
5+ expect . extend ( { toMatchImageSnapshot } )
6+ const path = require ( 'path' ) ;
7+ var scriptName = path . basename ( __filename , '.js' ) ;
8+ import * as selectors from './selectors'
9+
10+
11+
12+ //PAGE INFO:
13+ const baseURL = process . env . url || 'https://stage.netpyne.metacell.us/'
14+ const PAGE_WAIT = 3000 ;
15+ const TIMEOUT = 60000 ;
16+
17+ //SNAPSHOT:
18+ const SNAPSHOT_OPTIONS = {
19+ customSnapshotsDir : `./tests/snapshots/${ scriptName } ` ,
20+ comparisonMethod : 'ssim' ,
21+ failureThresholdType : 'percent' ,
22+ failureThreshold : 0.5
23+ } ;
24+
25+
26+
27+ //USERS:
28+ const USERNAME = 'test_user_tut_1_'
29+ const PASSWORD = 'testpassword'
30+
31+
32+ //TESTS:
33+
34+ jest . setTimeout ( 300000 ) ;
35+
36+
37+
38+ describe ( 'Tutorial #1 for Smoke Testing' , ( ) => {
39+
40+ beforeAll ( async ( ) => {
41+ await page . goto ( baseURL ) ;
42+ await page . waitForSelector ( selectors . LOGIN_PAGE_SELECTOR ) ;
43+ await page . waitForSelector ( selectors . USERNAME_SELECTOR )
44+ await expect ( page )
45+ . toFill ( selectors . USERNAME_SELECTOR , USERNAME , { timeout : TIMEOUT } ) ;
46+
47+ await page . waitForSelector ( selectors . PASSWORD_SELECTOR )
48+ await expect ( page )
49+ . toFill ( selectors . PASSWORD_SELECTOR , PASSWORD , { timeout : TIMEOUT } ) ;
50+
51+ await page . click ( selectors . LOGIN_BUTTON_SELECTOR )
52+ // Wait for initial loading spinner to disappear
53+ await page . waitForFunction ( ( ) => {
54+ let el = document . querySelector ( '#loading-spinner' ) ;
55+ return el == null || el . clientHeight === 0 ;
56+ } , { timeout : TIMEOUT } ) ;
57+ } ) ;
58+
59+ it ( 'Open new page' , async ( ) => {
60+
61+ console . log ( 'Opening a new NetPyNE page' )
62+
63+ await page . on ( "dialog" , dialog =>
64+ dialog . accept ( ) ) ;
65+
66+ await page . waitForSelector ( selectors . FILE_TAB_SELECTOR , { timeout : PAGE_WAIT * 20 } )
67+ await page . waitForTimeout ( PAGE_WAIT * 7 )
68+ await page . click ( selectors . FILE_TAB_SELECTOR )
69+ await page . waitForSelector ( selectors . NEW_FILE_SELECTOR , { timeout : PAGE_WAIT * 10 } )
70+ await page . waitForTimeout ( PAGE_WAIT )
71+ await page . click ( selectors . NEW_FILE_SELECTOR )
72+ await page . waitForTimeout ( PAGE_WAIT )
73+ await page . waitForSelector ( selectors . CONFIRM_NEW_PAGE_SELECTOR )
74+ await page . click ( selectors . CONFIRM_NEW_PAGE_SELECTOR )
75+ await page . waitForTimeout ( PAGE_WAIT * 2 )
76+
77+ await page . waitForFunction ( ( ) => {
78+ let el = document . querySelector ( '#loading-spinner' ) ;
79+ return el == null || el . clientHeight === 0 ;
80+ } , { timeout : TIMEOUT } ) ;
81+
82+
83+
84+ await page . waitForSelector ( selectors . SELECT_CELL_BUTTON_SELECTOR , { timeout : TIMEOUT * 10 } )
85+
86+ } )
87+
88+
89+ it ( 'Create and Simulate network' , async ( ) => {
90+
91+ await page . waitForTimeout ( PAGE_WAIT * 2 )
92+ await page . waitForSelector ( selectors . SELECT_CELL_BUTTON_SELECTOR , { timeout : TIMEOUT } )
93+
94+ console . log ( 'Tutorial #1' )
95+
96+ await page . waitForTimeout ( PAGE_WAIT )
97+
98+ await click ( page , selectors . TUTORIALS_BUTTON_SELECTOR , { timeout : TIMEOUT } )
99+
100+ await click ( page , selectors . TUTORIAL_1_SELECTOR , { timeout : TIMEOUT } )
101+ await page . waitForSelector ( selectors . PYR_CELL_SELECTOR )
102+ await page . waitForTimeout ( PAGE_WAIT )
103+
104+ await page . waitForSelector ( selectors . MODEL_BUTTON_SELECTOR )
105+ await click ( page , selectors . MODEL_BUTTON_SELECTOR , { timeout : TIMEOUT } ) ;
106+ await page . waitForSelector ( selectors . CREATE_NETWORK_SELECTOR )
107+ await click ( page , selectors . CREATE_NETWORK_SELECTOR , { timeout : TIMEOUT } ) ;
108+
109+ console . log ( 'Create network' )
110+
111+ await page . waitForTimeout ( PAGE_WAIT )
112+
113+ console . log ( '... taking snapshot ...' ) ;
114+ await page . waitForTimeout ( PAGE_WAIT ) ;
115+ expect ( await page . screenshot ( ) )
116+ . toMatchImageSnapshot ( {
117+ ...SNAPSHOT_OPTIONS ,
118+ customSnapshotIdentifier : 'Tutorial#1 Network'
119+ } ) ;
120+
121+ await click ( page , selectors . MODEL_BUTTON_SELECTOR , { timeout : TIMEOUT } ) ;
122+ await click ( page , selectors . SIMULATE_NETWORK_SELECTOR , { timeout : TIMEOUT } ) ;
123+ console . log ( 'Simulate network' )
124+
125+ await page . waitForSelector ( selectors . SIMULATION_PAGE_SELECTOR , { timeout : TIMEOUT * 2 } ) ;
126+
127+ await page . waitForTimeout ( PAGE_WAIT )
128+
129+ } ) ;
130+
131+
132+ it ( 'Connections Plot' , async ( ) => {
133+
134+ await page . waitForTimeout ( PAGE_WAIT * 2 ) ;
135+ await click ( page , selectors . CONNECTIONS_PLOT_SELECTOR , { timeout : TIMEOUT } )
136+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
137+ console . log ( 'View Connections Plot ...' )
138+ await page . waitForTimeout ( PAGE_WAIT ) ;
139+
140+ console . log ( '... taking snapshot ...' ) ;
141+ expect ( await page . screenshot ( ) )
142+ . toMatchImageSnapshot ( {
143+ ...SNAPSHOT_OPTIONS ,
144+ customSnapshotIdentifier : 'Connections Plot'
145+ } ) ;
146+
147+ } ) ;
148+
149+ it ( '2D Net Plot' , async ( ) => {
150+
151+ await click ( page , selectors . TWO_D_NET_PLOT_SELECTOR , { timeout : TIMEOUT } )
152+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
153+ console . log ( 'View 2D Net Plot ...' )
154+ await page . waitForTimeout ( PAGE_WAIT * 2 ) ;
155+
156+ console . log ( '... taking snapshot ...' ) ;
157+ expect ( await page . screenshot ( ) )
158+ . toMatchImageSnapshot ( {
159+ ...SNAPSHOT_OPTIONS ,
160+ customSnapshotIdentifier : '2D Net Plot'
161+ } ) ;
162+ } ) ;
163+
164+ it ( 'Cell Traces Plot' , async ( ) => {
165+
166+ await click ( page , selectors . CELL_TRACES_PLOT_SELECTOR , { timeout : TIMEOUT } )
167+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
168+ console . log ( 'View Cell Traces Plot ...' )
169+ await page . waitForTimeout ( PAGE_WAIT ) ;
170+
171+ console . log ( '... taking snapshot ...' ) ;
172+ expect ( await page . screenshot ( ) )
173+ . toMatchImageSnapshot ( {
174+ ...SNAPSHOT_OPTIONS ,
175+ customSnapshotIdentifier : 'Cell Traces Plot'
176+ } ) ;
177+ } ) ;
178+
179+ it ( 'Raster Plot' , async ( ) => {
180+
181+ await click ( page , selectors . RASTER_PLOT_SELECTOR , { timeout : TIMEOUT } )
182+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
183+ console . log ( 'View Raster Plot ...' )
184+ await page . waitForTimeout ( PAGE_WAIT ) ;
185+
186+ console . log ( '... taking snapshot ...' ) ;
187+ expect ( await page . screenshot ( ) )
188+ . toMatchImageSnapshot ( {
189+ ...SNAPSHOT_OPTIONS ,
190+ customSnapshotIdentifier : 'Raster Plot'
191+ } ) ;
192+ } ) ;
193+
194+ it ( 'Spike Hist Plot' , async ( ) => {
195+
196+ await click ( page , selectors . SPIKE_HIST_PLOT_SELECTOR , { timeout : TIMEOUT } )
197+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
198+ console . log ( 'View Spike Hist Plot ...' )
199+ await page . waitForTimeout ( PAGE_WAIT ) ;
200+
201+ console . log ( '... taking snapshot ...' ) ;
202+ expect ( await page . screenshot ( ) )
203+ . toMatchImageSnapshot ( {
204+ ...SNAPSHOT_OPTIONS ,
205+ customSnapshotIdentifier : 'Spike Hist Plot'
206+ } ) ;
207+ } ) ;
208+
209+ it ( 'Granger Plot' , async ( ) => {
210+
211+ await click ( page , selectors . GRANGER_PLOT_SELECTOR , { timeout : TIMEOUT } )
212+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
213+ console . log ( 'View Granger Plot ...' )
214+ await page . waitForTimeout ( PAGE_WAIT ) ;
215+
216+ console . log ( '... taking snapshot ...' ) ;
217+ expect ( await page . screenshot ( ) )
218+ . toMatchImageSnapshot ( {
219+ ...SNAPSHOT_OPTIONS ,
220+ customSnapshotIdentifier : 'Granger Plot'
221+ } ) ;
222+ } ) ;
223+
224+ it ( 'Rate Spectogram Plot' , async ( ) => {
225+
226+ await click ( page , selectors . RATE_SPECTROGRAM_PLOT_SELECTOR , { timeout : TIMEOUT } )
227+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
228+
229+ await page . waitForTimeout ( PAGE_WAIT ) ;
230+
231+ await click ( page , selectors . CONNECTIONS_PLOT_SELECTOR , { timeout : TIMEOUT } )
232+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
233+
234+ await page . waitForTimeout ( PAGE_WAIT ) ;
235+
236+ await click ( page , selectors . RATE_SPECTROGRAM_PLOT_SELECTOR , { timeout : TIMEOUT } )
237+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
238+
239+ console . log ( 'View Rate Spectogram Plot ...' )
240+ await page . waitForTimeout ( PAGE_WAIT ) ;
241+
242+ console . log ( '... taking snapshot ...' ) ;
243+ expect ( await page . screenshot ( ) )
244+ . toMatchImageSnapshot ( {
245+ ...SNAPSHOT_OPTIONS ,
246+ customSnapshotIdentifier : 'Rate Spectogram Plot'
247+ } ) ;
248+ } ) ;
249+
250+ } ) ;
0 commit comments