Skip to content

Commit bcd6cfb

Browse files
authored
Merge pull request #4722 from olifolkerd/unit-tests
Add more unit tests
2 parents df8fde1 + 85759f7 commit bcd6cfb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+12443
-93
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const config = {
136136
// setupFiles: [],
137137

138138
// A list of paths to modules that run some code to configure or set up the testing framework before each test
139-
// setupFilesAfterEnv: [],
139+
setupFilesAfterEnv: ['<rootDir>/test/unit/setup.js'],
140140

141141
// The number of seconds after which a test is considered as slow and reported as such in the results.
142142
// slowTestThreshold: 5,

playwright.config.js

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,14 @@ export default defineConfig({
3939
name: 'chromium',
4040
use: { ...devices['Desktop Chrome'] },
4141
},
42-
43-
{
44-
name: 'firefox',
45-
use: { ...devices['Desktop Firefox'] },
46-
},
47-
48-
{
49-
name: 'webkit',
50-
use: { ...devices['Desktop Safari'] },
51-
},
52-
53-
/* Test against mobile viewports. */
54-
// {
55-
// name: 'Mobile Chrome',
56-
// use: { ...devices['Pixel 5'] },
57-
// },
58-
// {
59-
// name: 'Mobile Safari',
60-
// use: { ...devices['iPhone 12'] },
61-
// },
62-
63-
/* Test against branded browsers. */
64-
// {
65-
// name: 'Microsoft Edge',
66-
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
67-
// },
68-
// {
69-
// name: 'Google Chrome',
70-
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
71-
// },
7242
],
7343

7444
/* Run your local dev server before starting the tests */
75-
// webServer: {
76-
// command: 'npm run start',
77-
// url: 'http://127.0.0.1:3000',
78-
// reuseExistingServer: !process.env.CI,
79-
// },
45+
webServer: {
46+
command: 'npx serve test -p 3000',
47+
port: 3000,
48+
timeout: 60 * 1000,
49+
reuseExistingServer: !process.env.CI,
50+
},
8051
});
8152

src/js/modules/SelectRange/RangeComponent.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export default class RangeComponent {
22
constructor(range) {
3-
/** @type {import("./Range").default} */
43
this._range = range;
54

65
return new Proxy(this, {
@@ -89,4 +88,4 @@ export default class RangeComponent {
8988
this._range.destroy(true);
9089
}
9190
}
92-
}
91+
}

src/js/modules/SelectRange/SelectRange.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ export default class SelectRange extends Module {
183183
/////// Table Functions ///////
184184
///////////////////////////////////
185185

186-
/** @returns {import("./RangeComponent.js").default[]} */
187186
getRanges(){
188187
return this.ranges.map((range) => range.getComponent());
189188
}

test/e2e/SelectRange.spec.js

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

test/e2e/basic.spec.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// @ts-check
2+
import { test, expect } from "@playwright/test";
3+
import { join } from "path";
4+
5+
test.describe("Tabulator functionality", () => {
6+
test.beforeEach(async ({ page }) => {
7+
const htmlPath = join(__dirname, "index.html");
8+
await page.goto(`file://${htmlPath}`);
9+
await page.waitForSelector(".tabulator");
10+
});
11+
12+
test("should initialize table correctly", async ({ page }) => {
13+
// Check that table is initialized
14+
const tableExists = await page.isVisible(".tabulator");
15+
expect(tableExists).toBeTruthy();
16+
17+
// Check row count
18+
await page.waitForSelector(".tabulator-row");
19+
const rowCount = await page.locator(".tabulator-row").count();
20+
expect(rowCount).toBe(5);
21+
22+
// Check column count
23+
const columnCount = await page.locator(".tabulator-col").count();
24+
expect(columnCount).toBe(4);
25+
});
26+
27+
test.describe("Row operations", () => {
28+
test("should add a new row", async ({ page }) => {
29+
await page.evaluate(() => {
30+
window.testTable.addRow({
31+
id: 6,
32+
name: "Frank",
33+
age: 29,
34+
gender: "Male",
35+
});
36+
});
37+
await page.waitForTimeout(300);
38+
39+
const newRowCount = await page.locator(".tabulator-row").count();
40+
expect(newRowCount).toBe(6);
41+
});
42+
43+
test("should update an existing row", async ({ page }) => {
44+
await page.evaluate(() => {
45+
window.testTable.updateRow(1, { name: "Alice Updated" });
46+
});
47+
await page.waitForTimeout(300);
48+
49+
const updatedName = await page.evaluate(() => {
50+
return window.testTable.getRow(1).getData().name;
51+
});
52+
53+
expect(updatedName).toBe("Alice Updated");
54+
});
55+
56+
test("should delete a row", async ({ page }) => {
57+
await page.evaluate(() => {
58+
window.testTable.deleteRow(1);
59+
});
60+
await page.waitForTimeout(300);
61+
62+
const finalRowCount = await page.locator(".tabulator-row").count();
63+
expect(finalRowCount).toBe(4); // Original count minus one
64+
});
65+
});
66+
67+
test.describe("Filtering functionality", () => {
68+
test("should filter rows by gender", async ({ page }) => {
69+
await page.evaluate(() => {
70+
window.testTable.setFilter("gender", "=", "Female");
71+
});
72+
await page.waitForTimeout(300);
73+
74+
const filteredRowCount = await page.locator(".tabulator-row").count();
75+
expect(filteredRowCount).toBe(2); // 2 females in our data
76+
});
77+
78+
test("should clear filters", async ({ page }) => {
79+
// First apply a filter
80+
await page.evaluate(() => {
81+
window.testTable.setFilter("gender", "=", "Female");
82+
});
83+
await page.waitForTimeout(300);
84+
85+
// Then clear it
86+
await page.evaluate(() => {
87+
window.testTable.clearFilter();
88+
});
89+
await page.waitForTimeout(300);
90+
91+
const rowCountAfterClearingFilter = await page
92+
.locator(".tabulator-row")
93+
.count();
94+
expect(rowCountAfterClearingFilter).toBe(5); // Back to original count
95+
});
96+
});
97+
});

test/e2e/index.html

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Tabulator Test</title>
6+
<link rel="stylesheet" href="../../dist/css/tabulator.min.css" />
7+
<script src="../../dist/js/tabulator.js"></script>
8+
<style>
9+
body {
10+
padding: 20px;
11+
font-family: Arial, sans-serif;
12+
}
13+
#test-table {
14+
width: 100%;
15+
height: 400px;
16+
margin-bottom: 20px;
17+
}
18+
</style>
19+
</head>
20+
<body>
21+
<h1>Tabulator Test</h1>
22+
<div id="test-table"></div>
23+
24+
<script>
25+
// Initialize table with test data
26+
document.addEventListener("DOMContentLoaded", function () {
27+
const testData = [
28+
{ id: 1, name: "Alice", age: 25, gender: "Female" },
29+
{ id: 2, name: "Bob", age: 32, gender: "Male" },
30+
{ id: 3, name: "Charlie", age: 45, gender: "Male" },
31+
{ id: 4, name: "Diana", age: 27, gender: "Female" },
32+
{ id: 5, name: "Ethan", age: 35, gender: "Male" },
33+
];
34+
35+
const columns = [
36+
{ title: "ID", field: "id", sorter: "number" },
37+
{ title: "Name", field: "name", sorter: "string" },
38+
{ title: "Age", field: "age", sorter: "number" },
39+
{ title: "Gender", field: "gender", sorter: "string" },
40+
];
41+
42+
// Create global reference for tests to access
43+
window.testTable = new Tabulator("#test-table", {
44+
data: testData,
45+
columns: columns,
46+
layout: "fitColumns",
47+
});
48+
});
49+
</script>
50+
</body>
51+
</html>

0 commit comments

Comments
 (0)