From ded163e7a1a9615b240df80b0d29e5a7056f9306 Mon Sep 17 00:00:00 2001 From: Ivan Kabir Date: Wed, 19 Jun 2024 18:19:14 +0300 Subject: [PATCH 1/2] fix: save RunMode to localStorage --- lib/static/components/controls/run-button/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/static/components/controls/run-button/index.jsx b/lib/static/components/controls/run-button/index.jsx index 81bc7b6dc..5384ccc23 100644 --- a/lib/static/components/controls/run-button/index.jsx +++ b/lib/static/components/controls/run-button/index.jsx @@ -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}); From de513ff4760da61533c251fcbc4580ad370ad4c3 Mon Sep 17 00:00:00 2001 From: Ivan Kabir Date: Thu, 20 Jun 2024 10:21:17 +0300 Subject: [PATCH 2/2] fix: change tests to work correctly with localStorage --- .../static/components/controls/run-button.jsx | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/test/unit/lib/static/components/controls/run-button.jsx b/test/unit/lib/static/components/controls/run-button.jsx index 4557cde22..d296925a1 100644 --- a/test/unit/lib/static/components/controls/run-button.jsx +++ b/test/unit/lib/static/components/controls/run-button.jsx @@ -5,10 +5,12 @@ import {mkConnectedComponent, mkState} from '../utils'; describe('', () => { 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'}), @@ -69,6 +71,7 @@ describe('', () => { }); 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); @@ -81,6 +84,7 @@ describe('', () => { }); 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); @@ -110,33 +114,46 @@ describe('', () => { 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(, { 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(, { + 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(, { 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(, { 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'); }); });