mirror of
https://github.com/apache/superset.git
synced 2026-04-20 08:34:37 +00:00
add more tests for Timer (#2889)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { describe, it } from 'mocha';
|
||||
import { mount } from 'enzyme';
|
||||
import { describe, it, beforeEach } from 'mocha';
|
||||
import { expect } from 'chai';
|
||||
|
||||
import Timer from '../../../javascripts/components/Timer';
|
||||
@@ -8,18 +8,44 @@ import { now } from '../../../javascripts/modules/dates';
|
||||
|
||||
|
||||
describe('Timer', () => {
|
||||
let wrapper;
|
||||
const mockedProps = {
|
||||
startTime: now(),
|
||||
endTime: null,
|
||||
isRunning: true,
|
||||
state: 'warning',
|
||||
status: 'warning',
|
||||
};
|
||||
it('is valid', () => {
|
||||
expect(React.isValidElement(<Timer {...mockedProps} />))
|
||||
.to.equal(true);
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = mount(<Timer {...mockedProps} />);
|
||||
});
|
||||
it('renders a span', () => {
|
||||
const wrapper = shallow(<Timer {...mockedProps} />);
|
||||
expect(wrapper.find('span')).to.have.length(1);
|
||||
|
||||
it('is a valid element', () => {
|
||||
expect(React.isValidElement(<Timer {...mockedProps} />)).to.equal(true);
|
||||
});
|
||||
|
||||
it('componentWillMount starts timer after 30ms and sets state.clockStr', () => {
|
||||
expect(wrapper.state().clockStr).to.equal('');
|
||||
setTimeout(() => {
|
||||
expect(wrapper.state().clockStr).not.equal('');
|
||||
}, 31);
|
||||
});
|
||||
|
||||
it('calls startTimer on mount', () => {
|
||||
const startTimerSpy = sinon.spy(Timer.prototype, 'startTimer');
|
||||
wrapper.mount();
|
||||
expect(Timer.prototype.startTimer.calledOnce);
|
||||
startTimerSpy.restore();
|
||||
});
|
||||
|
||||
it('calls stopTimer on unmount', () => {
|
||||
const stopTimerSpy = sinon.spy(Timer.prototype, 'stopTimer');
|
||||
wrapper.unmount();
|
||||
expect(Timer.prototype.stopTimer.calledOnce);
|
||||
stopTimerSpy.restore();
|
||||
});
|
||||
|
||||
it('renders a span with the correct class', () => {
|
||||
expect(wrapper.find('span').hasClass('label-warning')).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user