-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test each Control button appearing; stub out the ajax request.
- Loading branch information
Saleh Hindi
committed
Jun 20, 2017
1 parent
9c256ba
commit 0339f34
Showing
2 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
39 changes: 36 additions & 3 deletions
39
superset/assets/spec/javascripts/dashboard/Controls_spec.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters