Skip to content

Commit

Permalink
#675 Wait for commit in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Polleps committed Nov 20, 2023
1 parent 2d45bd7 commit 2684120
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
5 changes: 3 additions & 2 deletions browser/data-browser/tests/documents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ test.describe('documents', async () => {
await page.press(editableTitle, 'Enter');

const teststring = `My test: ${timestamp()}`;

const waiter = waitForCommitOnCurrentResource(page);
await page.fill('textarea', teststring);
await waiter;

// commit editing paragraph
await expect(page.locator(`text=${teststring}`)).toBeVisible();

// multi-user
const currentSubject = await getCurrentSubject(page);
await waitForCommitOnCurrentResource(page);
const page2 = await openNewSubjectWindow(browser, currentSubject!);
await expect(
page2.locator(`text=${teststring}`),
Expand Down
31 changes: 20 additions & 11 deletions browser/data-browser/tests/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,27 @@ test.describe('data-browser', async () => {

const alphabet = 'abcdefghijklmnopqrstuvwxyz';

const waiter = waitForCommitOnCurrentResource(page, {
set: {
['https://atomicdata.dev/properties/name']: alphabet,
},
});

for (const letter of alphabet) {
await page.type(editableTitle, letter, { delay: Math.random() * 300 });
}

// wait for commit debounce
// make sure no commits are waiting for each other
await waiter;

await page.keyboard.press('Escape');

await expect(
page.locator(`text=${alphabet}`).first(),
'String not correct after typing, bad typing UX. Maybe views are notified of changes twice?',
).toBeVisible();

// wait for commit debounce
// await page.waitForTimeout(2000);
// make sure no commits are waiting for each other
await waitForCommitOnCurrentResource(page);
await page.reload();
await expect(
page.locator(`text=${alphabet}`).first(),
Expand Down Expand Up @@ -422,7 +428,10 @@ test.describe('data-browser', async () => {
await page.locator(`[title="Create new resource under ${d0}"]`).click();
await page.click(`button:has-text("${klass}")`);
const d1 = 'depth1';

const waiter = waitForCommitOnCurrentResource(page);
await setTitle(page, d1);
await waiter;

await expect(
page.locator(`[data-test="sidebar"] >> text=${d0}`),
Expand All @@ -433,8 +442,6 @@ test.describe('data-browser', async () => {
"Sidebar doesn't show child resource title",
).toBeVisible();

await waitForCommitOnCurrentResource(page);

await page.reload();
await expect(
page.locator(`[data-test="sidebar"] >> text=${d1}`),
Expand Down Expand Up @@ -543,18 +550,20 @@ test.describe('data-browser', async () => {
// Wait for commit debounce
await page.waitForTimeout(500);

const waiter = waitForCommitOnCurrentResource(page, {
set: {
['https://atomicdata.dev/properties/name']: 'Second Title',
},
});
await editTitle('Second Title', page);
await waiter;

await expect(
page.getByRole('heading', { name: 'Second Title', level: 1 }),
).toBeVisible();

// The history page does not update when the resource changes so we need to wait to be sure the commit is done
// before opening the history page.
await waitForCommitOnCurrentResource(page, {
set: {
['https://atomicdata.dev/properties/name']: 'Second Title',
},
});

await contextMenuClick('history', page);

Expand Down

0 comments on commit 2684120

Please sign in to comment.