From: Pascal Mugnier Date: Wed, 28 Mar 2018 12:37:10 +0000 (+0200) Subject: Add tests X-Git-Tag: 7.5~1446 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=13db8cfae1593b4c195089079b2a1a3eda482181;p=sonarqube.git Add tests --- diff --git a/server/sonar-web/src/main/js/apps/settings/__tests__/DefinitionActions-test.tsx b/server/sonar-web/src/main/js/apps/settings/__tests__/DefinitionActions-test.tsx new file mode 100644 index 00000000000..d5ab2ec0ba7 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/__tests__/DefinitionActions-test.tsx @@ -0,0 +1,89 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +/* eslint-disable import/order */ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import DefinitionActions from '../components/DefinitionActions'; + +const definition = { + category: 'baz', + description: 'lorem', + fields: [], + key: 'key', + name: 'foobar', + options: [], + subCategory: 'bar', + type: 'foo' +}; + +const settings = { + key: 'key', + definition, + value: 'baz' +}; + +it('displays default message when value is default', () => { + const wrapper = shallowRender('', false, true); + expect(wrapper).toMatchSnapshot(); +}); + +it('displays save button when it can be saved', () => { + const wrapper = shallowRender('foo', false, true); + expect(wrapper).toMatchSnapshot(); +}); + +it('displays cancel button when value changed and no error', () => { + const wrapper = shallowRender('foo', false, true); + expect(wrapper).toMatchSnapshot(); +}); + +it('displays cancel button when value changed and has error', () => { + const wrapper = shallowRender('foo', true, true); + expect(wrapper).toMatchSnapshot(); +}); + +it('disables save button on error', () => { + const wrapper = shallowRender('foo', true, true); + expect(wrapper).toMatchSnapshot(); +}); + +it('displays reset button when empty and not default', () => { + const wrapper = shallowRender('', true, false); + expect(wrapper).toMatchSnapshot(); +}); + +it('displays default value label when current value differs', () => { + const wrapper = shallowRender('foobar', true, false); + expect(wrapper).toMatchSnapshot(); +}); + +function shallowRender(changedValue: string, hasError: boolean, isDefault: boolean) { + return shallow( + {}} + onReset={() => {}} + onSave={() => {}} + setting={settings} + /> + ); +} diff --git a/server/sonar-web/src/main/js/apps/settings/__tests__/__snapshots__/DefinitionActions-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/__tests__/__snapshots__/DefinitionActions-test.tsx.snap new file mode 100644 index 00000000000..12095239f94 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/__tests__/__snapshots__/DefinitionActions-test.tsx.snap @@ -0,0 +1,225 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`disables save button on error 1`] = ` + +
+ settings._default +
+
+ + +
+
+`; + +exports[`displays cancel button when value changed and has error 1`] = ` + +
+ settings._default +
+
+ + +
+
+`; + +exports[`displays cancel button when value changed and no error 1`] = ` + +
+ settings._default +
+
+ + +
+
+`; + +exports[`displays default message when value is default 1`] = ` + +
+ settings._default +
+
+ + +
+
+`; + +exports[`displays default value label when current value differs 1`] = ` + +
+ + + + default + : + settings.default.no_value + +
+
+`; + +exports[`displays reset button when empty and not default 1`] = ` + +
+ + + + + default + : + settings.default.no_value + +
+
+`; + +exports[`displays save button when it can be saved 1`] = ` + +
+ settings._default +
+
+ + +
+
+`;