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_4_'
27+ const PASSWORD = 'testpassword'
28+
29+
30+ //TESTS:
31+
32+ jest . setTimeout ( 300000 ) ;
33+
34+
35+
36+ describe ( 'Tutorial #4 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 #4' )
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_4_SELECTOR , { timeout : TIMEOUT } )
99+ await page . waitForSelector ( selectors . PYR_2_CELL_SELECTOR )
100+ await page . waitForTimeout ( PAGE_WAIT )
101+
102+ await page . waitForSelector ( selectors . MODEL_BUTTON_SELECTOR )
103+ await page . click ( selectors . MODEL_BUTTON_SELECTOR , { timeout : TIMEOUT } ) ;
104+ await page . waitForSelector ( selectors . CREATE_NETWORK_SELECTOR )
105+ await page . click ( selectors . CREATE_NETWORK_SELECTOR , { timeout : TIMEOUT } ) ;
106+
107+ console . log ( 'Create network' )
108+
109+ await page . waitForTimeout ( PAGE_WAIT * 3 )
110+
111+ await page . waitForSelector ( selectors . THREE_D_REP_SELECTOR )
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#4 Network'
119+ } ) ;
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+
212+ it ( 'Rate Spectogram Plot' , async ( ) => {
213+
214+ await page . click ( selectors . RATE_SPECTROGRAM_PLOT_SELECTOR , { timeout : TIMEOUT } )
215+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
216+
217+ await page . waitForTimeout ( PAGE_WAIT ) ;
218+
219+ await page . click ( selectors . CONNECTIONS_PLOT_SELECTOR , { timeout : TIMEOUT } )
220+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
221+
222+ await page . waitForTimeout ( PAGE_WAIT ) ;
223+
224+ await page . click ( selectors . RATE_SPECTROGRAM_PLOT_SELECTOR , { timeout : TIMEOUT } )
225+ await page . waitForSelector ( selectors . CANVAS_SELECTOR , { timeout : TIMEOUT } )
226+
227+ console . log ( 'View Rate Spectogram Plot ...' )
228+ await page . waitForTimeout ( PAGE_WAIT ) ;
229+
230+ console . log ( '... taking snapshot ...' ) ;
231+ expect ( await page . screenshot ( ) )
232+ . toMatchImageSnapshot ( {
233+ ...SNAPSHOT_OPTIONS ,
234+ customSnapshotIdentifier : 'Rate Spectogram Plot'
235+ } ) ;
236+ } ) ;
237+
238+ } ) ;
0 commit comments