mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
chore: Migrate Timer component from jsx to tsx (#10455)
* migrated LanguagePicker.jsx to tsx * Migrated Menu.jsx to tsx * migrated MenuObject.jsx to tsx * migrated NewMenu.jsx to tsx * Migrated UserMenu.jsx to tsx * removed unnecessary export from UserMenu * added language definition in LanguagePicker * removed unnecessary exports from Menu.tsx * used typeof guard for childs * changed LanguageProps to Languages * removed unnecessary type casting * fixed linting errors * migrated Checkbox to tsx * Migrated Timer component to tsx * fixed linting errors * fixed test cases * removed unused import in timer spec * reverting changes * renamed and then modified Timer * changes for review comments * fixed incorrect clear * using stopTimer in stopwatch * fixed lint issues * added explicit timer cleanup * fixed lint issue * fixed memory leak * renamed Timer * added changes after git mv
This commit is contained in:
@@ -18,8 +18,6 @@
|
||||
*/
|
||||
import React from 'react';
|
||||
import { styledMount as mount } from 'spec/helpers/theming';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import Timer from 'src/components/Timer';
|
||||
import { now } from 'src/modules/dates';
|
||||
|
||||
@@ -40,28 +38,10 @@ describe('Timer', () => {
|
||||
expect(React.isValidElement(<Timer {...mockedProps} />)).toBe(true);
|
||||
});
|
||||
|
||||
it('componentWillMount starts timer after 30ms and sets state.clockStr', async () => {
|
||||
expect(wrapper.state().clockStr).toBe('');
|
||||
it('useEffect starts timer after 30ms and sets state of clockStr', async () => {
|
||||
expect(wrapper.find('span').text()).toBe('');
|
||||
await new Promise(r => setTimeout(r, 35));
|
||||
expect(wrapper.state().clockStr).not.toBe('');
|
||||
});
|
||||
|
||||
it('calls startTimer on mount', () => {
|
||||
// Timer is already mounted in beforeEach
|
||||
wrapper.unmount();
|
||||
const startTimerSpy = sinon.spy(Timer.prototype, 'startTimer');
|
||||
wrapper.mount();
|
||||
// Timer is started once in willUnmount and a second timer in render
|
||||
// TODO: Questionable whether this is necessary.
|
||||
expect(startTimerSpy.callCount).toBe(2);
|
||||
startTimerSpy.restore();
|
||||
});
|
||||
|
||||
it('calls stopTimer on unmount', () => {
|
||||
const stopTimerSpy = sinon.spy(Timer.prototype, 'stopTimer');
|
||||
wrapper.unmount();
|
||||
expect(stopTimerSpy.callCount).toBe(1);
|
||||
stopTimerSpy.restore();
|
||||
expect(wrapper.find('span').text()).not.toBe('');
|
||||
});
|
||||
|
||||
it('renders a span with the correct class', () => {
|
||||
|
||||
Reference in New Issue
Block a user