--- /dev/null
+/*
+ * 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(
+ <DefinitionActions
+ changedValue={changedValue}
+ hasError={hasError}
+ isDefault={isDefault}
+ onCancel={() => {}}
+ onReset={() => {}}
+ onSave={() => {}}
+ setting={settings}
+ />
+ );
+}
--- /dev/null
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`disables save button on error 1`] = `
+<React.Fragment>
+ <div
+ className="spacer-top note"
+ style={
+ Object {
+ "lineHeight": "24px",
+ }
+ }
+ >
+ settings._default
+ </div>
+ <div
+ className="settings-definition-changes nowrap"
+ >
+ <Button
+ className="spacer-right button-success"
+ disabled={true}
+ onClick={[Function]}
+ >
+ save
+ </Button>
+ <Button
+ className="spacer-right button-link"
+ onClick={[Function]}
+ >
+ cancel
+ </Button>
+ </div>
+</React.Fragment>
+`;
+
+exports[`displays cancel button when value changed and has error 1`] = `
+<React.Fragment>
+ <div
+ className="spacer-top note"
+ style={
+ Object {
+ "lineHeight": "24px",
+ }
+ }
+ >
+ settings._default
+ </div>
+ <div
+ className="settings-definition-changes nowrap"
+ >
+ <Button
+ className="spacer-right button-success"
+ disabled={true}
+ onClick={[Function]}
+ >
+ save
+ </Button>
+ <Button
+ className="spacer-right button-link"
+ onClick={[Function]}
+ >
+ cancel
+ </Button>
+ </div>
+</React.Fragment>
+`;
+
+exports[`displays cancel button when value changed and no error 1`] = `
+<React.Fragment>
+ <div
+ className="spacer-top note"
+ style={
+ Object {
+ "lineHeight": "24px",
+ }
+ }
+ >
+ settings._default
+ </div>
+ <div
+ className="settings-definition-changes nowrap"
+ >
+ <Button
+ className="spacer-right button-success"
+ disabled={false}
+ onClick={[Function]}
+ >
+ save
+ </Button>
+ <Button
+ className="spacer-right button-link"
+ onClick={[Function]}
+ >
+ cancel
+ </Button>
+ </div>
+</React.Fragment>
+`;
+
+exports[`displays default message when value is default 1`] = `
+<React.Fragment>
+ <div
+ className="spacer-top note"
+ style={
+ Object {
+ "lineHeight": "24px",
+ }
+ }
+ >
+ settings._default
+ </div>
+ <div
+ className="settings-definition-changes nowrap"
+ >
+ <Button
+ className="spacer-right button-success"
+ disabled={false}
+ onClick={[Function]}
+ >
+ save
+ </Button>
+ <Button
+ className="spacer-right button-link"
+ onClick={[Function]}
+ >
+ cancel
+ </Button>
+ </div>
+</React.Fragment>
+`;
+
+exports[`displays default value label when current value differs 1`] = `
+<React.Fragment>
+ <div
+ className="settings-definition-changes nowrap"
+ >
+ <Button
+ className="spacer-right button-success"
+ disabled={true}
+ onClick={[Function]}
+ >
+ save
+ </Button>
+ <Button
+ className="spacer-right button-link"
+ onClick={[Function]}
+ >
+ cancel
+ </Button>
+ <span
+ className="note"
+ >
+ default
+ :
+ settings.default.no_value
+ </span>
+ </div>
+</React.Fragment>
+`;
+
+exports[`displays reset button when empty and not default 1`] = `
+<React.Fragment>
+ <div
+ className="settings-definition-changes nowrap"
+ >
+ <Button
+ className="spacer-right button-success"
+ disabled={true}
+ onClick={[Function]}
+ >
+ save
+ </Button>
+ <Button
+ className="spacer-right"
+ onClick={[Function]}
+ >
+ reset_verb
+ </Button>
+ <Button
+ className="spacer-right button-link"
+ onClick={[Function]}
+ >
+ cancel
+ </Button>
+ <span
+ className="note"
+ >
+ default
+ :
+ settings.default.no_value
+ </span>
+ </div>
+</React.Fragment>
+`;
+
+exports[`displays save button when it can be saved 1`] = `
+<React.Fragment>
+ <div
+ className="spacer-top note"
+ style={
+ Object {
+ "lineHeight": "24px",
+ }
+ }
+ >
+ settings._default
+ </div>
+ <div
+ className="settings-definition-changes nowrap"
+ >
+ <Button
+ className="spacer-right button-success"
+ disabled={false}
+ onClick={[Function]}
+ >
+ save
+ </Button>
+ <Button
+ className="spacer-right button-link"
+ onClick={[Function]}
+ >
+ cancel
+ </Button>
+ </div>
+</React.Fragment>
+`;