Skip to content

Commit

Permalink
test(e2e): refactor text test to wait for remote mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Feb 14, 2024
1 parent fcddac1 commit 341de5f
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions test/e2e/tests/inputs/text.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,47 +35,46 @@ test.describe('inputs: text', () => {
await page.waitForSelector('data-testid=field-simple', {timeout: 30000})
const field = page.getByTestId('field-simple').getByRole('textbox')

// Enter initial text and wait for the mutate call to be sent
const response = page.waitForResponse(/mutate/)
await field.fill(kanji)
await response
// Enter initial text and wait for the mutate call to be sent
await page.waitForResponse(/mutate/)

// Expect the document to now have the base value
let currentExpectedValue = kanji
expect(await field.inputValue()).toBe(currentExpectedValue)
expect(await getRemoteValue()).toBe(currentExpectedValue)
await expect(field).toHaveValue(currentExpectedValue)
await expect(await getRemoteValue()).toBe(currentExpectedValue)

Check failure on line 45 in test/e2e/tests/inputs/text.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-test (chromium, 3, 3)

[chromium] › inputs/text.spec.ts:18:7 › inputs: text › correctly applies kanji edits

1) [chromium] › inputs/text.spec.ts:18:7 › inputs: text › correctly applies kanji edits ────────── Error: expect(received).toBe(expected) // Object.is equality Expected: "速ヒマヤレ誌相ルなあね日諸せ変評ホ真攻同潔ク作先た員勝どそ際接レゅ自17浅ッ実情スヤ籍認ス重力務鳥の。8平はートご多乗12青國暮整ル通国うれけこ能新ロコラハ元横ミ休探ミソ梓批ざょにね薬展むい本隣ば禁抗ワアミ部真えくト提知週むすほ。査ル人形ルおじつ政謙減セヲモ読見れレぞえ録精てざ定第ぐゆとス務接産ヤ写馬エモス聞氏サヘマ有午ごね客岡ヘロ修彩枝雨父のけリド。· 住ゅなぜ日16語約セヤチ任政崎ソオユ枠体ぞン古91一専泉給12関モリレネ解透ぴゃラぼ転地す球北ドざう記番重投ぼづ。期ゃ更緒リだすし夫内オ代他られくド潤刊本クヘフ伊一ウムニヘ感週け出入ば勇起ょ関図ぜ覧説めわぶ室訪おがト強車傾町コ本喰杜椿榎ほれた。暮る生的更芸窓どさはむ近問ラ入必ラニス療心コウ怒応りめけひ載総ア北吾ヌイヘ主最ニ余記エツヤ州5念稼め化浮ヌリ済毎養ぜぼ。" Received: null 43 | let currentExpectedValue = kanji 44 | await expect(field).toHaveValue(currentExpectedValue) > 45 | await expect(await getRemoteValue()).toBe(currentExpectedValue) | ^ 46 | 47 | // Edit the value to start with "Paragraph 1: " 48 | const p1Prefix = 'Paragraph 1: ' at /home/runner/work/sanity/sanity/test/e2e/tests/inputs/text.spec.ts:45:42

Check failure on line 45 in test/e2e/tests/inputs/text.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-test (chromium, 3, 3)

[chromium] › inputs/text.spec.ts:18:7 › inputs: text › correctly applies kanji edits

1) [chromium] › inputs/text.spec.ts:18:7 › inputs: text › correctly applies kanji edits ────────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: "速ヒマヤレ誌相ルなあね日諸せ変評ホ真攻同潔ク作先た員勝どそ際接レゅ自17浅ッ実情スヤ籍認ス重力務鳥の。8平はートご多乗12青國暮整ル通国うれけこ能新ロコラハ元横ミ休探ミソ梓批ざょにね薬展むい本隣ば禁抗ワアミ部真えくト提知週むすほ。査ル人形ルおじつ政謙減セヲモ読見れレぞえ録精てざ定第ぐゆとス務接産ヤ写馬エモス聞氏サヘマ有午ごね客岡ヘロ修彩枝雨父のけリド。· 住ゅなぜ日16語約セヤチ任政崎ソオユ枠体ぞン古91一専泉給12関モリレネ解透ぴゃラぼ転地す球北ドざう記番重投ぼづ。期ゃ更緒リだすし夫内オ代他られくド潤刊本クヘフ伊一ウムニヘ感週け出入ば勇起ょ関図ぜ覧説めわぶ室訪おがト強車傾町コ本喰杜椿榎ほれた。暮る生的更芸窓どさはむ近問ラ入必ラニス療心コウ怒応りめけひ載総ア北吾ヌイヘ主最ニ余記エツヤ州5念稼め化浮ヌリ済毎養ぜぼ。" Received: null 43 | let currentExpectedValue = kanji 44 | await expect(field).toHaveValue(currentExpectedValue) > 45 | await expect(await getRemoteValue()).toBe(currentExpectedValue) | ^ 46 | 47 | // Edit the value to start with "Paragraph 1: " 48 | const p1Prefix = 'Paragraph 1: ' at /home/runner/work/sanity/sanity/test/e2e/tests/inputs/text.spec.ts:45:42

Check failure on line 45 in test/e2e/tests/inputs/text.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-test (firefox, 3, 3)

[firefox] › inputs/text.spec.ts:18:7 › inputs: text › correctly applies kanji edits

1) [firefox] › inputs/text.spec.ts:18:7 › inputs: text › correctly applies kanji edits ─────────── Error: expect(received).toBe(expected) // Object.is equality Expected: "速ヒマヤレ誌相ルなあね日諸せ変評ホ真攻同潔ク作先た員勝どそ際接レゅ自17浅ッ実情スヤ籍認ス重力務鳥の。8平はートご多乗12青國暮整ル通国うれけこ能新ロコラハ元横ミ休探ミソ梓批ざょにね薬展むい本隣ば禁抗ワアミ部真えくト提知週むすほ。査ル人形ルおじつ政謙減セヲモ読見れレぞえ録精てざ定第ぐゆとス務接産ヤ写馬エモス聞氏サヘマ有午ごね客岡ヘロ修彩枝雨父のけリド。· 住ゅなぜ日16語約セヤチ任政崎ソオユ枠体ぞン古91一専泉給12関モリレネ解透ぴゃラぼ転地す球北ドざう記番重投ぼづ。期ゃ更緒リだすし夫内オ代他られくド潤刊本クヘフ伊一ウムニヘ感週け出入ば勇起ょ関図ぜ覧説めわぶ室訪おがト強車傾町コ本喰杜椿榎ほれた。暮る生的更芸窓どさはむ近問ラ入必ラニス療心コウ怒応りめけひ載総ア北吾ヌイヘ主最ニ余記エツヤ州5念稼め化浮ヌリ済毎養ぜぼ。" Received: null 43 | let currentExpectedValue = kanji 44 | await expect(field).toHaveValue(currentExpectedValue) > 45 | await expect(await getRemoteValue()).toBe(currentExpectedValue) | ^ 46 | 47 | // Edit the value to start with "Paragraph 1: " 48 | const p1Prefix = 'Paragraph 1: ' at /home/runner/work/sanity/sanity/test/e2e/tests/inputs/text.spec.ts:45:42

Check failure on line 45 in test/e2e/tests/inputs/text.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-test (firefox, 3, 3)

[firefox] › inputs/text.spec.ts:18:7 › inputs: text › correctly applies kanji edits

1) [firefox] › inputs/text.spec.ts:18:7 › inputs: text › correctly applies kanji edits ─────────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: "速ヒマヤレ誌相ルなあね日諸せ変評ホ真攻同潔ク作先た員勝どそ際接レゅ自17浅ッ実情スヤ籍認ス重力務鳥の。8平はートご多乗12青國暮整ル通国うれけこ能新ロコラハ元横ミ休探ミソ梓批ざょにね薬展むい本隣ば禁抗ワアミ部真えくト提知週むすほ。査ル人形ルおじつ政謙減セヲモ読見れレぞえ録精てざ定第ぐゆとス務接産ヤ写馬エモス聞氏サヘマ有午ごね客岡ヘロ修彩枝雨父のけリド。· 住ゅなぜ日16語約セヤチ任政崎ソオユ枠体ぞン古91一専泉給12関モリレネ解透ぴゃラぼ転地す球北ドざう記番重投ぼづ。期ゃ更緒リだすし夫内オ代他られくド潤刊本クヘフ伊一ウムニヘ感週け出入ば勇起ょ関図ぜ覧説めわぶ室訪おがト強車傾町コ本喰杜椿榎ほれた。暮る生的更芸窓どさはむ近問ラ入必ラニス療心コウ怒応りめけひ載総ア北吾ヌイヘ主最ニ余記エツヤ州5念稼め化浮ヌリ済毎養ぜぼ。" Received: null 43 | let currentExpectedValue = kanji 44 | await expect(field).toHaveValue(currentExpectedValue) > 45 | await expect(await getRemoteValue()).toBe(currentExpectedValue) | ^ 46 | 47 | // Edit the value to start with "Paragraph 1: " 48 | const p1Prefix = 'Paragraph 1: ' at /home/runner/work/sanity/sanity/test/e2e/tests/inputs/text.spec.ts:45:42

// Edit the value to start with "Paragraph 1: "
const p1Prefix = 'Paragraph 1: '
let nextExpectedValue = `${p1Prefix}${kanji}`
await field.fill(nextExpectedValue)
await page.waitForTimeout(1000) // Hack, we need to wait for the mutation to be received
await page.waitForResponse(/mutate/)

// Expect both the browser input and the document to now have the updated value
currentExpectedValue = `${p1Prefix}${kanji}`
expect(await field.inputValue()).toBe(currentExpectedValue)
expect(await getRemoteValue()).toBe(currentExpectedValue)
await expect(field).toHaveValue(currentExpectedValue)
await expect(await getRemoteValue()).toBe(currentExpectedValue)

// Now move to the end of the paragraph and add a suffix
const p1Suffix = ' (end of paragraph 1)'
nextExpectedValue = currentExpectedValue.replace(/\n\n/, `${p1Suffix}\n\n`)
await field.fill(nextExpectedValue)
await page.waitForTimeout(1000) // Hack, we need to wait for the mutation to be received
await page.waitForResponse(/mutate/)

// Expect both the browser input and the document to now have the updated value
currentExpectedValue = nextExpectedValue
expect(await field.inputValue()).toBe(currentExpectedValue)
expect(await getRemoteValue()).toBe(currentExpectedValue)
await expect(field).toHaveValue(currentExpectedValue)
await expect(await getRemoteValue()).toBe(currentExpectedValue)

// Move to the end of the field and add a final suffix
const p2Suffix = `. EOL.`
nextExpectedValue = `${currentExpectedValue}${p2Suffix}`
await field.fill(nextExpectedValue)
await page.waitForTimeout(1000) // Hack, we need to wait for the mutation to be received
await page.waitForResponse(/mutate/)

// Expect both the browser input and the document to now have the updated value
currentExpectedValue = nextExpectedValue
expect(await field.inputValue()).toBe(currentExpectedValue)
expect(await getRemoteValue()).toBe(currentExpectedValue)
await expect(field).toHaveValue(currentExpectedValue)
await expect(await getRemoteValue()).toBe(currentExpectedValue)
})
})

0 comments on commit 341de5f

Please sign in to comment.