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_3a_'
27+ const PASSWORD = 'testpassword'
28+
29+
30+ //TESTS:
31+
32+ jest . setTimeout ( 300000 ) ;
33+
34+
35+
36+ describe ( 'Tutorial #3a 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 #3a' )
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_3A_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#3a Network'
120+ } ) ;
121+
122+ await page . click ( selectors . MODEL_BUTTON_SELECTOR , { timeout : TIMEOUT } ) ;
123+ await page . click ( selectors . SIMULATE_NETWORK_SELECTOR , { timeout : TIMEOUT } ) ;
124+
125+
126+ console . log ( 'Simulate network' )
127+
128+ await page . waitForSelector ( selectors . SIMULATION_PAGE_SELECTOR , { timeout : TIMEOUT * 2 } ) ;
129+
130+ await page . waitForSelector ( selectors . RASTER_PLOT_SELECTOR , { timeout : TIMEOUT * 10 } )
131+
132+
133+ } ) ;
134+
135+
136+ it ( 'Connections Plot' , async ( ) => {
137+
138+ await page . waitForTimeout ( PAGE_WAIT * 2 ) ;
139+ await page . click ( selectors . CONNECTIONS_PLOT_SELECTOR , { timeout : TIMEOUT } )
140+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
141+ console . log ( 'View Connections Plot ...' )
142+ await page . waitForTimeout ( PAGE_WAIT ) ;
143+
144+ console . log ( '... taking snapshot ...' ) ;
145+ expect ( await page . screenshot ( ) )
146+ . toMatchImageSnapshot ( {
147+ ...SNAPSHOT_OPTIONS ,
148+ customSnapshotIdentifier : 'Connections Plot'
149+ } ) ;
150+
151+ } ) ;
152+
153+ it ( '2D Net Plot' , async ( ) => {
154+
155+ await page . click ( selectors . TWO_D_NET_PLOT_SELECTOR , { timeout : TIMEOUT } )
156+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
157+ console . log ( 'View 2D Net Plot ...' )
158+ await page . waitForTimeout ( PAGE_WAIT * 3 ) ;
159+
160+ console . log ( '... taking snapshot ...' ) ;
161+ expect ( await page . screenshot ( ) )
162+ . toMatchImageSnapshot ( {
163+ ...SNAPSHOT_OPTIONS ,
164+ customSnapshotIdentifier : '2D Net Plot'
165+ } ) ;
166+ } ) ;
167+
168+ it ( 'Cell Traces Plot' , async ( ) => {
169+
170+ await page . click ( selectors . CELL_TRACES_PLOT_SELECTOR , { timeout : TIMEOUT } )
171+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
172+ console . log ( 'View Cell Traces Plot ...' )
173+ await page . waitForTimeout ( PAGE_WAIT ) ;
174+
175+ console . log ( '... taking snapshot ...' ) ;
176+ expect ( await page . screenshot ( ) )
177+ . toMatchImageSnapshot ( {
178+ ...SNAPSHOT_OPTIONS ,
179+ customSnapshotIdentifier : 'Cell Traces Plot'
180+ } ) ;
181+ } ) ;
182+
183+ it ( 'Raster Plot' , async ( ) => {
184+
185+ await page . click ( selectors . RASTER_PLOT_SELECTOR , { timeout : TIMEOUT } )
186+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
187+ console . log ( 'View Raster Plot ...' )
188+ await page . waitForTimeout ( PAGE_WAIT ) ;
189+
190+ console . log ( '... taking snapshot ...' ) ;
191+ expect ( await page . screenshot ( ) )
192+ . toMatchImageSnapshot ( {
193+ ...SNAPSHOT_OPTIONS ,
194+ customSnapshotIdentifier : 'Raster Plot'
195+ } ) ;
196+ } ) ;
197+
198+ it ( 'Spike Hist Plot' , async ( ) => {
199+
200+ await page . click ( selectors . SPIKE_HIST_PLOT_SELECTOR , { timeout : TIMEOUT } )
201+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
202+ console . log ( 'View Spike Hist Plot ...' )
203+ await page . waitForTimeout ( PAGE_WAIT ) ;
204+
205+ console . log ( '... taking snapshot ...' ) ;
206+ expect ( await page . screenshot ( ) )
207+ . toMatchImageSnapshot ( {
208+ ...SNAPSHOT_OPTIONS ,
209+ customSnapshotIdentifier : 'Spike Hist Plot'
210+ } ) ;
211+ } ) ;
212+
213+ it ( 'LFP Time Series Plot' , async ( ) => {
214+
215+ await page . click ( selectors . LFP_TS_PLOT_SELECTOR , { timeout : TIMEOUT } )
216+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
217+ console . log ( 'View LFP Time Series Plot ...' )
218+ await page . waitForTimeout ( PAGE_WAIT ) ;
219+
220+ console . log ( '... taking snapshot ...' ) ;
221+ expect ( await page . screenshot ( ) )
222+ . toMatchImageSnapshot ( {
223+ ...SNAPSHOT_OPTIONS ,
224+ customSnapshotIdentifier : 'LFP Time Series Plot'
225+ } ) ;
226+ } ) ;
227+
228+ it ( 'LFP PSD Plot' , async ( ) => {
229+
230+ await page . click ( selectors . LFP_PSD_PLOT_SELECTOR , { timeout : TIMEOUT } )
231+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
232+ console . log ( 'View LFP PSD Plot ...' )
233+ await page . waitForTimeout ( PAGE_WAIT ) ;
234+
235+ console . log ( '... taking snapshot ...' ) ;
236+ expect ( await page . screenshot ( ) )
237+ . toMatchImageSnapshot ( {
238+ ...SNAPSHOT_OPTIONS ,
239+ customSnapshotIdentifier : 'LFP PSD Plot'
240+ } ) ;
241+ } ) ;
242+
243+ it ( 'LFP Spectrogram Plot' , async ( ) => {
244+
245+ await page . click ( selectors . LFP_SPECTOGRAM_PLOT_SELECTOR , { timeout : TIMEOUT } )
246+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
247+ console . log ( 'View LFP Spectrogram Plot ...' )
248+ await page . waitForTimeout ( PAGE_WAIT * 5 ) ;
249+
250+ console . log ( '... taking snapshot ...' ) ;
251+ expect ( await page . screenshot ( ) )
252+ . toMatchImageSnapshot ( {
253+ ...SNAPSHOT_OPTIONS ,
254+ customSnapshotIdentifier : 'LFP Spectrogram Plot'
255+ } ) ;
256+ } ) ;
257+
258+ it ( 'Granger Plot' , async ( ) => {
259+
260+ await page . click ( selectors . GRANGER_PLOT_SELECTOR , { timeout : TIMEOUT } )
261+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
262+ console . log ( 'View Granger Plot ...' )
263+ await page . waitForTimeout ( PAGE_WAIT ) ;
264+
265+ console . log ( '... taking snapshot ...' ) ;
266+ expect ( await page . screenshot ( ) )
267+ . toMatchImageSnapshot ( {
268+ ...SNAPSHOT_OPTIONS ,
269+ customSnapshotIdentifier : 'Granger Plot'
270+ } ) ;
271+ } ) ;
272+
273+ it ( 'RxD concentration plot' , async ( ) => {
274+
275+ await page . click ( selectors . RXD_CONCENTRATION_PLOT_SELECTOR , { timeout : TIMEOUT } )
276+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
277+ console . log ( 'View RxD concentration plot ...' )
278+ await page . waitForTimeout ( PAGE_WAIT ) ;
279+
280+ console . log ( '... taking snapshot ...' ) ;
281+ expect ( await page . screenshot ( ) )
282+ . toMatchImageSnapshot ( {
283+ ...SNAPSHOT_OPTIONS ,
284+ customSnapshotIdentifier : 'RxD concentration plot'
285+ } ) ;
286+ } ) ;
287+
288+ it ( 'Rate Spectogram Plot' , async ( ) => {
289+
290+ await page . click ( selectors . RATE_SPECTROGRAM_PLOT_SELECTOR , { timeout : TIMEOUT } )
291+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
292+
293+ await page . waitForTimeout ( PAGE_WAIT ) ;
294+
295+ await page . click ( selectors . CONNECTIONS_PLOT_SELECTOR , { timeout : TIMEOUT } )
296+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
297+
298+ await page . waitForTimeout ( PAGE_WAIT ) ;
299+
300+ await page . click ( selectors . RATE_SPECTROGRAM_PLOT_SELECTOR , { timeout : TIMEOUT } )
301+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
302+
303+ console . log ( 'View Rate Spectogram Plot ...' )
304+ await page . waitForTimeout ( PAGE_WAIT ) ;
305+
306+ console . log ( '... taking snapshot ...' ) ;
307+ expect ( await page . screenshot ( ) )
308+ . toMatchImageSnapshot ( {
309+ ...SNAPSHOT_OPTIONS ,
310+ customSnapshotIdentifier : 'Rate Spectogram Plot'
311+ } ) ;
312+ } ) ;
313+ } ) ;
0 commit comments