Skip to content

Commit 218961a

Browse files
committed
Playwright setup.
Basic tests - visibility of custom scroll. position of scroll handle on scrolling
1 parent a3bb933 commit 218961a

12 files changed

+231
-2
lines changed

.github/workflows/playwright.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: 18
16+
- name: Install dependencies
17+
run: npm install -g yarn && yarn
18+
- name: Install Playwright Browsers
19+
run: yarn playwright install --with-deps
20+
- name: Run Playwright tests
21+
run: yarn playwright test
22+
- uses: actions/upload-artifact@v3
23+
if: always()
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
/test-results/
26+
/playwright-report/
27+
/blob-report/
28+
/playwright/.cache/

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"build": "tsc && vite build",
2424
"prepare": "npm run build",
2525
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
26-
"preview": "vite preview"
26+
"preview": "vite preview",
27+
"test": "playwright test",
28+
"test:ui": "playwright test --ui --project firefox"
2729
},
2830
"dependencies": {
2931
"@types/lodash": "^4.14.202",
@@ -33,6 +35,7 @@
3335
"styled-components": "^6.1.8"
3436
},
3537
"devDependencies": {
38+
"@playwright/test": "^1.41.1",
3639
"@types/node": "^20.11.10",
3740
"@types/react": "^18.2.43",
3841
"@types/react-dom": "^18.2.17",

playwright.config.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
import path from "path";
3+
import { fileURLToPath } from "url";
4+
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
6+
7+
/**
8+
* Read environment variables from file.
9+
* https://github.com/motdotla/dotenv
10+
*/
11+
// require('dotenv').config();
12+
13+
/**
14+
* See https://playwright.dev/docs/test-configuration.
15+
*/
16+
export default defineConfig({
17+
testDir: "./tests",
18+
/* Run tests in files in parallel */
19+
fullyParallel: true,
20+
/* Fail the build on CI if you accidentally left test.only in the source code. */
21+
forbidOnly: !!process.env.CI,
22+
/* Retry on CI only */
23+
retries: process.env.CI ? 2 : 0,
24+
/* Opt out of parallel tests on CI. */
25+
workers: process.env.CI ? 1 : undefined,
26+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
27+
reporter: "html",
28+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
29+
use: {
30+
/* Base URL to use in actions like `await page.goto('/')`. */
31+
// baseURL: 'http://127.0.0.1:3000',
32+
33+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
34+
trace: "on-first-retry",
35+
},
36+
37+
/* Configure projects for major browsers */
38+
projects: [
39+
{
40+
name: "chromium",
41+
use: { ...devices["Desktop Chrome"] },
42+
},
43+
44+
{
45+
name: "firefox",
46+
use: { ...devices["Desktop Firefox"] },
47+
},
48+
49+
{
50+
name: "webkit",
51+
use: { ...devices["Desktop Safari"] },
52+
},
53+
54+
/* Test against mobile viewports. */
55+
// {
56+
// name: 'Mobile Chrome',
57+
// use: { ...devices['Pixel 5'] },
58+
// },
59+
// {
60+
// name: 'Mobile Safari',
61+
// use: { ...devices['iPhone 12'] },
62+
// },
63+
64+
/* Test against branded browsers. */
65+
// {
66+
// name: 'Microsoft Edge',
67+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
68+
// },
69+
// {
70+
// name: 'Google Chrome',
71+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
72+
// },
73+
],
74+
75+
globalSetup: path.resolve(__dirname, "startServer.ts"),
76+
globalTeardown: path.resolve(__dirname, "stopServer.ts"),
77+
78+
/* Run your local dev server before starting the tests */
79+
// webServer: {
80+
// command: 'npm run start',
81+
// url: 'http://127.0.0.1:3000',
82+
// reuseExistingServer: !process.env.CI,
83+
// },
84+
});

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const App = () => {
1313
it doesn't take up any space. This enables the same results regardless
1414
of browser or operating system.
1515
</div>
16-
<div className="example-wrapper">
16+
<div data-testid="first-example" className="example-wrapper">
1717
<DemoComp demoType="compare-with-native" />
1818
</div>
1919
<div id="with-crazy-design">

src/customScroll.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ export class CustomScroll extends Component<
541541
ref={this.customScrollRef}
542542
>
543543
<div
544+
data-testid="outer-container"
544545
className="rcs-outer-container"
545546
style={this.getOuterContainerStyle()}
546547
onMouseDown={this.onMouseDown}
@@ -550,11 +551,13 @@ export class CustomScroll extends Component<
550551
{this.hasScroll ? (
551552
<div className="rcs-positioning">
552553
<CustomScrollbar
554+
data-testid="custom-scrollbar"
553555
ref={this.customScrollbarRef}
554556
className={`rcs-custom-scrollbar ${this.props.rtl ? "rcs-custom-scrollbar-rtl" : ""}`}
555557
key="scrollbar"
556558
>
557559
<div
560+
data-testid="custom-scroll-handle"
558561
ref={this.scrollHandleRef}
559562
className="rcs-custom-scroll-handle"
560563
style={scrollHandleStyle}
@@ -565,6 +568,7 @@ export class CustomScroll extends Component<
565568
</div>
566569
) : null}
567570
<div
571+
data-testid="inner-container"
568572
ref={this.innerContainerRef}
569573
className={this.getInnerContainerClasses()}
570574
style={scrollStyles.innerContainer}

startServer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { exec } from "child_process";
2+
3+
const startServer = async () => {
4+
// @ts-expect-error not needed
5+
global.__VITE_SERVER__ = exec("npm run dev"); // Replace 'npm run dev' with your Vite start script
6+
await new Promise((resolve) => setTimeout(resolve, 4000)); // Wait for the server to start
7+
};
8+
9+
export default startServer;

stopServer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const stopServer = async () => {
2+
// @ts-expect-error not needed
3+
global.__VITE_SERVER__.kill();
4+
};
5+
6+
export default stopServer;

tests/customScroll.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { test, expect } from "@playwright/test";
2+
import {
3+
assertCustomScrollBarVisible,
4+
getInnerContainer,
5+
getScrollHandle,
6+
} from "./customScrollDriver";
7+
8+
const APP_URL = "http://localhost:5174/";
9+
10+
test.describe("basic functionality", () => {
11+
test.beforeEach(async ({ page }) => {
12+
await page.goto(APP_URL);
13+
});
14+
15+
test("Custom scrollbar appears when hovering the container", async ({
16+
page,
17+
}) => {
18+
const examplePanel = page.getByTestId("first-example");
19+
await examplePanel.getByTestId("outer-container").hover();
20+
21+
await assertCustomScrollBarVisible(examplePanel);
22+
});
23+
24+
test("Updates the position of the scroll handle when scrolling", async ({
25+
page,
26+
}) => {
27+
const examplePanel = page.getByTestId("first-example");
28+
29+
await examplePanel.getByTestId("outer-container").hover();
30+
await expect(getScrollHandle(examplePanel)).toHaveCSS("top", "0px");
31+
32+
await page.mouse.wheel(0, 100);
33+
34+
expect(
35+
await getInnerContainer(examplePanel).evaluate(
36+
// @ts-expect-error missing type
37+
(node) => (node as HTMLElement).scrollTop,
38+
),
39+
).toBe(100);
40+
41+
expect(
42+
await getScrollHandle(examplePanel).evaluate(
43+
// @ts-expect-error missing type
44+
(node) => (node as HTMLElement).offsetTop,
45+
),
46+
).toBe(28);
47+
});
48+
});

tests/customScrollDriver.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { expect, Locator } from "@playwright/test";
2+
3+
export const getCustomScrollbar = (container: Locator) =>
4+
container.getByTestId("custom-scrollbar");
5+
6+
export const assertCustomScrollBarVisible = async (container: Locator) => {
7+
await expect(getCustomScrollbar(container)).toBeVisible();
8+
await expect(getCustomScrollbar(container)).toHaveCSS("opacity", "1");
9+
};
10+
11+
export const getInnerContainer = (container: Locator) =>
12+
container.getByTestId("inner-container");
13+
14+
export const getScrollHandle = (container: Locator) =>
15+
container.getByTestId("custom-scroll-handle");

vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ export default defineConfig({
2424
emptyOutDir: true,
2525
},
2626
plugins: [react(), dts()],
27+
server: {
28+
port: 5174,
29+
},
2730
});

yarn.lock

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,13 @@
312312
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
313313
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==
314314

315+
"@playwright/test@^1.41.1":
316+
version "1.41.1"
317+
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.41.1.tgz#6954139ed4a67999f1b17460aa3d184f4b334f18"
318+
integrity sha512-9g8EWTjiQ9yFBXc6HjCWe41msLpxEX0KhmfmPl9RPLJdfzL4F0lg2BdJ91O9azFdl11y1pmpwdjBiSxvqc+btw==
319+
dependencies:
320+
playwright "1.41.1"
321+
315322
"@rollup/pluginutils@^5.1.0":
316323
version "5.1.0"
317324
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-5.1.0.tgz#7e53eddc8c7f483a4ad0b94afb1f7f5fd3c771e0"
@@ -1273,6 +1280,11 @@ fs.realpath@^1.0.0:
12731280
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
12741281
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==
12751282

1283+
fsevents@2.3.2:
1284+
version "2.3.2"
1285+
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
1286+
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
1287+
12761288
fsevents@~2.3.2, fsevents@~2.3.3:
12771289
version "2.3.3"
12781290
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
@@ -1766,6 +1778,20 @@ pirates@^4.0.1:
17661778
resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.6.tgz#3018ae32ecfcff6c29ba2267cbf21166ac1f36b9"
17671779
integrity sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==
17681780

1781+
playwright-core@1.41.1:
1782+
version "1.41.1"
1783+
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.41.1.tgz#9c152670010d9d6f970f34b68e3e935d3c487431"
1784+
integrity sha512-/KPO5DzXSMlxSX77wy+HihKGOunh3hqndhqeo/nMxfigiKzogn8kfL0ZBDu0L1RKgan5XHCPmn6zXd2NUJgjhg==
1785+
1786+
playwright@1.41.1:
1787+
version "1.41.1"
1788+
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.41.1.tgz#83325f34165840d019355c2a78a50f21ed9b9c85"
1789+
integrity sha512-gdZAWG97oUnbBdRL3GuBvX3nDDmUOuqzV/D24dytqlKt+eI5KbwusluZRGljx1YoJKZ2NRPaeWiFTeGZO7SosQ==
1790+
dependencies:
1791+
playwright-core "1.41.1"
1792+
optionalDependencies:
1793+
fsevents "2.3.2"
1794+
17691795
postcss-import@^15.1.0:
17701796
version "15.1.0"
17711797
resolved "https://registry.yarnpkg.com/postcss-import/-/postcss-import-15.1.0.tgz#41c64ed8cc0e23735a9698b3249ffdbf704adc70"

0 commit comments

Comments
 (0)