From 24dac2135c84871323da10764d57088d93a6d788 Mon Sep 17 00:00:00 2001 From: Lukas Heiligenbrunner Date: Sun, 12 Jul 2020 13:12:13 +0200 Subject: [PATCH] add test to test savesettings --- src/pages/SettingsPage/GeneralSettings.js | 4 +++- src/pages/SettingsPage/GeneralSettings.test.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/pages/SettingsPage/GeneralSettings.js b/src/pages/SettingsPage/GeneralSettings.js index fa4996d..3f5b067 100644 --- a/src/pages/SettingsPage/GeneralSettings.js +++ b/src/pages/SettingsPage/GeneralSettings.js @@ -37,7 +37,7 @@ class GeneralSettings extends React.Component { return ( <>
-
{ + { e.preventDefault(); this.saveSettings(); }}> @@ -102,8 +102,10 @@ class GeneralSettings extends React.Component { .then((response) => response.json() .then((result) => { if (result.success) { + console.log("successfully saved settings"); // todo 2020-07-10: popup success } else { + console.log("failed to save settings"); // todo 2020-07-10: popup error } })); diff --git a/src/pages/SettingsPage/GeneralSettings.test.js b/src/pages/SettingsPage/GeneralSettings.test.js index a026ead..27873f7 100644 --- a/src/pages/SettingsPage/GeneralSettings.test.js +++ b/src/pages/SettingsPage/GeneralSettings.test.js @@ -24,4 +24,22 @@ describe('', function () { expect(wrapper.find("FormGroup").findWhere(it => it.props().controlId === "passwordfield")).toHaveLength(1); }); + + it('test savesettings', done => { + const wrapper = shallow(); + + global.fetch = prepareFetchApi({success: true}); + + expect(global.fetch).toBeCalledTimes(0); + wrapper.find("[data-testid='mainformsettings']").simulate("submit"); + expect(global.fetch).toBeCalledTimes(1); + + process.nextTick(() => { + // expect callback to have loaded correct tag + expect(wrapper.state().selected).toBe("testname"); + + global.fetch.mockClear(); + done(); + }); + }); });