Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions tests/e2e/specs/data-view-block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1019,4 +1019,136 @@
);
}
} );

test( 'auto-removes an empty row when deselected without editing', async ( {
admin,
page,
requestUtils,
} ) => {
const fixture = {};

try {
Object.assign(
fixture,
await createCollectionFixture( requestUtils )
);

fixture.page = await requestUtils.rest( {
method: 'POST',
path: '/wp/v2/crtxt_pages',
data: {
title: 'Empty row auto-remove',
status: 'private',
content: createDataViewBlockMarkup( fixture.collection.id ),
},
} );

await admin.visitAdminPage(
'admin.php',
`page=cortext&p=/page/${ fixture.page.id }`
);

await page.waitForFunction(
( postId ) =>
window.wp?.data
?.select( 'core/editor' )
?.getCurrentPostId?.() === postId,
fixture.page.id,
{ timeout: 15_000 }
);

const canvas = page.frameLocator( '[name="editor-canvas"]' );
await expect(
canvas.getByText( 'The Left Hand of Darkness' )
).toBeVisible();

const beforeRows = await requestUtils.rest( {
path: `/wp/v2/crtxt_${ fixture.slug }`,
params: {
context: 'edit',
status: 'draft,private,publish',
per_page: 100,
},
} );

// Click "New" to create an empty row; title cell receives focus.
await canvas
.getByRole( 'button', { name: 'New', exact: true } )
.click();

await expect
.poll( async () => {
const rows = await requestUtils.rest( {
path: `/wp/v2/crtxt_${ fixture.slug }`,
params: {
context: 'edit',
status: 'draft,private,publish',
per_page: 100,
},
} );
return rows.length;
} )
.toBe( beforeRows.length + 1 );

// Deselect: press Escape to leave the focused cell without typing
// anything, then click on an existing row to shift focus away.
await page.keyboard.press( 'Escape' );
await canvas
.getByText( 'The Left Hand of Darkness' )
.click();

// The empty row should be auto-purged.
await expect

Check failure on line 1101 in tests/e2e/specs/data-view-block.spec.js

View workflow job for this annotation

GitHub Actions / Playwright

[chromium] › tests/e2e/specs/data-view-block.spec.js:1023:2 › Collection view block › auto-removes an empty row when deselected without editing

1) [chromium] › tests/e2e/specs/data-view-block.spec.js:1023:2 › Collection view block › auto-removes an empty row when deselected without editing Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: 1 Received: 2 Call Log: - Timeout 5000ms exceeded while waiting on the predicate 1099 | 1100 | // The empty row should be auto-purged. > 1101 | await expect | ^ 1102 | .poll( async () => { 1103 | const rows = await requestUtils.rest( { 1104 | path: `/wp/v2/crtxt_${ fixture.slug }`, at /home/runner/work/cortext/cortext/tests/e2e/specs/data-view-block.spec.js:1101:4

Check failure on line 1101 in tests/e2e/specs/data-view-block.spec.js

View workflow job for this annotation

GitHub Actions / Playwright

[chromium] › tests/e2e/specs/data-view-block.spec.js:1023:2 › Collection view block › auto-removes an empty row when deselected without editing

1) [chromium] › tests/e2e/specs/data-view-block.spec.js:1023:2 › Collection view block › auto-removes an empty row when deselected without editing Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: 1 Received: 2 Call Log: - Timeout 5000ms exceeded while waiting on the predicate 1099 | 1100 | // The empty row should be auto-purged. > 1101 | await expect | ^ 1102 | .poll( async () => { 1103 | const rows = await requestUtils.rest( { 1104 | path: `/wp/v2/crtxt_${ fixture.slug }`, at /home/runner/work/cortext/cortext/tests/e2e/specs/data-view-block.spec.js:1101:4

Check failure on line 1101 in tests/e2e/specs/data-view-block.spec.js

View workflow job for this annotation

GitHub Actions / Playwright

[chromium] › tests/e2e/specs/data-view-block.spec.js:1023:2 › Collection view block › auto-removes an empty row when deselected without editing

1) [chromium] › tests/e2e/specs/data-view-block.spec.js:1023:2 › Collection view block › auto-removes an empty row when deselected without editing Error: expect(received).toBe(expected) // Object.is equality Expected: 1 Received: 2 Call Log: - Timeout 5000ms exceeded while waiting on the predicate 1099 | 1100 | // The empty row should be auto-purged. > 1101 | await expect | ^ 1102 | .poll( async () => { 1103 | const rows = await requestUtils.rest( { 1104 | path: `/wp/v2/crtxt_${ fixture.slug }`, at /home/runner/work/cortext/cortext/tests/e2e/specs/data-view-block.spec.js:1101:4
.poll( async () => {
const rows = await requestUtils.rest( {
path: `/wp/v2/crtxt_${ fixture.slug }`,
params: {
context: 'edit',
status: 'draft,private,publish',
per_page: 100,
},
} );
return rows.length;
} )
.toBe( beforeRows.length );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we commit to immediate creation + trashing/deleting, row count alone feels a little loose; I’d track the newly created row ID and verify that the specific row was removed.

} finally {
// Best-effort cleanup of any row the auto-purge may not have
// reached (e.g. if the test failed before deselection).
const remainingRows = await requestUtils
.rest( {
path: `/wp/v2/crtxt_${ fixture.slug }`,
params: {
status: 'draft,private,publish',
per_page: 100,
},
} )
.catch( () => [] );
for ( const row of remainingRows ) {
if ( row.id !== fixture.entry?.id ) {
await deleteIfCreated(
requestUtils,
`/wp/v2/crtxt_${ fixture.slug }/${ row.id }`
);
}
}
await deleteIfCreated(
requestUtils,
fixture.entry &&
`/wp/v2/crtxt_${ fixture.slug }/${ fixture.entry.id }`
);
await deleteIfCreated(
requestUtils,
fixture.page && `/wp/v2/crtxt_pages/${ fixture.page.id }`
);
await deleteIfCreated(
requestUtils,
fixture.field && `/wp/v2/crtxt_fields/${ fixture.field.id }`
);
await deleteIfCreated(
requestUtils,
fixture.collection &&
`/wp/v2/crtxt_collections/${ fixture.collection.id }`
);
}
} );
} );
Loading