Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit e51b876

Browse files
Add e2e tests (#65)
* update playwright tests * Add repository navigation test, add settings test * fix onboarding flow * Update playwright config * Update code tests * Fix code search tests * Update tests * Update tests config Co-authored-by: anastasiia <anastasiya1155@gmail.com>
1 parent 1ed3593 commit e51b876

13 files changed

+599
-29
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"devDependencies": {
1313
"@playwright/test": "^1.28.1",
14+
"@types/node": "^18.11.18",
1415
"@typescript-eslint/parser": "^5.42.1",
1516
"dotenv": "^16.0.3",
1617
"eslint": "~8.22.0",

playwright.config.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// @ts-check
22
const { devices } = require('@playwright/test');
33
const dotenv = require('dotenv');
4-
dotenv.config({ path: '.tests.env' });
5-
4+
dotenv.config({ path: './tests/.env' });
65
/**
76
* Read environment variables from file.
87
* https://github.com/motdotla/dotenv
98
*/
10-
// require('dotenv').config();
119

1210
/**
1311
* @see https://playwright.dev/docs/test-configuration
@@ -51,11 +49,17 @@ const config = {
5149

5250
/* Configure projects for major browsers */
5351
projects: [
52+
{
53+
name: 'msedge',
54+
use: { ...devices['Desktop Edge'] },
55+
},
5456
{
5557
name: 'webkit',
56-
use: {
57-
...devices['Desktop Safari'],
58-
},
58+
use: { ...devices['Desktop Safari'] },
59+
},
60+
{
61+
name: 'firefox',
62+
use: { ...devices['Desktop Firefox'] },
5963
},
6064
],
6165

@@ -64,7 +68,7 @@ const config = {
6468

6569
/* Run your local dev server before starting the tests */
6670
// webServer: {
67-
// command: 'npm run start',
71+
// command: '',
6872
// port: 3000,
6973
// },
7074
};

pnpm-lock.yaml

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/.example.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SCAN_FOLDER=/Users/...
2+
GITHUB_USER=test
3+
GITHUB_PASSWORD=123

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ test.describe.serial('Main test group', () => {
1313
const context = await browser.newContext();
1414
page = await context.newPage();
1515
await page.goto(
16-
'http://localhost:5173/?chosen_scan_folder=${process.env.SCAN_FOLDER}'
16+
'http://localhost:5173/?chosen_scan_folder=${process.env.SCAN_FOLDER}',
1717
);
1818
});
1919

2020
const repoNames = [];
2121

2222
test.afterAll(async ({ browser }) => {
23-
browser.close;
23+
await browser.close();
2424
});
2525

2626
test('Local and GitHub onboarding', async () => {
2727
await page.goto(
28-
`http://localhost:5173/?chosen_scan_folder=${process.env.SCAN_FOLDER}`
28+
`http://localhost:5173/?chosen_scan_folder=${process.env.SCAN_FOLDER}`,
2929
);
30+
await page.getByRole('button', { name: "Don't share" }).click();
3031
await page.getByPlaceholder('First name').click();
3132
await page.getByPlaceholder('First name').fill('Steve');
3233
await page.getByPlaceholder('First name').press('Tab');
@@ -111,24 +112,23 @@ test.describe.serial('Main test group', () => {
111112
}
112113

113114
await page.getByRole('button', { name: 'Sync repositories' }).click();
114-
await page.getByRole('button', { name: 'Share with bloop' }).click();
115115

116116
await Promise.all(
117117
repoNames.map((repoName) =>
118118
page.waitForSelector(`p:has-text("${repoName}")`, {
119119
state: 'attached',
120120
timeout: 60 * 1000,
121-
})
122-
)
121+
}),
122+
),
123123
);
124124

125125
await Promise.all(
126126
repoNames.map((repoName, i) =>
127127
page
128128
.locator('.bg-green-500')
129129
.nth(i)
130-
.waitFor({ timeout: 60 * 1000 })
131-
)
130+
.waitFor({ timeout: 60 * 1000 }),
131+
),
132132
);
133133

134134
await page.evaluate(() => {
@@ -138,7 +138,7 @@ test.describe.serial('Main test group', () => {
138138
localStorage.key(i) +
139139
'=[' +
140140
localStorage.getItem(localStorage.key(i)) +
141-
']'
141+
']',
142142
);
143143
}
144144
});
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const REPOS_TO_SYNC = 3;
44

55
test('test', async ({ page }) => {
66
await page.goto(`http://localhost:5173`);
7+
await page.getByRole('button', { name: "Don't share" }).click();
78
await page.getByRole('button', { name: 'Skip this step' }).click();
89
await page.getByRole('button', { name: 'Skip this step' }).click();
910
await expect(page.locator('.subhead-l > span')).toBeVisible();
@@ -56,23 +57,22 @@ test('test', async ({ page }) => {
5657
}
5758

5859
await page.getByRole('button', { name: 'Sync repositories' }).click();
59-
await page.getByRole('button', { name: 'Share with bloop' }).click();
6060

6161
await Promise.all(
6262
repoNames.map((repoName) =>
6363
page.waitForSelector(`p:has-text("${repoName}")`, {
6464
state: 'attached',
6565
timeout: 60 * 1000,
66-
})
67-
)
66+
}),
67+
),
6868
);
6969

7070
await Promise.all(
7171
repoNames.map((repoName, i) =>
7272
page
7373
.locator('.bg-green-500')
7474
.nth(i)
75-
.waitFor({ timeout: 60 * 1000 })
76-
)
75+
.waitFor({ timeout: 60 * 1000 }),
76+
),
7777
);
7878
});
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { test, expect } from '@playwright/test';
22

33
const REPOS_TO_SYNC = 3;
44

5-
test('test', async ({ page }) => {
5+
test.skip('test', async ({ page }) => {
66
if (!process.env.SCAN_FOLDER) {
77
throw new Error('SCAN_FOLDER env not set');
88
}
99

1010
await page.goto(
11-
`http://localhost:5173/?chosen_scan_folder=${process.env.SCAN_FOLDER}`
11+
`http://localhost:5173/?chosen_scan_folder=${process.env.SCAN_FOLDER}`,
1212
);
13+
await page.getByRole('button', { name: "Don't share" }).click();
1314
await page.getByPlaceholder('First name').click();
1415
await page.getByPlaceholder('First name').fill('Steve');
1516
await page.getByPlaceholder('First name').press('Tab');
@@ -45,23 +46,22 @@ test('test', async ({ page }) => {
4546

4647
await page.getByRole('button', { name: 'Sync repositories' }).click();
4748
await page.getByRole('button', { name: 'Setup later' }).click();
48-
await page.getByRole('button', { name: 'Share with bloop' }).click();
4949

5050
await Promise.all(
5151
repoNames.map((repoName) =>
5252
page.waitForSelector(`p:has-text("${repoName}")`, {
5353
state: 'attached',
5454
timeout: 60 * 1000,
55-
})
56-
)
55+
}),
56+
),
5757
);
5858

5959
await Promise.all(
6060
repoNames.map((repoName, i) =>
6161
page
6262
.locator('.bg-green-500')
6363
.nth(i)
64-
.waitFor({ timeout: 60 * 1000 })
65-
)
64+
.waitFor({ timeout: 60 * 1000 }),
65+
),
6666
);
6767
});

tests/onboarding.spec.ts

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
const REPOS_TO_SYNC = 1;
4+
5+
test.describe.serial('OnBoarding', () => {
6+
let page; // Share page context between tests
7+
8+
test.beforeAll(async ({ browser }) => {
9+
const context = await browser.newContext();
10+
page = await context.newPage();
11+
await page.goto(
12+
`http://localhost:5173/?chosen_scan_folder=${process.env.SCAN_FOLDER}`,
13+
);
14+
});
15+
16+
test.afterAll(async ({ browser }) => {
17+
await browser.close();
18+
});
19+
20+
test('Local and GitHub', async () => {
21+
const repoNames = [];
22+
23+
await page.getByRole('button', { name: "Don't share" }).click();
24+
await page.getByPlaceholder('First name').click();
25+
await page.getByPlaceholder('First name').fill('Steve');
26+
await page.getByPlaceholder('First name').press('Tab');
27+
await page.getByRole('button').first().press('Tab');
28+
await page.getByPlaceholder('Last name').fill('Wozniak');
29+
await page.getByPlaceholder('Email address').click();
30+
await page.getByPlaceholder('Email address').fill('steve@bloop.ai');
31+
await page.locator('form').getByRole('button').nth(2).click();
32+
await page.getByPlaceholder('Email address').fill('steve.w@bloop.ai');
33+
await page.getByRole('button', { name: 'Submit' }).click();
34+
35+
// Local
36+
37+
await page.getByRole('button', { name: 'Choose a folder' }).click();
38+
await page.getByRole('button', { name: 'Sync selected repos' }).click();
39+
40+
await page.waitForSelector('.bg-skeleton', {
41+
state: 'detached',
42+
timeout: 60 * 1000,
43+
});
44+
45+
for (let i = 1; i <= REPOS_TO_SYNC; i++) {
46+
const repo = page.locator(`ul > :nth-match(li, ${i})`);
47+
repoNames.push(await repo.locator('span').innerText());
48+
await repo.click();
49+
}
50+
51+
await page.getByRole('button', { name: 'Sync repositories' }).click();
52+
53+
// GitHub login
54+
55+
await expect(page.locator('.subhead-l > span')).toBeVisible();
56+
await page.getByRole('button').first().click();
57+
const [page1] = await Promise.all([
58+
page.waitForEvent('popup'),
59+
page.getByRole('button', { name: 'Connect GitHub' }).click(),
60+
]);
61+
await page1
62+
.getByLabel('Username or email address')
63+
.fill(process.env.GITHUB_USER);
64+
await page1.getByLabel('Password').click();
65+
await page1.getByLabel('Password').fill(process.env.GITHUB_PASSWORD);
66+
await page1.getByRole('button', { name: 'Sign in' }).click();
67+
68+
const githubAuthCode = await page
69+
.locator('.subhead-l > span')
70+
.first()
71+
.innerText();
72+
73+
for (var i = 0; i < githubAuthCode.length; i++) {
74+
if (i === 4) continue;
75+
await page1.locator(`#user-code-${i}`).fill(githubAuthCode[i]);
76+
}
77+
78+
await page1.getByRole('button', { name: 'Continue' }).click();
79+
await page1.getByRole('button', { name: 'Authorize BloopAI' }).click();
80+
await page1.close();
81+
82+
await page.getByRole('button', { name: 'Sync selected repos' }).click();
83+
84+
await page.waitForSelector('.bg-skeleton', {
85+
state: 'detached',
86+
timeout: 60 * 1000,
87+
});
88+
89+
for (let i = 1; i <= REPOS_TO_SYNC; i++) {
90+
const repo = page.locator(`ul > :nth-match(li, ${i})`);
91+
repoNames.push(await repo.locator('span').innerText());
92+
await repo.click();
93+
}
94+
95+
await page.getByRole('button', { name: 'Sync repositories' }).click();
96+
97+
await Promise.all(
98+
repoNames.map((repoName) =>
99+
page.waitForSelector(`p:has-text("${repoName}")`, {
100+
state: 'attached',
101+
timeout: 60 * 1000,
102+
}),
103+
),
104+
);
105+
106+
await Promise.all(
107+
repoNames.map((repoName, i) =>
108+
page
109+
.locator('.bg-green-500')
110+
.nth(i)
111+
.waitFor({ timeout: 60 * 1000 }),
112+
),
113+
);
114+
115+
await page.evaluate(() => {
116+
for (i = 0; i < localStorage.length; i++) {
117+
console.log(
118+
localStorage.key(i) +
119+
'=[' +
120+
localStorage.getItem(localStorage.key(i)) +
121+
']',
122+
);
123+
}
124+
});
125+
});
126+
});

0 commit comments

Comments
 (0)