Skip to content

Commit a238d3c

Browse files
authored
Merge pull request #420 from Codeinwp/fix/attach-on-new-group
Fix Attach Modal visibility
2 parents 756122a + a500fc8 commit a238d3c

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

templates/admin/ppom-fields.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
$product_meta = array();
2626
$ppom_field_index = 1;
2727
$is_edit_screen = false;
28+
$is_new_group = false;
2829

2930
if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'new' ) {
3031
$is_edit_screen = true;
32+
$is_new_group = true;
3133
}
3234
if ( isset( $_REQUEST['productmeta_id'] ) && $_REQUEST ['do_meta'] == 'edit' ) {
3335

@@ -542,7 +544,7 @@ class="dashicons dashicons-editor-help"></i></span>
542544
</select>
543545
</div>
544546

545-
<?php if ( $is_edit_screen ) { ?>
547+
<?php if ( $is_edit_screen && ! $is_new_group ) { ?>
546548
<a class="btn btn-sm btn-secondary ppom-products-modal"
547549
data-ppom_id="<?php echo esc_attr( $product_meta_id ); ?>"
548550
data-formmodal-id="ppom-product-modal"

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* WordPress dependencies
33
*/
44
import { test, expect } from "@wordpress/e2e-test-utils-playwright";
5-
import { createSimpleGroupField } from "../utils";
5+
import { addNewField, createSimpleGroupField, fillFieldNameAndId, pickFieldTypeInModal, saveFieldInModal, saveFields } from "../utils";
66

77
test.describe("Attach Modal", () => {
88
/**
@@ -82,4 +82,32 @@ test.describe("Attach Modal", () => {
8282
expect(count ).toBeGreaterThan(0);
8383
}
8484
});
85+
86+
/**
87+
* Attach Modal should be visible only for existing PPOM fields.
88+
*/
89+
test("attach modal visibility on Group Edit page", async ({ page, admin }) => {
90+
await admin.visitAdminPage("admin.php?page=ppom");
91+
92+
await page.getByRole("link", { name: "Add New Group" }).click();
93+
await page.getByRole("textbox").fill("Test Attach Modal visibility");
94+
95+
await expect( page.locator('[data-formmodal-id="ppom-product-modal"]') ).toBeHidden();
96+
97+
await addNewField(page);
98+
await pickFieldTypeInModal(page, "text");
99+
await fillFieldNameAndId(
100+
page,
101+
1,
102+
`Test`,
103+
`test`,
104+
);
105+
await saveFieldInModal(page, 1);
106+
await saveFields(page);
107+
108+
await page.waitForLoadState("networkidle");
109+
await page.reload();
110+
111+
await expect( page.locator('[data-formmodal-id="ppom-product-modal"]') ).toBeVisible();
112+
});
85113
});

0 commit comments

Comments
 (0)