From a236fb889a1ac1be7d0e16cf658a031a94d9f4d6 Mon Sep 17 00:00:00 2001 From: Richard Vsiansky Date: Fri, 16 Aug 2019 14:52:50 +0200 Subject: [PATCH] fix(pf3select): props options was overwriting state --- .../src/form-fields/select/index.js | 1 + .../__snapshots__/select.test.js.snap | 150 ++++-------------- .../src/tests/form-fields/select.test.js | 6 +- 3 files changed, 34 insertions(+), 123 deletions(-) diff --git a/packages/pf3-component-mapper/src/form-fields/select/index.js b/packages/pf3-component-mapper/src/form-fields/select/index.js index 0476b5ff4..be257a23c 100644 --- a/packages/pf3-component-mapper/src/form-fields/select/index.js +++ b/packages/pf3-component-mapper/src/form-fields/select/index.js @@ -58,6 +58,7 @@ class Select extends Component { isReadOnly, loadingMessage, simpleValue, + options: _options, // catch options from props, if they are undefined (bcs they would overwrite the state) ...rest } = this.props; diff --git a/packages/pf3-component-mapper/src/tests/form-fields/__snapshots__/select.test.js.snap b/packages/pf3-component-mapper/src/tests/form-fields/__snapshots__/select.test.js.snap index 6ae1af555..89e4c8092 100644 --- a/packages/pf3-component-mapper/src/tests/form-fields/__snapshots__/select.test.js.snap +++ b/packages/pf3-component-mapper/src/tests/form-fields/__snapshots__/select.test.js.snap @@ -150,12 +150,7 @@ exports[` should mount Async correctly 1`] = ` options={ Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ] } @@ -182,7 +177,7 @@ exports[` should mount Async correctly 1`] = ` value={ Array [ Object { - "label": "label", + "label": "asyncLabel", }, ] } @@ -247,12 +242,7 @@ exports[` should mount Async correctly 1`] = ` options={ Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ] } @@ -283,7 +273,7 @@ exports[` should mount Async correctly 1`] = ` value={ Array [ Object { - "label": "label", + "label": "asyncLabel", }, ] } @@ -308,12 +298,7 @@ exports[` should mount Async correctly 1`] = ` options={ Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ] } @@ -374,12 +359,7 @@ exports[` should mount Async correctly 1`] = ` "openMenuOnFocus": false, "options": Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ], "pageSize": 5, @@ -406,7 +386,7 @@ exports[` should mount Async correctly 1`] = ` "tabSelectsValue": true, "value": Array [ Object { - "label": "label", + "label": "asyncLabel", }, ], } @@ -468,12 +448,7 @@ exports[` should mount Async correctly 1`] = ` options={ Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ] } @@ -534,12 +509,7 @@ exports[` should mount Async correctly 1`] = ` "openMenuOnFocus": false, "options": Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ], "pageSize": 5, @@ -566,7 +536,7 @@ exports[` should mount Async correctly 1`] = ` "tabSelectsValue": true, "value": Array [ Object { - "label": "label", + "label": "asyncLabel", }, ], } @@ -619,12 +589,7 @@ exports[` should mount Async correctly 1`] = ` options={ Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ] } @@ -685,12 +650,7 @@ exports[` should mount Async correctly 1`] = ` "openMenuOnFocus": false, "options": Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ], "pageSize": 5, @@ -717,7 +677,7 @@ exports[` should mount Async correctly 1`] = ` "tabSelectsValue": true, "value": Array [ Object { - "label": "label", + "label": "asyncLabel", }, ], } @@ -765,12 +725,7 @@ exports[` should mount Async correctly 1`] = ` options={ Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ] } @@ -831,12 +786,7 @@ exports[` should mount Async correctly 1`] = ` "openMenuOnFocus": false, "options": Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ], "pageSize": 5, @@ -863,7 +813,7 @@ exports[` should mount Async correctly 1`] = ` "tabSelectsValue": true, "value": Array [ Object { - "label": "label", + "label": "asyncLabel", }, ], } @@ -907,7 +857,7 @@ exports[` should mount Async correctly 1`] = ` cx={[Function]} data={ Object { - "label": "label", + "label": "asyncLabel", } } getStyles={[Function]} @@ -919,12 +869,7 @@ exports[` should mount Async correctly 1`] = ` options={ Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ] } @@ -985,12 +930,7 @@ exports[` should mount Async correctly 1`] = ` "openMenuOnFocus": false, "options": Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ], "pageSize": 5, @@ -1017,7 +957,7 @@ exports[` should mount Async correctly 1`] = ` "tabSelectsValue": true, "value": Array [ Object { - "label": "label", + "label": "asyncLabel", }, ], } @@ -1056,7 +996,7 @@ exports[` should mount Async correctly 1`] = `
- label + asyncLabel
should mount Async correctly 1`] = ` options={ Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ] } @@ -1163,12 +1098,7 @@ exports[` should mount Async correctly 1`] = ` "openMenuOnFocus": false, "options": Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ], "pageSize": 5, @@ -1195,7 +1125,7 @@ exports[` should mount Async correctly 1`] = ` "tabSelectsValue": true, "value": Array [ Object { - "label": "label", + "label": "asyncLabel", }, ], } @@ -1247,12 +1177,7 @@ exports[` should mount Async correctly 1`] = ` options={ Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ] } @@ -1313,12 +1238,7 @@ exports[` should mount Async correctly 1`] = ` "openMenuOnFocus": false, "options": Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ], "pageSize": 5, @@ -1345,7 +1265,7 @@ exports[` should mount Async correctly 1`] = ` "tabSelectsValue": true, "value": Array [ Object { - "label": "label", + "label": "asyncLabel", }, ], } @@ -1405,12 +1325,7 @@ exports[` should mount Async correctly 1`] = ` options={ Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ] } @@ -1471,12 +1386,7 @@ exports[` should mount Async correctly 1`] = ` "openMenuOnFocus": false, "options": Array [ Object { - "label": "option 1", - "value": 1, - }, - Object { - "label": "option 2", - "value": 2, + "label": "asyncLabel", }, ], "pageSize": 5, @@ -1503,7 +1413,7 @@ exports[` should mount Async correctly 1`] = ` "tabSelectsValue": true, "value": Array [ Object { - "label": "label", + "label": "asyncLabel", }, ], } diff --git a/packages/pf3-component-mapper/src/tests/form-fields/select.test.js b/packages/pf3-component-mapper/src/tests/form-fields/select.test.js index 8f8b0de64..49d9a4758 100644 --- a/packages/pf3-component-mapper/src/tests/form-fields/select.test.js +++ b/packages/pf3-component-mapper/src/tests/form-fields/select.test.js @@ -36,7 +36,7 @@ describe('', () => { }); it('should mount Async correctly', (done) => { - const asyncLoading = jest.fn().mockReturnValue(Promise.resolve([{ label: 'label' }])); + const asyncLoading = jest.fn().mockReturnValue(Promise.resolve([{ label: 'asyncLabel' }])); const wrapper = mount(); @@ -48,13 +48,13 @@ describe('', () => { }); it('should load Async options correctly', (done) => { - const asyncLoading = jest.fn().mockReturnValue(Promise.resolve([{ label: 'label' }])); + const asyncLoading = jest.fn().mockReturnValue(Promise.resolve([{ label: 'asyncLabel' }])); const wrapper = mount(); setImmediate(() => { wrapper.update(); - expect(wrapper.find(SelectPF3).first().instance().state.options).toEqual([{ label: 'label' }]); + expect(wrapper.find(SelectPF3).first().instance().state.options).toEqual([{ label: 'asyncLabel' }]); done(); }); });