-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.test.js
101 lines (80 loc) · 3 KB
/
App.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import test from "ava";
import { startBackgroundProcess } from "./util";
const dappeteer = require("dappeteer");
import puppeteer from "puppeteer";
test.beforeEach(async t => {
const browser = await dappeteer.launch(puppeteer, {
headless: false,
args: ["--start-maximized", "--no-sandbox", "--disable-setuid-sandbox","--disable-web-security"]
});
const page = await browser.newPage();
const metamask = await dappeteer.getMetamask(browser);
const { stdout, exit } = await startBackgroundProcess({
cmd: "aragon",
args: ["run"],
execaOpts: {
cwd: `./`
},
readyOutput: "Opening http://localhost:3000/#/"
});
// hack so the wrapper has time to start
await new Promise(resolve => setTimeout(resolve, 60 * 1000)); // TODO move to utils
// finding the DAO address
const daoAddress = stdout.match(/DAO address: (0x[a-fA-F0-9]{40})/)[1];
await metamask.switchNetwork("localhost");
await metamask.importPK('a8a54b2d8197bc0b19bb8a084031be71835580a01e70a45a13babd16c9bc1563')
await metamask.switchAccount(2);
t.context = {
browser: browser,
page: page,
daoAddress: daoAddress,
metamask: metamask,
exit: exit
};
});
test(
"should run an aragon app successfully",
async t => {
let frameH1;
try {
const url = `http://localhost:3000/#/${t.context.daoAddress}`;
await t.context.page.goto(url);
const text = "Counter";
await t.context.page.reload();
await t.context.page.bringToFront();
await t.context.page.waitForFunction(
text => document.querySelector("body").innerText.includes(text),
{},
text
);
const CounterAppSpan = await t.context.page.$x("//span[contains(text(), 'Counter')]");
if (CounterAppSpan.length > 0) {
await CounterAppSpan[0].click();
await new Promise(resolve => setTimeout(resolve, 3 * 1000))
const frame = await t.context.page.frames().find(f => f.name() === 'AppIFrame');
await frame.waitForSelector('#IncrementButton');
const incrementButton = await frame.$('#IncrementButton');
await incrementButton.click();
await new Promise(resolve => setTimeout(resolve, 3 * 1000))
const confirmTransaction = await t.context.page.$x("//button[contains(text(), 'Create transaction')]");
if (confirmTransaction.length > 0) {
await confirmTransaction[0].click();
await t.context.metamask.confirmTransaction();
await new Promise(resolve => setTimeout(resolve, 3 * 1000))
frameH1 = await frame.evaluate(el => el.innerHTML, await frame.$('h1'));
await t.context.page.bringToFront();
await new Promise(resolve => setTimeout(resolve, 3 * 1000))
} else {
throw new Error("confirmTransaction not found");
}
} else {
throw new Error("CounterApp not found");
}
} catch (e) {
console.log(e);
}
t.is(frameH1,'Count: 1')
// cleanup
await t.context.exit();
}
);