diff --git a/editor/header/saved-state/index.js b/editor/header/saved-state/index.js index 371a0fd4d4a64e..8d55efda5bb96e 100644 --- a/editor/header/saved-state/index.js +++ b/editor/header/saved-state/index.js @@ -24,7 +24,7 @@ import { getEditedPostAttribute, } from '../../selectors'; -function SavedState( { isNew, isDirty, isSaving, isSaveable, status, onStatusChange, onSave } ) { +export function SavedState( { isNew, isDirty, isSaving, isSaveable, status, onStatusChange, onSave } ) { const className = 'editor-saved-state'; if ( isSaving ) { diff --git a/editor/header/saved-state/test/index.js b/editor/header/saved-state/test/index.js new file mode 100644 index 00000000000000..7b8e68dbd9f9d9 --- /dev/null +++ b/editor/header/saved-state/test/index.js @@ -0,0 +1,70 @@ +/** + * External dependencies + */ +import { expect } from 'chai'; +import { shallow } from 'enzyme'; +import sinon from 'sinon'; + +/** + * Internal dependencies + */ +import { SavedState } from '../'; + +describe( 'SavedState', () => { + it( 'should display saving while save in progress, even if not saveable', () => { + const wrapper = shallow( + + ); + + expect( wrapper.text() ).to.equal( 'Saving' ); + } ); + + it( 'returns null if the post is not saveable', () => { + const wrapper = shallow( + + ); + + expect( wrapper.type() ).to.be.null(); + } ); + + it( 'should return Saved text if not new and not dirty', () => { + const wrapper = shallow( + + ); + + expect( wrapper.childAt( 0 ).name() ).to.equal( 'Dashicon' ); + expect( wrapper.childAt( 1 ).text() ).to.equal( 'Saved' ); + } ); + + it( 'should return Save button if edits to be saved', () => { + const statusSpy = sinon.spy(); + const saveSpy = sinon.spy(); + const wrapper = shallow( + + ); + + expect( wrapper.name() ).to.equal( 'Button' ); + expect( wrapper.childAt( 0 ).text() ).to.equal( 'Save' ); + wrapper.simulate( 'click' ); + expect( statusSpy ).to.have.been.calledWith( 'draft' ); + expect( saveSpy ).to.have.been.called(); + } ); +} );