Skip to content

Commit 6d20a06

Browse files
committed
Implement crunchyroll login test using spectron
1 parent c9c1182 commit 6d20a06

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

src/api/crunchyroll/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class Crunchyroll {
346346
const loggedIn = this.authCookies !== null;
347347

348348
return (
349-
<div key="crunchyroll" className="card">
349+
<div id="crunchyroll" key="crunchyroll" className="card">
350350
<header className="card-header">
351351
<p className="card-header-title">
352352
Crunchyroll
@@ -357,10 +357,10 @@ class Crunchyroll {
357357
</div>
358358
<footer className="card-footer">
359359
{loggedIn
360-
? <a className="card-footer-item" href="#crlogout" onClick={() => this.logout()}>
360+
? <a id="crLogout" className="card-footer-item" href="#crlogout" onClick={() => this.logout()}>
361361
Logout
362362
</a>
363-
: <a className="card-footer-item" href="#crlogin" onClick={() => this.auth()}>
363+
: <a id="crLogin" className="card-footer-item" href="#crlogin" onClick={() => this.auth()}>
364364
Login
365365
</a>}
366366
</footer>

src/components/navbar/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default () => (
2525
</div>
2626
<div className="nav-right nav-menu">
2727
<div className="nav-item">
28-
<Link to="/settings" className="button">
28+
<Link id="settings" to="/settings" className="button">
2929
<span className="icon">
3030
<i className="fa fa-cog" />
3131
</span>

test/index.js

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,67 @@ const {Application} = require('spectron');
77
const baseDir = path.join(__dirname, '..');
88
const electronBinary = path.join(baseDir, 'node_modules', '.bin', 'electron');
99

10+
// utility functions
11+
const sleep = time => new Promise(r => setTimeout(r, time));
12+
1013
describe('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

Comments
 (0)