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+ //PAGE INFO:
12+ const baseURL = process . env . url || 'https://stage.netpyne.metacell.us/'
13+ const PAGE_WAIT = 3000 ;
14+ const TIMEOUT = 60000 ;
15+
16+ //SNAPSHOT:
17+ const SNAPSHOT_OPTIONS = {
18+ customSnapshotsDir : `./tests/snapshots/${ scriptName } ` ,
19+ comparisonMethod : 'ssim' ,
20+ failureThresholdType : 'percent' ,
21+ failureThreshold : 0.5
22+ } ;
23+
24+
25+ //USERS:
26+ const USERNAME = 'test_user_tut_3b_'
27+ const PASSWORD = 'testpassword'
28+
29+
30+ //TESTS:
31+
32+ jest . setTimeout ( 300000 ) ;
33+
34+
35+
36+ describe ( 'Tutorial #3b for Smoke Testing' , ( ) => {
37+
38+ beforeAll ( async ( ) => {
39+ await page . goto ( baseURL ) ;
40+ await page . waitForSelector ( selectors . LOGIN_PAGE_SELECTOR ) ;
41+ await page . waitForSelector ( selectors . USERNAME_SELECTOR )
42+ await expect ( page )
43+ . toFill ( selectors . USERNAME_SELECTOR , USERNAME , { timeout : TIMEOUT } ) ;
44+
45+ await page . waitForSelector ( selectors . PASSWORD_SELECTOR )
46+ await expect ( page )
47+ . toFill ( selectors . PASSWORD_SELECTOR , PASSWORD , { timeout : TIMEOUT } ) ;
48+
49+ await page . click ( selectors . LOGIN_BUTTON_SELECTOR )
50+ // Wait for initial loading spinner to disappear
51+ await page . waitForFunction ( ( ) => {
52+ let el = document . querySelector ( '#loading-spinner' ) ;
53+ return el == null || el . clientHeight === 0 ;
54+ } , { timeout : TIMEOUT } ) ;
55+ } ) ;
56+
57+ it ( 'Open new page' , async ( ) => {
58+
59+ console . log ( 'Opening a new NetPyNE page' )
60+
61+ await page . on ( "dialog" , dialog =>
62+ dialog . accept ( ) ) ;
63+
64+ await page . waitForSelector ( selectors . FILE_TAB_SELECTOR , { timeout : PAGE_WAIT * 20 } )
65+ await page . waitForTimeout ( PAGE_WAIT * 7 )
66+ await page . click ( selectors . FILE_TAB_SELECTOR )
67+ await page . waitForSelector ( selectors . NEW_FILE_SELECTOR , { timeout : PAGE_WAIT * 10 } )
68+ await page . waitForTimeout ( PAGE_WAIT )
69+ await page . click ( selectors . NEW_FILE_SELECTOR )
70+ await page . waitForTimeout ( PAGE_WAIT )
71+ await page . waitForSelector ( selectors . CONFIRM_NEW_PAGE_SELECTOR )
72+ await page . click ( selectors . CONFIRM_NEW_PAGE_SELECTOR )
73+ await page . waitForTimeout ( PAGE_WAIT * 2 )
74+
75+ await page . waitForFunction ( ( ) => {
76+ let el = document . querySelector ( '#loading-spinner' ) ;
77+ return el == null || el . clientHeight === 0 ;
78+ } , { timeout : TIMEOUT } ) ;
79+
80+
81+
82+ await page . waitForSelector ( selectors . SELECT_CELL_BUTTON_SELECTOR , { timeout : TIMEOUT * 10 } )
83+
84+ } )
85+
86+
87+ it ( 'Create and Simulate network' , async ( ) => {
88+
89+ await page . waitForTimeout ( PAGE_WAIT * 2 )
90+ await page . waitForSelector ( selectors . SELECT_CELL_BUTTON_SELECTOR , { timeout : TIMEOUT } )
91+
92+ console . log ( 'Tutorial #3b' )
93+
94+ await page . waitForTimeout ( PAGE_WAIT )
95+
96+ await page . click ( selectors . TUTORIALS_BUTTON_SELECTOR , { timeout : TIMEOUT } )
97+
98+ await page . click ( selectors . TUTORIAL_3B_SELECTOR , { timeout : TIMEOUT } )
99+ await page . waitForSelector ( selectors . E_CELL_TYPE_SELECTOR )
100+ await page . waitForSelector ( selectors . I_CELL_TYPE_SELECTOR )
101+ await page . waitForTimeout ( PAGE_WAIT )
102+
103+ await page . waitForSelector ( selectors . MODEL_BUTTON_SELECTOR )
104+ await page . click ( selectors . MODEL_BUTTON_SELECTOR , { timeout : TIMEOUT } ) ;
105+ await page . waitForSelector ( selectors . CREATE_NETWORK_SELECTOR )
106+ await page . click ( selectors . CREATE_NETWORK_SELECTOR , { timeout : TIMEOUT } ) ;
107+
108+ console . log ( 'Create network' )
109+
110+ await page . waitForTimeout ( PAGE_WAIT * 3 )
111+
112+ await page . waitForSelector ( selectors . THREE_D_REP_SELECTOR )
113+
114+ console . log ( '... taking snapshot ...' ) ;
115+ await page . waitForTimeout ( PAGE_WAIT ) ;
116+ expect ( await page . screenshot ( ) )
117+ . toMatchImageSnapshot ( {
118+ ...SNAPSHOT_OPTIONS ,
119+ customSnapshotIdentifier : 'Tutorial#3b Network'
120+ } ) ;
121+ await page . click ( selectors . MODEL_BUTTON_SELECTOR , { timeout : TIMEOUT } ) ;
122+ await page . click ( selectors . SIMULATE_NETWORK_SELECTOR , { timeout : TIMEOUT } ) ;
123+
124+ console . log ( 'Simulate network' )
125+
126+ await page . waitForSelector ( selectors . SIMULATION_PAGE_SELECTOR , { timeout : TIMEOUT * 2 } ) ;
127+
128+ await page . waitForSelector ( selectors . RASTER_PLOT_SELECTOR , { timeout : TIMEOUT * 3 } )
129+
130+
131+ } ) ;
132+
133+
134+ it ( 'Connections Plot' , async ( ) => {
135+
136+ await page . waitForTimeout ( PAGE_WAIT * 2 ) ;
137+ await page . click ( selectors . CONNECTIONS_PLOT_SELECTOR , { timeout : TIMEOUT } )
138+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
139+ console . log ( 'View Connections Plot ...' )
140+ await page . waitForTimeout ( PAGE_WAIT ) ;
141+
142+ console . log ( '... taking snapshot ...' ) ;
143+ expect ( await page . screenshot ( ) )
144+ . toMatchImageSnapshot ( {
145+ ...SNAPSHOT_OPTIONS ,
146+ customSnapshotIdentifier : 'Connections Plot'
147+ } ) ;
148+
149+ } ) ;
150+
151+ it ( '2D Net Plot' , async ( ) => {
152+
153+ await page . click ( selectors . TWO_D_NET_PLOT_SELECTOR , { timeout : TIMEOUT } )
154+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
155+ console . log ( 'View 2D Net Plot ...' )
156+ await page . waitForTimeout ( PAGE_WAIT * 3 ) ;
157+
158+ console . log ( '... taking snapshot ...' ) ;
159+ expect ( await page . screenshot ( ) )
160+ . toMatchImageSnapshot ( {
161+ ...SNAPSHOT_OPTIONS ,
162+ customSnapshotIdentifier : '2D Net Plot'
163+ } ) ;
164+ } ) ;
165+
166+ it ( 'Cell Traces Plot' , async ( ) => {
167+
168+ await page . click ( selectors . CELL_TRACES_PLOT_SELECTOR , { timeout : TIMEOUT } )
169+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
170+ console . log ( 'View Cell Traces Plot ...' )
171+ await page . waitForTimeout ( PAGE_WAIT ) ;
172+
173+ console . log ( '... taking snapshot ...' ) ;
174+ expect ( await page . screenshot ( ) )
175+ . toMatchImageSnapshot ( {
176+ ...SNAPSHOT_OPTIONS ,
177+ customSnapshotIdentifier : 'Cell Traces Plot'
178+ } ) ;
179+ } ) ;
180+
181+ it ( 'Raster Plot' , async ( ) => {
182+
183+ await page . click ( selectors . RASTER_PLOT_SELECTOR , { timeout : TIMEOUT } )
184+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
185+ console . log ( 'View Raster Plot ...' )
186+ await page . waitForTimeout ( PAGE_WAIT ) ;
187+
188+ console . log ( '... taking snapshot ...' ) ;
189+ expect ( await page . screenshot ( ) )
190+ . toMatchImageSnapshot ( {
191+ ...SNAPSHOT_OPTIONS ,
192+ customSnapshotIdentifier : 'Raster Plot'
193+ } ) ;
194+ } ) ;
195+
196+ it ( 'Spike Hist Plot' , async ( ) => {
197+
198+ await page . click ( selectors . SPIKE_HIST_PLOT_SELECTOR , { timeout : TIMEOUT } )
199+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
200+ console . log ( 'View Spike Hist Plot ...' )
201+ await page . waitForTimeout ( PAGE_WAIT ) ;
202+
203+ console . log ( '... taking snapshot ...' ) ;
204+ expect ( await page . screenshot ( ) )
205+ . toMatchImageSnapshot ( {
206+ ...SNAPSHOT_OPTIONS ,
207+ customSnapshotIdentifier : 'Spike Hist Plot'
208+ } ) ;
209+ } ) ;
210+
211+ it ( 'LFP Time Series Plot' , async ( ) => {
212+
213+ await page . click ( selectors . LFP_TS_PLOT_SELECTOR , { timeout : TIMEOUT } )
214+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
215+ console . log ( 'View LFP Time Series Plot ...' )
216+ await page . waitForTimeout ( PAGE_WAIT ) ;
217+
218+ console . log ( '... taking snapshot ...' ) ;
219+ expect ( await page . screenshot ( ) )
220+ . toMatchImageSnapshot ( {
221+ ...SNAPSHOT_OPTIONS ,
222+ customSnapshotIdentifier : 'LFP Time Series Plot'
223+ } ) ;
224+ } ) ;
225+
226+ it ( 'LFP PSD Plot' , async ( ) => {
227+
228+ await page . click ( selectors . LFP_PSD_PLOT_SELECTOR , { timeout : TIMEOUT } )
229+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
230+ console . log ( 'View LFP PSD Plot ...' )
231+ await page . waitForTimeout ( PAGE_WAIT * 2 ) ;
232+
233+ console . log ( '... taking snapshot ...' ) ;
234+ expect ( await page . screenshot ( ) )
235+ . toMatchImageSnapshot ( {
236+ ...SNAPSHOT_OPTIONS ,
237+ customSnapshotIdentifier : 'LFP PSD Plot'
238+ } ) ;
239+ } ) ;
240+
241+ it ( 'LFP Spectrogram Plot' , async ( ) => {
242+
243+ await page . click ( selectors . LFP_SPECTOGRAM_PLOT_SELECTOR , { timeout : TIMEOUT } )
244+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
245+ console . log ( 'View LFP Spectrogram Plot ...' )
246+ await page . waitForTimeout ( PAGE_WAIT * 5 ) ;
247+
248+ console . log ( '... taking snapshot ...' ) ;
249+ expect ( await page . screenshot ( ) )
250+ . toMatchImageSnapshot ( {
251+ ...SNAPSHOT_OPTIONS ,
252+ customSnapshotIdentifier : 'LFP Spectrogram Plot'
253+ } ) ;
254+ } ) ;
255+
256+ it ( 'Granger Plot' , async ( ) => {
257+
258+ await page . click ( selectors . GRANGER_PLOT_SELECTOR , { timeout : TIMEOUT } )
259+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
260+ console . log ( 'View Granger Plot ...' )
261+ await page . waitForTimeout ( PAGE_WAIT * 2 ) ;
262+
263+ console . log ( '... taking snapshot ...' ) ;
264+ expect ( await page . screenshot ( ) )
265+ . toMatchImageSnapshot ( {
266+ ...SNAPSHOT_OPTIONS ,
267+ customSnapshotIdentifier : 'Granger Plot'
268+ } ) ;
269+ } ) ;
270+
271+ it ( 'RxD concentration plot' , async ( ) => {
272+
273+ await page . click ( selectors . RXD_CONCENTRATION_PLOT_SELECTOR , { timeout : TIMEOUT } )
274+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
275+ console . log ( 'View RxD concentration plot ...' )
276+ await page . waitForTimeout ( PAGE_WAIT ) ;
277+
278+ console . log ( '... taking snapshot ...' ) ;
279+ expect ( await page . screenshot ( ) )
280+ . toMatchImageSnapshot ( {
281+ ...SNAPSHOT_OPTIONS ,
282+ customSnapshotIdentifier : 'RxD concentration plot'
283+ } ) ;
284+ } ) ;
285+
286+ it ( 'Rate Spectogram Plot' , async ( ) => {
287+
288+ await page . click ( selectors . RATE_SPECTROGRAM_PLOT_SELECTOR , { timeout : TIMEOUT } )
289+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
290+
291+ await page . waitForTimeout ( PAGE_WAIT ) ;
292+
293+ await page . click ( selectors . CONNECTIONS_PLOT_SELECTOR , { timeout : TIMEOUT } )
294+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
295+
296+ await page . waitForTimeout ( PAGE_WAIT ) ;
297+
298+ await page . click ( selectors . RATE_SPECTROGRAM_PLOT_SELECTOR , { timeout : TIMEOUT } )
299+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
300+
301+ console . log ( 'View Rate Spectogram Plot ...' )
302+ await page . waitForTimeout ( PAGE_WAIT ) ;
303+
304+ console . log ( '... taking snapshot ...' ) ;
305+ expect ( await page . screenshot ( ) )
306+ . toMatchImageSnapshot ( {
307+ ...SNAPSHOT_OPTIONS ,
308+ customSnapshotIdentifier : 'Rate Spectogram Plot'
309+ } ) ;
310+ } ) ;
311+
312+ } ) ;
0 commit comments