@@ -7,20 +7,67 @@ const {Application} = require('spectron');
77const baseDir = path . join ( __dirname , '..' ) ;
88const electronBinary = path . join ( baseDir , 'node_modules' , '.bin' , 'electron' ) ;
99
10+ // utility functions
11+ const sleep = time => new Promise ( r => setTimeout ( r , time ) ) ;
12+
1013describe ( 'Application launch' , function ( ) {
11- this . timeout ( 10000 ) ;
14+ this . timeout ( 30000 ) ;
1215
1316 const app = new Application ( {
1417 path : electronBinary ,
1518 args : [ baseDir ] ,
1619 } ) ;
1720
18- beforeEach ( ( ) => app . start ( ) ) ;
21+ before ( ( ) => app . start ( ) ) ;
1922
20- afterEach ( ( ) => app . stop ( ) ) ;
23+ after ( ( ) => app . stop ( ) ) ;
2124
2225 it ( 'Shows an initial window' , async ( ) => {
26+ await app . client . waitUntilWindowLoaded ( ) ;
2327 const count = await app . client . getWindowCount ( ) ;
2428 assert . equal ( count , 1 ) ;
2529 } ) ;
30+
31+ it ( 'Navigates to settings' , async ( ) => {
32+ app . client . click ( '#settings' ) ;
33+ await app . client . waitUntilWindowLoaded ( ) ;
34+ const crSettings = await app . client . getHTML ( '#crunchyroll' ) ;
35+ assert . ok ( crSettings ) ;
36+ } ) ;
37+
38+ it ( 'Login using crunchyroll' , async ( ) => {
39+ await app . client . click ( '#crLogin' ) ;
40+ // check that login window has been created
41+ const count = await app . client . getWindowCount ( ) ;
42+ assert . equal ( count , 2 ) ;
43+ // set login window as active
44+ await app . client . windowByIndex ( 1 ) ;
45+ await app . client . waitUntilWindowLoaded ( ) ;
46+ // check login form and sleep if we hit bot protection
47+ try {
48+ await app . client . getHTML ( '#login_form' ) ;
49+ } catch ( e ) {
50+ await sleep ( 6000 ) ;
51+ }
52+ // get login form again
53+ const loginFormTwo = await app . client . getHTML ( '#login_form' ) ;
54+ assert . ok ( loginFormTwo ) ;
55+ // fill out login form
56+ await app . client . setValue ( '#login_form_name' , process . env . CR_LOGIN ) ;
57+ await app . client . setValue ( '#login_form_password' , process . env . CR_PASS ) ;
58+ await app . client . click ( 'button=Log In' ) ;
59+ await app . client . waitUntilWindowLoaded ( ) ;
60+ await sleep ( 2000 ) ;
61+ // check that login window has been closed
62+ const finalCount = await app . client . getWindowCount ( ) ;
63+ assert . equal ( finalCount , 1 ) ;
64+ // switch back to main window
65+ await app . client . windowByIndex ( 0 ) ;
66+ // go back to settings page
67+ app . client . click ( '#settings' ) ;
68+ await app . client . waitUntilWindowLoaded ( ) ;
69+ // check that button is now logout
70+ const crLogout = await app . client . getHTML ( '#crLogout' ) ;
71+ assert . ok ( crLogout ) ;
72+ } ) ;
2673} ) ;
0 commit comments