-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [EXT-2360] add test for onvaluechanged (#431)
* feat: [EXT-2360] add test for onvaluechanged * feat: test onvaluechanged with new content
- Loading branch information
Showing
2 changed files
with
56 additions
and
3 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
53 changes: 53 additions & 0 deletions
53
test/cypress/integration/entry-editor-on-value-changed.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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { entry } from '../utils/paths' | ||
import { verifyLocation } from '../utils/verify-location' | ||
import { | ||
verifySdkInstallationParameters, | ||
verifySdkInstanceParameters, | ||
} from '../utils/verify-parameters' | ||
import idsData from './fixtures/ids-data.json' | ||
import contentTypeData from './fixtures/content-type-data/entry-editor-ext.json' | ||
|
||
const post = { | ||
id: '5KnnZPwiIq1RNctf1Q1uNl', | ||
title: 'My post to test onValueChanged', | ||
body: 'body value', | ||
} | ||
|
||
const iframeSelector = '[data-test-id="cf-ui-workbench-content"] iframe' | ||
const entryExtensionSelector = 'cf-ui-card' | ||
|
||
context('Entry editor extension', () => { | ||
beforeEach(() => { | ||
cy.setupBrowserStorage() | ||
cy.visit(entry(post.id)) | ||
cy.findByTestId('workbench-title').should(($title) => { | ||
expect($title).to.exist | ||
}) | ||
|
||
cy.waitForIframeWithTestId(entryExtensionSelector) | ||
cy.get('[data-test-id="cf-ui-workbench-content"]').within(() => { | ||
cy.get('iframe').captureIFrameAs('extension') | ||
}) | ||
}) | ||
|
||
it('verifies that onValueChanged is called with the initial value and updates', () => { | ||
cy.getSdk(iframeSelector).then(async (sdk) => { | ||
const spy = cy.stub() | ||
sdk.entry.fields.body.onValueChanged(spy) | ||
expect(spy).to.be.calledOnce | ||
expect(spy).to.be.calledWith('body value') | ||
|
||
spy.reset() | ||
|
||
cy.get('@extension').within(() => { | ||
cy.findByTestId('body-field').should('exist').and('have.value', post.body) | ||
expect(spy).not.to.be.called | ||
cy.findByTestId('body-field') | ||
.type('updating') | ||
.then(() => { | ||
expect(spy).to.be.called | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |