Skip to content

Commit

Permalink
test(e2e): re-enable tests for Actions API feature toggle and expand …
Browse files Browse the repository at this point in the history
…test cases

This commit also removes the `__internal_serverDocumentActions` override from the E2E Studio.

Actions API enablement can now be controlled dynamically using the `mockActionsFeatureToggle`
helper.
  • Loading branch information
juice49 committed Jul 8, 2024
1 parent f31671b commit daca8e9
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 50 deletions.
4 changes: 0 additions & 4 deletions dev/studio-e2e-testing/sanity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,4 @@ export default defineConfig({

plugins: [sharedSettings()],
basePath: '/test',
// eslint-disable-next-line camelcase
__internal_serverDocumentActions: {
enabled: true,
},
})
148 changes: 102 additions & 46 deletions test/e2e/tests/document-actions/fetchFeatureToggle.spec.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,113 @@
import {expect} from '@playwright/test'
import {test} from '@sanity/test'

interface ActionsFeatureToggle {
actions: boolean
}

/*
Test skipped due to on going developments around server actions that make them flaky
Re-enable this test when the server actions are stable
*/
test.skip(`document actions follow appropriate logic after receiving response from feature toggle endpoint`, async ({
import {mockActionsFeatureToggle} from '../../helpers/mockActionsFeatureToggle'

test('Actions API should be used if the feature toggle is enabled and the Studio version satisfies the `compatibleStudioVersions` constraint', async ({
page,
createDraftDocument,
}) => {
await mockActionsFeatureToggle({
response: {
enabled: true,
compatibleStudioVersions: '>= 3',
},
page,
})

const actionsEditRequest = page.waitForResponse(
(response) =>
response.url().includes('/data/actions') && response.request().method() === 'POST',
{
timeout: 20_000,
},
)

const titleInput = page.getByTestId('field-title').getByTestId('string-input')

await createDraftDocument('/test/content/book')
await titleInput.fill('Test title')
const actionsEditResponse = await (await actionsEditRequest).json()

expect(actionsEditResponse).toEqual(
expect.objectContaining({
transactionId: expect.any(String),
}),
)
})

const featureToggleRequest = page.waitForResponse(async (response) => {
return response.url().includes('/data/actions') && response.request().method() === 'GET'
test('Actions API should not be used if the feature toggle is enabled, but the Studio version does not satisfy the `compatibleStudioVersions` constraint', async ({
page,
createDraftDocument,
}) => {
await mockActionsFeatureToggle({
response: {
enabled: true,
compatibleStudioVersions: '< 3.0.0',
},
page,
})

const featureToggleResponse: ActionsFeatureToggle = await (await featureToggleRequest).json()

await page.getByTestId('field-title').getByTestId('string-input').fill('Test title')

if (featureToggleResponse.actions) {
const actionsEditRequest = page.waitForResponse(async (response) => {
return response.url().includes('/data/actions') && response.request().method() === 'POST'
})

const actionsEditResponse = await (await actionsEditRequest).json()

expect(actionsEditResponse).toEqual(
expect.objectContaining({
transactionId: expect.any(String),
}),
)
} else {
const mutateEditRequest = page.waitForResponse(async (response) => {
return response.url().includes('/data/mutate') && response.request().method() === 'POST'
})

const mutateEditResponse = await (await mutateEditRequest).json()

expect(mutateEditResponse).toEqual(
expect.objectContaining({
transactionId: expect.any(String),
results: [
{
id: expect.any(String),
operation: expect.any(String),
},
],
}),
)
}
const mutateEditRequest = page.waitForResponse(
(response) => response.url().includes('/data/mutate') && response.request().method() === 'POST',
{
timeout: 20_000,
},
)

const titleInput = page.getByTestId('field-title').getByTestId('string-input')

await createDraftDocument('/test/content/book')
await titleInput.fill('Test title')
const mutateEditResponse = await (await mutateEditRequest).json()

expect(mutateEditResponse).toEqual(
expect.objectContaining({
transactionId: expect.any(String),
results: [
{
id: expect.any(String),
operation: expect.any(String),
},
],
}),
)
})

test('Actions API should not be used if the feature toggle is not enabled, regardless of whether the Studio version satisfies the `compatibleStudioVersions` constraint', async ({
page,
createDraftDocument,
}) => {
await mockActionsFeatureToggle({
response: {
enabled: false,
compatibleStudioVersions: '>= 3',
},
page,
})

const mutateEditRequest = page.waitForResponse(
(response) => response.url().includes('/data/mutate') && response.request().method() === 'POST',
{
timeout: 20_000,
},
)

const titleInput = page.getByTestId('field-title').getByTestId('string-input')

await createDraftDocument('/test/content/book')
await titleInput.fill('Test title')
const mutateEditResponse = await (await mutateEditRequest).json()

expect(mutateEditResponse).toEqual(
expect.objectContaining({
transactionId: expect.any(String),
results: [
{
id: expect.any(String),
operation: expect.any(String),
},
],
}),
)
})

0 comments on commit daca8e9

Please sign in to comment.