Skip to content

Commit

Permalink
Merge pull request #420 from Codeinwp/fix/attach-on-new-group
Browse files Browse the repository at this point in the history
Fix Attach Modal visibility
  • Loading branch information
selul authored Oct 17, 2024
2 parents 756122a + a500fc8 commit a238d3c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 3 additions & 1 deletion templates/admin/ppom-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
$product_meta = array();
$ppom_field_index = 1;
$is_edit_screen = false;
$is_new_group = false;

if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'new' ) {
$is_edit_screen = true;
$is_new_group = true;
}
if ( isset( $_REQUEST['productmeta_id'] ) && $_REQUEST ['do_meta'] == 'edit' ) {

Expand Down Expand Up @@ -542,7 +544,7 @@ class="dashicons dashicons-editor-help"></i></span>
</select>
</div>

<?php if ( $is_edit_screen ) { ?>
<?php if ( $is_edit_screen && ! $is_new_group ) { ?>
<a class="btn btn-sm btn-secondary ppom-products-modal"
data-ppom_id="<?php echo esc_attr( $product_meta_id ); ?>"
data-formmodal-id="ppom-product-modal"
Expand Down
30 changes: 29 additions & 1 deletion tests/e2e/specs/attach-modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { test, expect } from "@wordpress/e2e-test-utils-playwright";
import { createSimpleGroupField } from "../utils";
import { addNewField, createSimpleGroupField, fillFieldNameAndId, pickFieldTypeInModal, saveFieldInModal, saveFields } from "../utils";

test.describe("Attach Modal", () => {
/**
Expand Down Expand Up @@ -82,4 +82,32 @@ test.describe("Attach Modal", () => {
expect(count ).toBeGreaterThan(0);
}
});

/**
* Attach Modal should be visible only for existing PPOM fields.
*/
test("attach modal visibility on Group Edit page", async ({ page, admin }) => {
await admin.visitAdminPage("admin.php?page=ppom");

await page.getByRole("link", { name: "Add New Group" }).click();
await page.getByRole("textbox").fill("Test Attach Modal visibility");

await expect( page.locator('[data-formmodal-id="ppom-product-modal"]') ).toBeHidden();

await addNewField(page);
await pickFieldTypeInModal(page, "text");
await fillFieldNameAndId(
page,
1,
`Test`,
`test`,
);
await saveFieldInModal(page, 1);
await saveFields(page);

await page.waitForLoadState("networkidle");
await page.reload();

await expect( page.locator('[data-formmodal-id="ppom-product-modal"]') ).toBeVisible();
});
});

0 comments on commit a238d3c

Please sign in to comment.