Skip to content

Commit

Permalink
adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Jun 14, 2023
1 parent 5ebe8b4 commit 61758d0
Showing 1 changed file with 57 additions and 55 deletions.
112 changes: 57 additions & 55 deletions test/e2e/app-dir/actions/app-action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,63 @@ createNextDescribe(
}, 'success')
})

it('should revalidate when cookies.set is called in a client action', async () => {
const browser = await next.browser('/revalidate')
await browser.refresh()

let randomCookie
await check(async () => {
randomCookie = JSON.parse(
await browser.elementByCss('#random-cookie').text()
).value
return randomCookie ? 'success' : 'failure'
}, 'success')

console.log(123, await browser.elementByCss('body').text())

await browser.elementByCss('#another').click()
await check(async () => {
return browser.elementByCss('#title').text()
}, 'another route')

const newRandomCookie = JSON.parse(
await browser.elementByCss('#random-cookie').text()
).value

console.log(456, await browser.elementByCss('body').text())

// Should be the same value
expect(randomCookie).toEqual(newRandomCookie)

await browser.elementByCss('#back').click()

// Modify the cookie
await browser.elementByCss('#set-cookie').click()

// Should be different
let revalidatedRandomCookie
await check(async () => {
revalidatedRandomCookie = JSON.parse(
await browser.elementByCss('#random-cookie').text()
).value
return randomCookie !== revalidatedRandomCookie
? 'success'
: 'failure'
}, 'success')

await browser.elementByCss('#another').click()

// The other page should be revalidated too
await check(async () => {
const newRandomCookie = await JSON.parse(
await browser.elementByCss('#random-cookie').text()
).value
return revalidatedRandomCookie === newRandomCookie
? 'success'
: 'failure'
}, 'success')
})

it.each(['tag', 'path'])(
'should invalidate client cache when %s is revalidated',
async (type) => {
Expand Down Expand Up @@ -560,61 +617,6 @@ createNextDescribe(
}, 'success')
}
)

it('should revalidate when cookies.set is called in a client action', async () => {
const browser = await next.browser('/revalidate')

// Make sure we have a cookie set initially
await browser.elementByCss('#set-cookie').click()

let randomCookie
await check(async () => {
randomCookie = JSON.parse(
await browser.elementByCss('#random-cookie').text()
).value
return randomCookie ? 'success' : 'failure'
}, 'success')

await browser.elementByCss('#another').click()
await check(async () => {
return browser.elementByCss('#title').text()
}, 'another route')

const newRandomCookie = JSON.parse(
await browser.elementByCss('#random-cookie').text()
).value

// Should be the same value
expect(randomCookie).toEqual(newRandomCookie)

await browser.elementByCss('#back').click()

// Modify the cookie
await browser.elementByCss('#set-cookie').click()

// Should be different
let revalidatedRandomCookie
await check(async () => {
revalidatedRandomCookie = JSON.parse(
await browser.elementByCss('#random-cookie').text()
).value
return randomCookie !== revalidatedRandomCookie
? 'success'
: 'failure'
}, 'success')

await browser.elementByCss('#another').click()

// The other page should be revalidated too
await check(async () => {
const newRandomCookie = await JSON.parse(
await browser.elementByCss('#random-cookie').text()
).value
return revalidatedRandomCookie === newRandomCookie
? 'success'
: 'failure'
}, 'success')
})
})
}
)

0 comments on commit 61758d0

Please sign in to comment.