Skip to content

Commit 668e119

Browse files
LucasXu0appflowy
andauthored
chore: config tauri web driver test (#1947)
* chore: setup tauri test * chore: update test * chore: update test * chore: update test * chore: update test * refactor: test folder location * chore: remove deps * ci: fix build --------- Co-authored-by: appflowy <[email protected]> Co-authored-by: nathan <[email protected]>
1 parent 688d55e commit 668e119

File tree

10 files changed

+133
-82
lines changed

10 files changed

+133
-82
lines changed

frontend/appflowy_tauri/jest.config.cjs

Lines changed: 0 additions & 8 deletions
This file was deleted.

frontend/appflowy_tauri/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"test:errors": "eslint --quiet --ext .js,.ts,.tsx .",
1313
"test:prettier": "yarn prettier --list-different src",
1414
"tauri:clean": "cargo make --cwd .. tauri_clean",
15-
"tauri:dev": "tauri dev",
16-
"test": "jest"
15+
"tauri:dev": "tauri dev"
1716
},
1817
"dependencies": {
1918
"@emotion/react": "^11.10.6",
@@ -26,7 +25,7 @@
2625
"i18next": "^22.4.10",
2726
"i18next-browser-languagedetector": "^7.0.1",
2827
"is-hotkey": "^0.2.0",
29-
"jest": "^29.4.3",
28+
"jest": "^29.5.0",
3029
"nanoid": "^4.0.0",
3130
"react": "^18.2.0",
3231
"react-dom": "^18.2.0",
@@ -46,8 +45,6 @@
4645
"@tauri-apps/cli": "^1.2.2",
4746
"@types/google-protobuf": "^3.15.6",
4847
"@types/is-hotkey": "^0.1.7",
49-
"@types/jest": "^29.4.0",
50-
"@types/mocha": "^10.0.1",
5148
"@types/node": "^18.7.10",
5249
"@types/react": "^18.0.15",
5350
"@types/react-dom": "^18.0.6",
@@ -62,7 +59,6 @@
6259
"prettier": "2.8.4",
6360
"prettier-plugin-tailwindcss": "^0.2.2",
6461
"tailwindcss": "^3.2.7",
65-
"ts-jest": "^29.0.5",
6662
"typescript": "^4.6.4",
6763
"vite": "^4.0.0"
6864
}

frontend/appflowy_tauri/src/appflowy_app/components/auth/GetStarted/GetStarted.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const GetStarted = () => {
99
<>
1010
<form onSubmit={(e) => e.preventDefault()} method='POST'>
1111
<div className='relative flex h-screen w-screen flex-col items-center justify-center gap-12 text-center'>
12-
<div className='flex h-10 w-10 justify-center'>
12+
<div className='flex h-10 w-10 justify-center' id='appflowy'>
1313
<AppflowyLogo />
1414
</div>
1515

@@ -19,8 +19,8 @@ export const GetStarted = () => {
1919
</span>
2020
</div>
2121

22-
<div className='flex w-full max-w-[340px] flex-col gap-6 '>
23-
<Button size={'primary'} onClick={() => onAutoSignInClick()}>
22+
<div id='Get-Started' className='flex w-full max-w-[340px] flex-col gap-6 ' aria-label='Get-Started' >
23+
<Button size={'primary'} onClick={() => onAutoSignInClick()} >
2424
{t('signUp.getStartedText')}
2525
</Button>
2626
</div>

frontend/appflowy_tauri/src/appflowy_app/components/layout/HeaderPanel/PageOptions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const PageOptions = () => {
1313
Share
1414
</Button>
1515

16-
<button className={'relative h-8 w-8'} onClick={onOptionsClick}>
16+
<button id='option-button' className={'relative h-8 w-8'} onClick={onOptionsClick} >
1717
<Details2Svg></Details2Svg>
1818
</button>
1919
</div>
Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
1-
import { AuthBackendService, UserBackendService } from '../appflowy_app/stores/effects/user/user_bd_svc';
2-
import { randomFillSync } from 'crypto';
3-
import { nanoid } from '@reduxjs/toolkit';
1+
export {}
2+
// import { AuthBackendService, UserBackendService } from '../appflowy_app/stores/effects/user/user_bd_svc';
3+
// import { randomFillSync } from 'crypto';
4+
// import { nanoid } from '@reduxjs/toolkit';
45

5-
beforeAll(() => {
6-
//@ts-ignore
7-
window.crypto = {
8-
// @ts-ignore
9-
getRandomValues: function (buffer) {
10-
// @ts-ignore
11-
return randomFillSync(buffer);
12-
},
13-
};
14-
});
6+
// beforeAll(() => {
7+
// //@ts-ignore
8+
// window.crypto = {
9+
// // @ts-ignore
10+
// getRandomValues: function (buffer) {
11+
// // @ts-ignore
12+
// return randomFillSync(buffer);
13+
// },
14+
// };
15+
// });
1516

16-
describe('User backend service', () => {
17-
it('sign up', async () => {
18-
const service = new AuthBackendService();
19-
const result = await service.autoSignUp();
20-
expect(result.ok).toBeTruthy;
21-
});
17+
// describe('User backend service', () => {
18+
// it('sign up', async () => {
19+
// const service = new AuthBackendService();
20+
// const result = await service.autoSignUp();
21+
// expect(result.ok).toBeTruthy;
22+
// });
2223

23-
it('sign in', async () => {
24-
const authService = new AuthBackendService();
25-
const email = nanoid(4) + '@appflowy.io';
26-
const password = nanoid(10);
27-
const signUpResult = await authService.signUp({ name: 'nathan', email: email, password: password });
28-
expect(signUpResult.ok).toBeTruthy;
24+
// it('sign in', async () => {
25+
// const authService = new AuthBackendService();
26+
// const email = nanoid(4) + '@appflowy.io';
27+
// const password = nanoid(10);
28+
// const signUpResult = await authService.signUp({ name: 'nathan', email: email, password: password });
29+
// expect(signUpResult.ok).toBeTruthy;
2930

30-
const signInResult = await authService.signIn({ email: email, password: password });
31-
expect(signInResult.ok).toBeTruthy;
32-
});
31+
// const signInResult = await authService.signIn({ email: email, password: password });
32+
// expect(signInResult.ok).toBeTruthy;
33+
// });
3334

34-
it('get user profile', async () => {
35-
const service = new AuthBackendService();
36-
const result = await service.autoSignUp();
37-
const userProfile = result.unwrap();
35+
// it('get user profile', async () => {
36+
// const service = new AuthBackendService();
37+
// const result = await service.autoSignUp();
38+
// const userProfile = result.unwrap();
3839

39-
const userService = new UserBackendService(userProfile.id);
40-
expect((await userService.getUserProfile()).unwrap()).toBe(userProfile);
41-
});
42-
});
40+
// const userService = new UserBackendService(userProfile.id);
41+
// expect((await userService.getUserProfile()).unwrap()).toBe(userProfile);
42+
// });
43+
// });

frontend/appflowy_tauri/test/specs/example.e2e.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

frontend/appflowy_tauri/test/tsconfig.json

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "selenium",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"test": "mocha"
7+
},
8+
"dependencies": {
9+
"chai": "^4.3.4",
10+
"mocha": "^9.0.3",
11+
"selenium-webdriver": "^4.0.0-beta.4"
12+
}
13+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const os = require("os");
2+
const path = require("path");
3+
const { expect } = require("chai");
4+
const { spawn, spawnSync } = require("child_process");
5+
const { Builder, By, Capabilities, until } = require("selenium-webdriver");
6+
const { elementIsVisible, elementLocated } = require("selenium-webdriver/lib/until.js");
7+
8+
// create the path to the expected application binary
9+
const application = path.resolve(
10+
__dirname,
11+
"..",
12+
"..",
13+
"..",
14+
"src-tauri",
15+
"target",
16+
"release",
17+
"appflowy_tauri"
18+
);
19+
20+
// keep track of the webdriver instance we create
21+
let driver;
22+
23+
// keep track of the tauri-driver process we start
24+
let tauriDriver;
25+
26+
before(async function() {
27+
// set timeout to 2 minutes to allow the program to build if it needs to
28+
this.timeout(120000);
29+
30+
// ensure the program has been built
31+
spawnSync("cargo", ["build", "--release"]);
32+
33+
// start tauri-driver
34+
tauriDriver = spawn(
35+
path.resolve(os.homedir(), ".cargo", "bin", "tauri-driver"),
36+
[],
37+
{ stdio: [null, process.stdout, process.stderr] }
38+
);
39+
40+
const capabilities = new Capabilities();
41+
capabilities.set("tauri:options", { application });
42+
capabilities.setBrowserName("wry");
43+
44+
// start the webdriver client
45+
driver = await new Builder()
46+
.withCapabilities(capabilities)
47+
.usingServer("http://localhost:4444/")
48+
.build();
49+
});
50+
51+
after(async function() {
52+
// stop the webdriver session
53+
await driver.quit();
54+
55+
// kill the tauri-driver process
56+
tauriDriver.kill();
57+
});
58+
59+
describe("AppFlowy Unit Test", () => {
60+
it("should find get started button", async () => {
61+
// should sign out if already sign in
62+
const getStartedButton = await driver.wait(until.elementLocated(By.xpath("//*[@id=\"root\"]/form/div/div[3]")));
63+
getStartedButton.click();
64+
});
65+
66+
it("should get sign out button", async (done) => {
67+
// const optionButton = await driver.wait(until.elementLocated(By.css('*[test-id=option-button]')));
68+
// const optionButton = await driver.wait(until.elementLocated(By.id('option-button')));
69+
// const optionButton = await driver.wait(until.elementLocated(By.css('[aria-label=option]')));
70+
71+
// Currently, only the find className is work
72+
const optionButton = await driver.wait(until.elementLocated(By.className("relative h-8 w-8")));
73+
optionButton.click();
74+
await new Promise((resolve) => setTimeout(resolve, 4000));
75+
});
76+
});

frontend/scripts/makefile/protobuf.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ script_runner = "@shell"
1313

1414
[tasks.install_tauri_protobuf.linux]
1515
script = """
16-
npm install -g protoc-gen-ts
16+
sudo npm install -g protoc-gen-ts
1717
"""
1818
script_runner = "@shell"
1919

0 commit comments

Comments
 (0)