constructor (props) { super(props) this.state = { sourceRegion: props.settings.sourceRegion || sesRegions[0].id, enable: props.settings.enable || false, sourceEmailAddress: props.settings.sourceEmailAddress || '', isUpdating: false, message: '' } }
context('constructor', () => { it('should initialize the state', () => { const props = generateProps() const settings = shallow(<GeneralSettings {...props} />) assert(settings.state('serviceName') === props.settings.serviceName) assert.deepEqual(settings.state('apiKeys')[0].id, props.settings.apiKeys[0].id) assert.deepEqual(settings.state('apiKeys')[0].status, apiKeyStatuses.created) }) })
context('handleApiKeyDelete', () => { it('should set the delete flag', () => { const props = generateProps() const settings = shallow(<GeneralSettings {...props} />) settings.instance().handleApiKeyDelete(props.settings.apiKeys[0].id) assert.deepEqual(settings.state('apiKeys').length, props.settings.apiKeys.length) assert.deepEqual(settings.state('apiKeys')[0].status, apiKeyStatuses.toBeDeleted) }) it('should remove the key from the list if the key is not created yet', () => { const props = generateProps() const settings = shallow(<GeneralSettings {...props} />) settings.instance().handleApiKeyAdd() settings.instance().handleApiKeyDelete(settings.state('apiKeys')[settings.state('apiKeys').length - 1].id) assert.deepEqual(settings.state('apiKeys').length, props.settings.apiKeys.length) }) })
const id = settings.apiKeys[0].id
/** * SitePost methods * * @param {string} id - post id * @param {string} sid site id * @param {WPCOM} wpcom - wpcom instance * @returns {null} null */ constructor( id, sid, wpcom ) { if ( ! ( this instanceof SitePost ) ) { return new SitePost( id, sid, wpcom ); } this.wpcom = wpcom; this._sid = sid; this.path = `${ root }/${ this._sid }/posts`; // set `id` and/or `slug` properties id = id || {}; if ( 'object' !== typeof id ) { this._id = id; } else { this._id = id.id; this._slug = id.slug; } }
context('handleClickSaveButton', () => { it('should call the updateSettings function', () => { const props = generateProps() const settings = shallow(<GeneralSettings {...props} />) settings.find(Button).simulate('click') assert(props.updateSettings.calledOnce) }) it('should call the postApiKey function', () => { const props = generateProps() const settings = shallow(<GeneralSettings {...props} />) settings.instance().handleApiKeyAdd() settings.find(Button).simulate('click') assert(props.postApiKey.calledOnce) assert(props.deleteApiKey.notCalled) }) it('should call the deleteApiKey function', () => { const props = generateProps() const settings = shallow(<GeneralSettings {...props} />) settings.instance().handleApiKeyDelete(props.settings.apiKeys[0].id) settings.find(Button).simulate('click') assert(props.postApiKey.notCalled) assert(props.deleteApiKey.calledOnce) }) })
action: ACTIVATE_PLUGIN, siteId: 'one.site', pluginId: akismet.id, } ); expect( state ).to.eql( { 'one.site': { [ akismet.id ]: { status: 'inProgress', action: ACTIVATE_PLUGIN, const originalState = deepFreeze( { 'one.site': { [ akismet.id ]: { status: 'inProgress', action: ACTIVATE_PLUGIN, action: ACTIVATE_PLUGIN, siteId: 'one.site', pluginId: akismet.id, data: Object.assign( {}, akismet, { active: true } ), } ); expect( state ).to.eql( { 'one.site': { [ akismet.id ]: { status: 'completed', action: ACTIVATE_PLUGIN, action: ACTIVATE_PLUGIN, siteId: 'one.site',
assert(state.settings.apiKeys[0].id === '2') }) }) assert(state.settings.logoID === resp.id) assert(state.settings.serviceName === settings.serviceName) assert.deepEqual(state.settings.apiKeys, settings.apiKeys) const id = settings.apiKeys[0].id const state = settingsReducer({settings}, removeApiKey(id))
constructor (props) { super(props) this.state = { sourceRegion: props.settings.sourceRegion || sesRegions[0].id, enable: props.settings.enable || false, sourceEmailAddress: props.settings.sourceEmailAddress || '', isUpdating: false, message: '' } }
context('constructor', () => { it('should initialize the state', () => { const props = generateProps() const settings = shallow(<GeneralSettings {...props} />) assert(settings.state('serviceName') === props.settings.serviceName) assert.deepEqual(settings.state('apiKeys')[0].id, props.settings.apiKeys[0].id) assert.deepEqual(settings.state('apiKeys')[0].status, apiKeyStatuses.created) }) })
context('handleApiKeyDelete', () => { it('should set the delete flag', () => { const props = generateProps() const settings = shallow(<GeneralSettings {...props} />) settings.instance().handleApiKeyDelete(props.settings.apiKeys[0].id) assert.deepEqual(settings.state('apiKeys').length, props.settings.apiKeys.length) assert.deepEqual(settings.state('apiKeys')[0].status, apiKeyStatuses.toBeDeleted) }) it('should remove the key from the list if the key is not created yet', () => { const props = generateProps() const settings = shallow(<GeneralSettings {...props} />) settings.instance().handleApiKeyAdd() settings.instance().handleApiKeyDelete(settings.state('apiKeys')[settings.state('apiKeys').length - 1].id) assert.deepEqual(settings.state('apiKeys').length, props.settings.apiKeys.length) }) })
context('handleClickSaveButton', () => { it('should call the updateSettings function', () => { const props = generateProps() const settings = shallow(<GeneralSettings {...props} />) settings.find(Button).simulate('click') assert(props.updateSettings.calledOnce) }) it('should call the postApiKey function', () => { const props = generateProps() const settings = shallow(<GeneralSettings {...props} />) settings.instance().handleApiKeyAdd() settings.find(Button).simulate('click') assert(props.postApiKey.calledOnce) assert(props.deleteApiKey.notCalled) }) it('should call the deleteApiKey function', () => { const props = generateProps() const settings = shallow(<GeneralSettings {...props} />) settings.instance().handleApiKeyDelete(props.settings.apiKeys[0].id) settings.find(Button).simulate('click') assert(props.postApiKey.notCalled) assert(props.deleteApiKey.calledOnce) }) })
const id = settings.apiKeys[0].id