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