garrensmith commented on a change in pull request #938: Refactor CORS tests to run with Jest and Enzyme URL: https://github.com/apache/couchdb-fauxton/pull/938#discussion_r130361730
########## File path: app/addons/cors/__tests__/components.test.js ########## @@ -0,0 +1,215 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. +import FauxtonAPI from "../../../core/api"; +import Views from "../components"; +import Actions from "../actions"; +import Resources from "../resources"; +import Stores from "../stores"; +import utils from "../../../../test/mocha/testUtils"; +import React from "react"; +import ReactDOM from "react-dom"; +import sinon from "sinon"; +import { shallow, mount } from 'enzyme'; + +FauxtonAPI.router = new FauxtonAPI.Router([]); +var assert = utils.assert; +var corsStore = Stores.corsStore; + +describe('CORS Components', () => { + + describe('CorsController', () => { + + beforeEach(() => { + corsStore._origins = ['http://hello.com']; + corsStore._node = '[email protected]'; + corsStore._isEnabled = true; + corsStore._configChanged = true; + }); + + afterEach(() => { + utils.restore(window.confirm); + }); + + it('confirms user change from restricted origin to disabled cors', () => { + var spy = sinon.stub(window, 'confirm'); + spy.returns(false); + + const wrapper = shallow(<Views.CORSController />); + wrapper.find('#bt-enable-disable-cors').simulate('click'); + assert.ok(spy.calledOnce); + }); + + it('does not confirm user change to disable cors when restricted origins are empty', () => { + let spy = sinon.stub(window, 'confirm'); + spy.returns(false); + + // Set selected origins to empty + corsStore._origins = []; + + const wrapper = shallow(<Views.CORSController />); + wrapper.find('#bt-enable-disable-cors').simulate('click'); + assert.ok(spy.notCalled); + }); + + it('confirms user change when moving from selected origins to all origins', () => { + const spy = sinon.stub(window, 'confirm'); + spy.returns(false); + + const wrapper = mount(<Views.CORSController />); + wrapper.find('input').at(0).simulate('change', {target: {checked: true, value: 'all'}}); + assert.ok(spy.calledOnce); + }); + + it('does not confirm all origins change if selected origins are emtpy', () => { + var spy = sinon.stub(window, 'confirm'); + // sinon.stub(Actions, 'toggleLoadingBarsToEnabled'); Review comment: Delete if you don't need it. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
