Skip to content

Commit

Permalink
feat: [EXT-2360] add test for onvaluechanged (#431)
Browse files Browse the repository at this point in the history
* feat: [EXT-2360] add test for onvaluechanged

* feat: test onvaluechanged with new content
  • Loading branch information
Jwhiles committed Dec 15, 2020
1 parent 9074023 commit 229d930
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { checkSdkSpaceMethods } from './reusable/check-sdk-space-methods-test'
import { checkSdkNavigationSlideInCallbackTest } from './reusable/check-sdk-navigation-slide-in-callback-test'
import {
openSuccessNotificationTest,
openErrorNotificationTest
openErrorNotificationTest,
} from './reusable/open-notifications-test'

const post = {
id: '5mwUiJB2kThfAG9ZnRNuNQ',
title: 'My post with a custom entry editor',
body: 'body value'
body: 'body value',
}

const iframeSelector = '[data-test-id="cf-ui-workbench-content"] iframe'
Expand All @@ -27,7 +27,7 @@ context('Entry editor extension', () => {
beforeEach(() => {
cy.setupBrowserStorage()
cy.visit(entry(post.id))
cy.findByTestId('workbench-title').should($title => {
cy.findByTestId('workbench-title').should(($title) => {
expect($title).to.exist
})

Expand Down
53 changes: 53 additions & 0 deletions test/cypress/integration/entry-editor-on-value-changed.spec.ts
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
})
})
})
})
})

0 comments on commit 229d930

Please sign in to comment.