1+ //IMPORTS:
2+ import 'expect-puppeteer' ;
3+ import { toMatchImageSnapshot } from 'jest-image-snapshot'
4+ expect . extend ( { toMatchImageSnapshot } )
5+ const path = require ( 'path' ) ;
6+ var scriptName = path . basename ( __filename , '.js' ) ;
7+ import * as selectors from './selectors'
8+
9+
10+
11+
12+ //PAGE INFO:
13+ const baseURL = process . env . url || 'https://test.netpyne.metacell.us/'
14+ const PAGE_WAIT = 5000 ;
15+ const TIMEOUT = 600000 ;
16+
17+ //SNAPSHOT:
18+ const SNAPSHOT_OPTIONS = {
19+ customSnapshotsDir : `./tests/snapshots/${ scriptName } ` ,
20+ comparisonMethod : 'ssim' ,
21+ customDiffConfig : {
22+ ssim : 'fast' ,
23+ } ,
24+ failureThresholdType : 'percent' ,
25+ failureThreshold : 0.05
26+ } ;
27+
28+
29+ let r = ( Math . random ( ) + 1 ) . toString ( 36 ) . substring ( 2 ) ;
30+
31+
32+ //USERS:
33+ const USERNAME = `TestUser${ r } `
34+ const PASSWORD = 'testpassword'
35+
36+
37+
38+ //TESTS:
39+
40+ jest . setTimeout ( 600000 ) ;
41+
42+ describe ( 'RxD testing' , ( ) => {
43+
44+ beforeAll ( async ( ) => {
45+ await page . goto ( baseURL ) ;
46+ await page . waitForSelector ( selectors . LOGIN_PAGE_SELECTOR ) ;
47+ await page . waitForSelector ( selectors . USERNAME_SELECTOR )
48+ await expect ( page )
49+ . toFill ( selectors . USERNAME_SELECTOR , USERNAME , { timeout : TIMEOUT } ) ;
50+
51+ await page . waitForSelector ( selectors . PASSWORD_SELECTOR )
52+ await expect ( page )
53+ . toFill ( selectors . PASSWORD_SELECTOR , PASSWORD , { timeout : TIMEOUT } ) ;
54+
55+ await page . click ( selectors . LOGIN_BUTTON_SELECTOR )
56+
57+ await page . waitForFunction ( ( ) => {
58+ let el = document . querySelector ( '#loading-spinner' ) ;
59+ return el == null || el . clientHeight === 0 ;
60+ } , { timeout : TIMEOUT } ) ;
61+ } ) ;
62+
63+ it ( 'Open new page' , async ( ) => {
64+
65+ console . log ( 'Opening a new NetPyNE page ...' )
66+
67+ await page . on ( "dialog" , dialog =>
68+ dialog . accept ( ) ) ;
69+
70+ await page . waitForSelector ( selectors . SELECT_CELL_BUTTON_SELECTOR , { timeout : TIMEOUT * 6 , visible : true } )
71+ await page . waitForSelector ( selectors . FILE_TAB_SELECTOR , { timeout : PAGE_WAIT * 3 } )
72+ await page . waitForTimeout ( PAGE_WAIT )
73+ await page . click ( selectors . FILE_TAB_SELECTOR )
74+ await page . waitForSelector ( selectors . NEW_FILE_SELECTOR , { timeout : PAGE_WAIT * 3 } )
75+ await page . waitForTimeout ( PAGE_WAIT )
76+ await page . click ( selectors . NEW_FILE_SELECTOR )
77+ await page . waitForTimeout ( PAGE_WAIT )
78+ await page . waitForSelector ( selectors . CONFIRM_NEW_PAGE_SELECTOR )
79+ await page . click ( selectors . CONFIRM_NEW_PAGE_SELECTOR )
80+ await page . waitForTimeout ( PAGE_WAIT * 3 )
81+
82+ await page . waitForFunction ( ( ) => {
83+ let el = document . querySelector ( '#loading-spinner' ) ;
84+ return el == null || el . clientHeight === 0 ;
85+ } , { timeout : TIMEOUT * 3 } ) ;
86+
87+ await page . waitForSelector ( selectors . SELECT_CELL_BUTTON_SELECTOR , { timeout : TIMEOUT * 10 } )
88+
89+ console . log ( 'Page opened successfully' )
90+
91+ } )
92+
93+ it ( 'Load Tutorial 3b' , async ( ) => {
94+
95+ await page . waitForTimeout ( PAGE_WAIT * 2 )
96+ await page . waitForSelector ( '#selectCellButton' , { timeout : TIMEOUT } )
97+
98+ console . log ( 'Loading Tutorial #3b ...' )
99+
100+ await page . waitForTimeout ( PAGE_WAIT )
101+
102+ await page . click ( selectors . TUTORIALS_BUTTON_SELECTOR , { timeout : TIMEOUT } )
103+
104+ await page . click ( "li[id='Model 3b: Multiscale network (high IP3)']" , { timeout : TIMEOUT } )
105+ await page . waitForSelector ( '#E' )
106+ await page . waitForSelector ( '#I' )
107+ await page . waitForTimeout ( PAGE_WAIT )
108+
109+ console . log ( 'Tutorial loaded' )
110+
111+ } )
112+
113+ it ( 'Create and Simulate Network' , async ( ) => {
114+
115+
116+ await page . waitForSelector ( selectors . MODEL_BUTTON_SELECTOR )
117+ await page . click ( selectors . MODEL_BUTTON_SELECTOR ) ;
118+ await page . waitForSelector ( selectors . CREATE_NETWORK_SELECTOR )
119+ await page . click ( selectors . CREATE_NETWORK_SELECTOR , { timeout : TIMEOUT } ) ;
120+
121+ console . log ( 'Creating network ...' )
122+
123+ await page . waitForTimeout ( PAGE_WAIT * 3 )
124+
125+ await page . waitForSelector ( 'div[title="3D Representation"][aria-disabled="false"]' )
126+
127+ await page . click ( selectors . MODEL_BUTTON_SELECTOR , { timeout : TIMEOUT } ) ;
128+ await page . click ( selectors . SIMULATE_NETWORK_SELECTOR , { timeout : TIMEOUT } ) ;
129+ console . log ( 'Simulating network ...' )
130+
131+ await page . waitForSelector ( 'div[title="Raster plot"][aria-disabled="false"]' , { timeout : TIMEOUT * 3 } )
132+ await page . waitForSelector ( 'div[title="RxD concentration plot"][aria-disabled="false"]' , { timeout : TIMEOUT * 3 } )
133+
134+ await page . waitForTimeout ( PAGE_WAIT )
135+
136+ console . log ( 'Network created and simulated' )
137+
138+ } )
139+
140+ it ( 'Check RxD Plot' , async ( ) => {
141+ console . log ( 'Opening the RxD plot ...' )
142+
143+ await page . waitForSelector ( 'div[title="RxD concentration plot"][aria-disabled="false"]' , { timeout : TIMEOUT * 3 } )
144+ await page . click ( 'div[title="RxD concentration plot"][aria-disabled="false"]' )
145+ await page . waitForSelector ( 'div.flexlayout__tabset' )
146+
147+ console . log ( '... taking snapshot ...' ) ;
148+ await page . waitForTimeout ( PAGE_WAIT ) ;
149+ expect ( await page . screenshot ( ) )
150+ . toMatchImageSnapshot ( {
151+ ...SNAPSHOT_OPTIONS ,
152+ customSnapshotIdentifier : 'RxD Plot'
153+ } ) ;
154+ await page . waitForTimeout ( PAGE_WAIT ) ;
155+ console . log ( 'Plot displayed' )
156+ } )
157+ it ( 'Check LFP Time Series Plot' , async ( ) => {
158+ console . log ( 'Opening the LFP TS plot ...' )
159+
160+ await page . waitForSelector ( 'div[title="LFP Time Series Plot"][aria-disabled="false"]' , { timeout : TIMEOUT * 3 } )
161+ await page . click ( 'div[title="LFP Time Series Plot"][aria-disabled="false"]' )
162+ await page . waitForSelector ( 'div.flexlayout__tabset' )
163+
164+ console . log ( '... taking snapshot ...' ) ;
165+ await page . waitForTimeout ( PAGE_WAIT ) ;
166+ expect ( await page . screenshot ( ) )
167+ . toMatchImageSnapshot ( {
168+ ...SNAPSHOT_OPTIONS ,
169+ customSnapshotIdentifier : 'LFP Time Series Plot Before change'
170+ } ) ;
171+ await page . waitForTimeout ( PAGE_WAIT ) ;
172+ console . log ( 'Plot displayed' )
173+ } )
174+ it ( 'Check LFP PSD Plot' , async ( ) => {
175+ console . log ( 'Opening the LFP PSD plot ...' )
176+
177+ await page . waitForSelector ( 'div[title="LFP PSD Plot"][aria-disabled="false"]' , { timeout : TIMEOUT * 3 } )
178+ await page . click ( 'div[title="LFP PSD Plot"][aria-disabled="false"]' )
179+ await page . waitForSelector ( 'div.flexlayout__tabset' )
180+
181+ console . log ( '... taking snapshot ...' ) ;
182+ await page . waitForTimeout ( PAGE_WAIT ) ;
183+ expect ( await page . screenshot ( ) )
184+ . toMatchImageSnapshot ( {
185+ ...SNAPSHOT_OPTIONS ,
186+ customSnapshotIdentifier : 'LFP PSD Plot Before change'
187+ } ) ;
188+ await page . waitForTimeout ( PAGE_WAIT ) ;
189+ console . log ( 'Plot displayed' )
190+
191+ } )
192+
193+ it ( 'Go back to Edit' , async ( ) => {
194+
195+ console . log ( 'Going back to Edit ...' )
196+ await page . waitForSelector ( '.MuiButtonBase-root.MuiButton-root.MuiButton-contained' )
197+ await page . evaluate ( ( ) => {
198+ [ ...document . querySelectorAll ( '.MuiButtonBase-root.MuiButton-root.MuiButton-contained' ) ] . find ( element => element . innerText === "BACK TO EDIT" ) . click ( ) ;
199+ } ) ;
200+ await page . waitForSelector ( '#E' )
201+ await page . waitForSelector ( '#I' )
202+ console . log ( 'Edit mode displayed' )
203+
204+ } )
205+
206+ it ( 'Open RxD Tab ' , async ( ) => {
207+
208+ console . log ( 'Opening RxD tab ...' )
209+ await page . waitForSelector ( 'div[title="Reaction-Diffusion"]' )
210+ await page . click ( 'div[title="Reaction-Diffusion"]' )
211+
212+ await page . waitForSelector ( '#simple-tabpanel-0' )
213+
214+ //TO CHANGE
215+ const regions_text = await page . $$eval ( '#simple-tabpanel-0' , regions_text => {
216+ return regions_text . map ( regions_text => regions_text . innerText )
217+ } )
218+
219+ expect ( regions_text [ 0 ] ) . toContain ( 'Regions' )
220+
221+ console . log ( 'RxD Tab Opened' )
222+
223+ } )
224+
225+ it ( 'Change RxD Configuration' , async ( ) => {
226+ console . log ( 'Opening RxD config ...' )
227+
228+ await page . waitForSelector ( '#simple-tabpanel-1' )
229+ await page . click ( '#simple-tab-1' )
230+
231+ await page . waitForSelector ( 'button[aria-selected="true"][id = "simple-tab-1"]' )
232+
233+ const no_regions_text = await page . $$eval ( '#simple-tabpanel-1' , no_regions_text => {
234+ return no_regions_text . map ( no_regions_text => no_regions_text . innerText )
235+ } )
236+
237+ expect ( no_regions_text ) . toContain ( 'There are no Species yet.' )
238+ console . log ( 'Species tab opened' )
239+ await page . waitForTimeout ( PAGE_WAIT )
240+
241+ } )
242+
243+ it ( 'Increase IP3 species concentration' , async ( ) => {
244+
245+ console . log ( 'Increasing IP3 concentration ...' )
246+
247+ await page . waitForSelector ( '#ip3' )
248+ await page . click ( '#ip3' )
249+ await page . waitForTimeout ( PAGE_WAIT )
250+ await page . waitForSelector ( '#netParamsrxdParamsspeciesip3regions' )
251+ await page . waitForSelector ( '#netParamsrxdParamsspeciesip3d' )
252+ await page . waitForSelector ( '#netParamsrxdParamsspeciesip3charge' )
253+ await page . waitForSelector ( '#netParamsrxdParamsspeciesip3initial' )
254+ await page . waitForTimeout ( PAGE_WAIT )
255+ await page . click ( '#netParamsrxdParamsspeciesip3initial' )
256+ await page . keyboard . press ( 'Backspace' ) ;
257+ await page . keyboard . press ( 'Backspace' ) ;
258+ await page . keyboard . press ( 'Backspace' ) ;
259+ await page . type ( '#netParamsrxdParamsspeciesip3initial' , '2' )
260+ await page . waitForTimeout ( PAGE_WAIT )
261+ await page . click ( '#netParamsrxdParamsspeciesip3charge' )
262+ await page . waitForTimeout ( PAGE_WAIT )
263+ await page . waitForSelector ( '#netParamsrxdParamsspeciesip3initial[value = "2"]' )
264+
265+ console . log ( 'IP3 increased' )
266+
267+ } )
268+
269+
270+ it ( 'Create and Simulate Network' , async ( ) => {
271+
272+ await page . waitForSelector ( selectors . MODEL_BUTTON_SELECTOR )
273+ await page . click ( selectors . MODEL_BUTTON_SELECTOR ) ;
274+ await page . waitForSelector ( selectors . CREATE_AND_SIMULATE_NETWORK_SELECTOR )
275+ await page . click ( selectors . CREATE_AND_SIMULATE_NETWORK_SELECTOR , { timeout : TIMEOUT } ) ;
276+
277+ console . log ( 'Creating and simulating network ...' )
278+
279+ await page . waitForTimeout ( PAGE_WAIT * 3 )
280+
281+ await page . waitForSelector ( 'div[title="Raster plot"][aria-disabled="false"]' , { timeout : TIMEOUT * 3 } )
282+ await page . waitForSelector ( 'div[title="RxD concentration plot"][aria-disabled="false"]' , { timeout : TIMEOUT * 3 } )
283+
284+ await page . waitForTimeout ( PAGE_WAIT )
285+
286+ console . log ( 'Network created and simulated' )
287+ } )
288+
289+ it ( 'Check RxD Plot' , async ( ) => {
290+
291+ console . log ( 'Opening the RxD plot ...' )
292+
293+ await page . waitForSelector ( 'div[title="RxD concentration plot"][aria-disabled="false"]' , { timeout : TIMEOUT * 3 } )
294+ await page . click ( 'div[title="RxD concentration plot"][aria-disabled="false"]' )
295+ await page . waitForSelector ( 'div.flexlayout__tabset' )
296+
297+ console . log ( '... taking snapshot ...' ) ;
298+ await page . waitForTimeout ( PAGE_WAIT ) ;
299+ expect ( await page . screenshot ( ) )
300+ . toMatchImageSnapshot ( {
301+ ...SNAPSHOT_OPTIONS ,
302+ customSnapshotIdentifier : 'RxD Plot'
303+ } ) ;
304+ await page . waitForTimeout ( PAGE_WAIT ) ;
305+ console . log ( 'Plot displayed' )
306+ } )
307+ it ( 'Check LFP Time Series Plot' , async ( ) => {
308+
309+ console . log ( 'Opening the LFP TS plot ...' )
310+
311+ await page . waitForSelector ( 'div[title="LFP Time Series Plot"][aria-disabled="false"]' , { timeout : TIMEOUT * 3 } )
312+ await page . click ( 'div[title="LFP Time Series Plot"][aria-disabled="false"]' )
313+ await page . waitForSelector ( 'div.flexlayout__tabset' )
314+
315+ console . log ( '... taking snapshot ...' ) ;
316+ await page . waitForTimeout ( PAGE_WAIT ) ;
317+ expect ( await page . screenshot ( ) )
318+ . toMatchImageSnapshot ( {
319+ ...SNAPSHOT_OPTIONS ,
320+ customSnapshotIdentifier : 'LFP Time Series Plot After change'
321+ } ) ;
322+ await page . waitForTimeout ( PAGE_WAIT ) ;
323+ console . log ( 'Plot displayed' )
324+ } )
325+ it ( 'Check LFP PSD Plot' , async ( ) => {
326+
327+ console . log ( 'Opening the LFP PSD plot ...' )
328+
329+ await page . waitForSelector ( 'div[title="LFP PSD Plot"][aria-disabled="false"]' , { timeout : TIMEOUT * 3 } )
330+ await page . click ( 'div[title="LFP PSD Plot"][aria-disabled="false"]' )
331+ await page . waitForSelector ( 'div.flexlayout__tabset' )
332+
333+ console . log ( '... taking snapshot ...' ) ;
334+ await page . waitForTimeout ( PAGE_WAIT ) ;
335+ expect ( await page . screenshot ( ) )
336+ . toMatchImageSnapshot ( {
337+ ...SNAPSHOT_OPTIONS ,
338+ customSnapshotIdentifier : 'LFP PSD Plot After change'
339+ } ) ;
340+ await page . waitForTimeout ( PAGE_WAIT ) ;
341+ console . log ( 'Plot displayed' )
342+
343+ } )
344+
345+
346+ } )
0 commit comments