-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): re-enable tests for Actions API feature toggle and expand …
…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
Showing
2 changed files
with
102 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 102 additions & 46 deletions
148
test/e2e/tests/document-actions/fetchFeatureToggle.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}, | ||
], | ||
}), | ||
) | ||
}) |