Skip to content

Commit 8344d90

Browse files
chore: add editorconfig for js files
1 parent cf71aa0 commit 8344d90

File tree

4 files changed

+202
-133
lines changed

4 files changed

+202
-133
lines changed

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[*.js]
2+
charset = utf-8
3+
insert_final_newline = true
4+
end_of_line = lf
5+
indent_style = tab
6+
indent_size = 4

tests/e2e/specs/attach-modal.spec.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
/**
22
* WordPress dependencies
33
*/
4-
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
5-
import { createSimpleGroupField } from '../utils';
4+
import { test, expect } from "@wordpress/e2e-test-utils-playwright";
5+
import { createSimpleGroupField } from "../utils";
66

7-
test.describe( 'Attach Modal', () => {
7+
test.describe("Attach Modal", () => {
8+
test("attach to products", async ({ page, admin }) => {
9+
await createSimpleGroupField(admin, page);
10+
await page.waitForTimeout(500);
11+
await admin.visitAdminPage("admin.php?page=ppom");
812

9-
test( 'attach to products', async({ page, admin }) => {
10-
await createSimpleGroupField( admin, page );
11-
await page.waitForTimeout(500);
12-
await admin.visitAdminPage('admin.php?page=ppom');
13+
const firstRow = page
14+
.locator("#ppom-groups-export-form tbody tr")
15+
.first();
16+
const ppomId = await firstRow.locator("td").nth(1).innerText();
17+
await firstRow.getByText("Attach to Products").click();
1318

14-
const firstRow = page.locator('#ppom-groups-export-form tbody tr').first();
15-
const ppomId = await firstRow.locator('td').nth(1).innerText();
16-
await firstRow.getByText('Attach to Products').click();
19+
const productSelector = page
20+
.locator("#ppom-product-form div")
21+
.filter({ hasText: "Display on Specific Products" })
22+
.first()
23+
.locator('select[name="ppom-attach-to-products\\[\\]"]');
24+
await productSelector.selectOption({ index: 0 });
1725

18-
const productSelector = page.locator('#ppom-product-form div').filter({ hasText: 'Display on Specific Products' }).first().locator('select[name="ppom-attach-to-products\\[\\]"]');
19-
await productSelector.selectOption({ index: 0 });
20-
21-
const selectedOption = await productSelector.inputValue();
22-
console.log('Selected option value:', selectedOption);
23-
await page.getByRole('button', { name: 'Save' }).click();
26+
const selectedOption = await productSelector.inputValue();
27+
console.log("Selected option value:", selectedOption);
28+
await page.getByRole("button", { name: "Save" }).click();
2429

25-
await page.waitForLoadState('networkidle');
26-
await page.goto(`/?p=${selectedOption}`);
30+
await page.waitForLoadState("networkidle");
31+
await page.goto(`/?p=${selectedOption}`);
2732

28-
const elements = page.locator(`.ppom-id-${ppomId}`);
29-
const count = await elements.count();
30-
for (let i = 0; i < count; i++) {
31-
await expect(elements.nth(i)).toBeVisible();
32-
}
33+
const elements = page.locator(`.ppom-id-${ppomId}`);
34+
const count = await elements.count();
35+
for (let i = 0; i < count; i++) {
36+
await expect(elements.nth(i)).toBeVisible();
37+
}
3338
});
3439
});

tests/e2e/specs/conditions.spec.js

Lines changed: 127 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,131 @@
11
/**
22
* WordPress dependencies
33
*/
4-
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
5-
import { addNewField, addNewOptionInModal, enableConditionsInModal, fillFieldNameAndId, fillOptionNameAndValue, pickFieldTypeInModal, saveFieldInModal, saveFields, switchToConditionsModalTab } from '../utils';
6-
7-
test.describe( 'Conditions', () => {
8-
9-
/***
10-
* Create two select fields (with two options each) and one text field. Display the text field if the second option of the second select is selected.
11-
*/
12-
test( 'conditions with Select input', async({ page, admin }) => {
13-
14-
await admin.visitAdminPage('admin.php?page=ppom');
15-
16-
await page.getByRole('link', { name: 'Add New Group' }).click();
17-
await page.getByRole('textbox').fill('Test Group Field with Select Conditions');
18-
19-
const randomNumber = Math.floor(Math.random() * 1000);
20-
const numOfInputFields = 2;
21-
22-
for (let i = 1; i <= numOfInputFields; i++) {
23-
await page.getByRole('button', { name: 'Add field' }).click();
24-
await pickFieldTypeInModal( page, 'select' );
25-
26-
await fillFieldNameAndId( page, i, `Select Input ${randomNumber + i - 1}`, `select_test_${randomNumber + i - 1}`);
27-
28-
await page.locator(`#ppom_field_model_${i}`).getByText('Add Options', { exact: true }).click();
29-
30-
await fillOptionNameAndValue(page, i, 0, 'Option 1', 'option_1');
31-
await addNewOptionInModal(page, i);
32-
await fillOptionNameAndValue(page, i, 1, 'Option 2', 'option_2');
33-
34-
await saveFieldInModal(page, i);
35-
}
36-
37-
await addNewField(page);
38-
await pickFieldTypeInModal( page, 'text' );
39-
await fillFieldNameAndId( page, numOfInputFields + 1, 'Output', 'output_test');
40-
41-
await saveFields(page);
42-
await page.waitForLoadState('networkidle');
43-
await page.reload();
44-
45-
await page.locator(`#ppom_sort_id_${numOfInputFields + 1} .ppom-edit-field`).click();
46-
47-
await switchToConditionsModalTab( page, numOfInputFields + 1);
48-
await enableConditionsInModal(page, numOfInputFields + 1);
49-
50-
await page.locator(`select[name="ppom\\[${numOfInputFields + 1}\\]\\[conditions\\]\\[rules\\]\\[0\\]\\[elements\\]"]`).selectOption({ index: 1 });
51-
52-
await page.locator(`select[name="ppom\\[${numOfInputFields + 1}\\]\\[conditions\\]\\[rules\\]\\[0\\]\\[operators\\]"]`).selectOption({ index: 0 });
53-
54-
await page.locator(`select[name="ppom\\[${numOfInputFields + 1}\\]\\[conditions\\]\\[rules\\]\\[0\\]\\[element_values\\]"]`).selectOption({ index: 1 });
55-
56-
await saveFieldInModal(page, numOfInputFields + 1);
57-
await saveFields(page);
58-
59-
await page.waitForLoadState('networkidle');
60-
61-
await page.reload();
62-
await page.getByText('Attach to Products').click({ force: true });
63-
await page.waitForLoadState('networkidle');
64-
65-
const productSelector = page.locator('select[name="ppom-attach-to-products\\[\\]"]');
66-
await page.waitForLoadState('networkidle');
67-
68-
await productSelector.selectOption({ index: 0 });
69-
const selectedOption = await productSelector.inputValue();
70-
console.log('Selected option value:', selectedOption);
71-
await page.getByRole('button', { name: 'Save', exact: true }).click();
72-
73-
await page.waitForLoadState('networkidle');
74-
await page.goto(`/?p=${selectedOption}`);
75-
76-
await expect( page.getByLabel('Output') ).toBeHidden();
77-
78-
await page.locator(`select[name="ppom[fields][select_test_${randomNumber + 1 }]"]`).selectOption({ index: 1 });
79-
80-
await expect( page.getByLabel('Output') ).toBeVisible();
4+
import { test, expect } from "@wordpress/e2e-test-utils-playwright";
5+
import {
6+
addNewField,
7+
addNewOptionInModal,
8+
enableConditionsInModal,
9+
fillFieldNameAndId,
10+
fillOptionNameAndValue,
11+
pickFieldTypeInModal,
12+
saveFieldInModal,
13+
saveFields,
14+
switchToConditionsModalTab,
15+
} from "../utils";
16+
17+
test.describe("Conditions", () => {
18+
/***
19+
* Create two select fields (with two options each) and one text field. Display the text field if the second option of the second select is selected.
20+
*/
21+
test("conditions with Select input", async ({ page, admin }) => {
22+
await admin.visitAdminPage("admin.php?page=ppom");
23+
24+
await page.getByRole("link", { name: "Add New Group" }).click();
25+
await page
26+
.getByRole("textbox")
27+
.fill("Test Group Field with Select Conditions");
28+
29+
const randomNumber = Math.floor(Math.random() * 1000);
30+
const numOfInputFields = 2;
31+
32+
for (let i = 1; i <= numOfInputFields; i++) {
33+
await page.getByRole("button", { name: "Add field" }).click();
34+
await pickFieldTypeInModal(page, "select");
35+
36+
await fillFieldNameAndId(
37+
page,
38+
i,
39+
`Select Input ${randomNumber + i - 1}`,
40+
`select_test_${randomNumber + i - 1}`,
41+
);
42+
43+
await page
44+
.locator(`#ppom_field_model_${i}`)
45+
.getByText("Add Options", { exact: true })
46+
.click();
47+
48+
await fillOptionNameAndValue(page, i, 0, "Option 1", "option_1");
49+
await addNewOptionInModal(page, i);
50+
await fillOptionNameAndValue(page, i, 1, "Option 2", "option_2");
51+
52+
await saveFieldInModal(page, i);
53+
}
54+
55+
await addNewField(page);
56+
await pickFieldTypeInModal(page, "text");
57+
await fillFieldNameAndId(
58+
page,
59+
numOfInputFields + 1,
60+
"Output",
61+
"output_test",
62+
);
63+
64+
await saveFields(page);
65+
await page.waitForLoadState("networkidle");
66+
await page.reload();
67+
68+
await page
69+
.locator(`#ppom_sort_id_${numOfInputFields + 1} .ppom-edit-field`)
70+
.click();
71+
72+
await switchToConditionsModalTab(page, numOfInputFields + 1);
73+
await enableConditionsInModal(page, numOfInputFields + 1);
74+
75+
await page
76+
.locator(
77+
`select[name="ppom\\[${
78+
numOfInputFields + 1
79+
}\\]\\[conditions\\]\\[rules\\]\\[0\\]\\[elements\\]"]`,
80+
)
81+
.selectOption({ index: 1 });
82+
83+
await page
84+
.locator(
85+
`select[name="ppom\\[${
86+
numOfInputFields + 1
87+
}\\]\\[conditions\\]\\[rules\\]\\[0\\]\\[operators\\]"]`,
88+
)
89+
.selectOption({ index: 0 });
90+
91+
await page
92+
.locator(
93+
`select[name="ppom\\[${
94+
numOfInputFields + 1
95+
}\\]\\[conditions\\]\\[rules\\]\\[0\\]\\[element_values\\]"]`,
96+
)
97+
.selectOption({ index: 1 });
98+
99+
await saveFieldInModal(page, numOfInputFields + 1);
100+
await saveFields(page);
101+
102+
await page.waitForLoadState("networkidle");
103+
104+
await page.reload();
105+
await page.getByText("Attach to Products").click({ force: true });
106+
await page.waitForLoadState("networkidle");
107+
108+
const productSelector = page.locator(
109+
'select[name="ppom-attach-to-products\\[\\]"]',
110+
);
111+
await page.waitForLoadState("networkidle");
112+
113+
await productSelector.selectOption({ index: 0 });
114+
const selectedOption = await productSelector.inputValue();
115+
console.log("Selected option value:", selectedOption);
116+
await page.getByRole("button", { name: "Save", exact: true }).click();
117+
118+
await page.waitForLoadState("networkidle");
119+
await page.goto(`/?p=${selectedOption}`);
120+
121+
await expect(page.getByLabel("Output")).toBeHidden();
122+
123+
await page
124+
.locator(
125+
`select[name="ppom[fields][select_test_${randomNumber + 1}]"]`,
126+
)
127+
.selectOption({ index: 1 });
128+
129+
await expect(page.getByLabel("Output")).toBeVisible();
81130
});
82-
});
131+
});
Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
11
/**
22
* WordPress dependencies
33
*/
4-
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
5-
import { createSimpleGroupField } from '../utils';
6-
7-
test.describe( 'Group Fields Edit', () => {
8-
test( 'change fields order', async({ page, admin }) => {
9-
await createSimpleGroupField( admin, page );
10-
await page.waitForTimeout(500);
11-
await admin.visitAdminPage('admin.php?page=ppom');
12-
13-
const firstRow = page.locator('#ppom-groups-export-form tbody tr').first();
14-
const ppomId = await firstRow.locator('td').nth(1).innerText();
15-
16-
await admin.visitAdminPage(`admin.php?page=ppom&productmeta_id=${ppomId}&do_meta=edit`);
17-
18-
const fieldIds = await page.$$eval('td.ppom_meta_field_id', tds => tds.map(td => td.innerText));
19-
20-
// Move the last row into the first position using HTML manipulation.
21-
await page.evaluate(() => {
22-
const tbody = document.querySelector('tbody.ui-sortable');
23-
const rows = Array.from(tbody.querySelectorAll('tr'));
24-
if ( rows.length > 1 ) {
25-
const lastRow = rows[rows.length - 1];
26-
tbody.insertBefore(lastRow, rows[0]);
27-
}
28-
});
29-
30-
await page.getByRole('button', { name: 'Save Fields' }).click();
31-
32-
const newOrderFieldIds = await page.$$eval('td.ppom_meta_field_id', tds => tds.map(td => td.innerText));
33-
34-
expect(newOrderFieldIds).not.toEqual(fieldIds);
4+
import { test, expect } from "@wordpress/e2e-test-utils-playwright";
5+
import { createSimpleGroupField } from "../utils";
6+
7+
test.describe("Group Fields Edit", () => {
8+
test("change fields order", async ({ page, admin }) => {
9+
await createSimpleGroupField(admin, page);
10+
await page.waitForTimeout(500);
11+
await admin.visitAdminPage("admin.php?page=ppom");
12+
13+
const firstRow = page
14+
.locator("#ppom-groups-export-form tbody tr")
15+
.first();
16+
const ppomId = await firstRow.locator("td").nth(1).innerText();
17+
18+
await admin.visitAdminPage(
19+
`admin.php?page=ppom&productmeta_id=${ppomId}&do_meta=edit`,
20+
);
21+
22+
const fieldIds = await page.$$eval("td.ppom_meta_field_id", (tds) =>
23+
tds.map((td) => td.innerText),
24+
);
25+
26+
// Move the last row into the first position using HTML manipulation.
27+
await page.evaluate(() => {
28+
const tbody = document.querySelector("tbody.ui-sortable");
29+
const rows = Array.from(tbody.querySelectorAll("tr"));
30+
if (rows.length > 1) {
31+
const lastRow = rows[rows.length - 1];
32+
tbody.insertBefore(lastRow, rows[0]);
33+
}
34+
});
35+
36+
await page.getByRole("button", { name: "Save Fields" }).click();
37+
38+
const newOrderFieldIds = await page.$$eval(
39+
"td.ppom_meta_field_id",
40+
(tds) => tds.map((td) => td.innerText),
41+
);
42+
43+
expect(newOrderFieldIds).not.toEqual(fieldIds);
3544
});
36-
});
45+
});

0 commit comments

Comments
 (0)