Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/static/components/controls/run-button/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const RunMode = Object.freeze({
});

const RunButton = ({actions, autoRun, isDisabled, isRunning, failedTests, checkedTests}) => {
const [mode, setMode] = useState(RunMode.ALL);
const [mode, setMode] = useLocalStorage('RunMode', RunMode.FAILED);
const [showCheckboxes] = useLocalStorage('showCheckboxes', false);

const btnClassName = classNames('btn', {'button_blink': isRunning});
Expand Down
31 changes: 24 additions & 7 deletions test/unit/lib/static/components/controls/run-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {mkConnectedComponent, mkState} from '../utils';
describe('<RunButton />', () => {
const sandbox = sinon.sandbox.create();

let RunButton, useLocalStorageStub, actionsStub, selectorsStub;
let RunButton, useLocalStorageStub, actionsStub, selectorsStub, writeValueStub;

beforeEach(() => {
writeValueStub = sandbox.stub();
useLocalStorageStub = sandbox.stub().returns([true]);
useLocalStorageStub.withArgs('RunMode', 'Failed').returns(['All', writeValueStub]);
actionsStub = {
runAllTests: sandbox.stub().returns({type: 'some-type'}),
runFailedTests: sandbox.stub().returns({type: 'some-type'}),
Expand Down Expand Up @@ -69,6 +71,7 @@ describe('<RunButton />', () => {
});

it('should call "runFailedTests" action on "Run failed tests" click', () => {
useLocalStorageStub.withArgs('RunMode', 'Failed').returns(['Failed', () => {}]);
const failedTests = [{testName: 'suite test', browserName: 'yabro'}];
const state = mkState({initialState: {tree: {suites: {allRootIds: ['suite']}}, processing: false}});
selectorsStub.getFailedTests.withArgs(state).returns(failedTests);
Expand All @@ -81,6 +84,7 @@ describe('<RunButton />', () => {
});

it('should call "retrySuite" action on "Run checked tests" click', () => {
useLocalStorageStub.withArgs('RunMode', 'Failed').returns(['Checked', () => {}]);
const checkedTests = [{testName: 'suite test', browserName: 'yabro'}];
const state = mkState({initialState: {tree: {suites: {allRootIds: ['suite']}}, processing: false}});
selectorsStub.getCheckedTests.withArgs(state).returns(checkedTests);
Expand Down Expand Up @@ -110,33 +114,46 @@ describe('<RunButton />', () => {
assert.equal(component.find('button').text(), 'Run all tests');
});

it('should be "Run checked tests" if there are checked tests', () => {
it('should switch to "Run checked tests" if there are checked tests', () => {
selectorsStub.getCheckedTests.returns([{testName: 'testName', browserName: 'browserName'}]);
const component = mkConnectedComponent(<RunButton />, {
initialState: {tree: {suites: {allRootIds: ['suite']}}, processing: false}
});

assert.equal(component.find('button').text(), 'Run checked tests');
assert.calledWith(writeValueStub, 'Checked');
});
});

describe('localStorage', () => {
it('should save "Run all tests" if picked', () => {
selectorsStub.getCheckedTests.returns([{testName: 'testName', browserName: 'browserName'}]);
selectorsStub.getFailedTests.returns([{testName: 'testName', browserName: 'browserName'}]);
const component = mkConnectedComponent(<RunButton />, {
initialState: {tree: {suites: {allRootIds: ['suite']}}, processing: false}
});

component.find({children: 'All'}).simulate('click');
assert.calledWith(writeValueStub, 'All');
});

it('should be "Run failed tests" if picked', () => {
it('should save "Run failed tests" if picked', () => {
selectorsStub.getFailedTests.returns([{testName: 'testName', browserName: 'browserName'}]);
const component = mkConnectedComponent(<RunButton />, {
initialState: {tree: {suites: {allRootIds: ['suite']}}, processing: false}
});

component.find({children: 'Failed'}).simulate('click');
assert.equal(component.find('button').text(), 'Run failed tests');
assert.calledOnceWith(writeValueStub, 'Failed');
});

it('should be "Run checked tests" if picked', () => {
it('should save "Run checked tests" if picked', () => {
selectorsStub.getCheckedTests.returns([{testName: 'testName', browserName: 'browserName'}]);
const component = mkConnectedComponent(<RunButton />, {
initialState: {tree: {suites: {allRootIds: ['suite']}}, processing: false}
});

component.find({children: 'Checked'}).simulate('click');
assert.equal(component.find('button').text(), 'Run checked tests');
assert.calledWith(writeValueStub, 'Checked');
});
});

Expand Down