Skip to content

Commit

Permalink
Test each Control button appearing; stub out the ajax request.
Browse files Browse the repository at this point in the history
  • Loading branch information
Saleh Hindi committed Jun 20, 2017
1 parent 9c256ba commit 0339f34
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
39 changes: 36 additions & 3 deletions superset/assets/spec/javascripts/dashboard/Controls_spec.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,64 @@
import React from 'react';
import { mount } from 'enzyme';
import { describe, it, beforeEach } from 'mocha';
import { describe, it, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';
import sinon from 'sinon';
import $ from 'jquery';

import Controls from '../../../javascripts/dashboard/components/Controls';
import { dashboardData } from './fixtures';

describe('Controls', () => {
let wrapper;
let ajaxStub;
const mockedProps = {
dashboard: dashboardData,
};
mockedProps.dashboard.css = 'foo';

beforeEach(() => {
ajaxStub = sinon.stub($, 'ajax');
wrapper = mount(<Controls {...mockedProps} />);
});

afterEach(() => {
ajaxStub.restore();
});

it('is a valid element', () => {
expect(React.isValidElement(<Controls {...mockedProps} />)).to.equal(true);
});

it('sets the state to cssTemplates on componentWillMount', () => {
expect(wrapper.state().css).to.equal('foo');
ajaxStub.yieldsTo('success', {
result: [{
template_name: 'Test1',
css: 'Test2',
}],
});

const wrapper2 = mount(<Controls {...mockedProps} />);

expect(wrapper2.state().css).to.equal('foo');
expect(wrapper2.state().cssTemplates[0].value).to.equal('Test1');
expect(wrapper2.state().cssTemplates[0].css).to.equal('Test2');
expect(wrapper2.state().cssTemplates[0].label).to.equal('Test1');
});

it('renders the buttons properly', () => {
it('renders all of the buttons', () => {
expect(wrapper.find('button').nodes.length).to.equal(8);

const buttons = ['refresh', 'plus', 'clock-o', 'filter', 'css3', 'envelope', 'edit', 'save'];
let className;
buttons.forEach((button) => {
className = 'fa fa-' + button;
expect(wrapper.contains(<i className={className} />)).to.equal(true);
});
});

it('changeCSS changes the CSS', () => {
expect(wrapper.state().css).to.equal('foo');
wrapper.component.getInstance().changeCss('bar');
expect(wrapper.state().css).to.equal('bar');
});
});
1 change: 1 addition & 0 deletions superset/assets/spec/javascripts/dashboard/fixtures.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const dashboardData = {
sliceObjects: [slice],
dashboard_title: 'Births',
readFilters: () => {},
onChange: () => {},
};

export const contextData = {
Expand Down

0 comments on commit 0339f34

Please sign in to comment.