]> source.dussan.org Git - sonarqube.git/commitdiff
Add tests
authorPascal Mugnier <pascal.mugnier@sonarsource.com>
Wed, 28 Mar 2018 12:37:10 +0000 (14:37 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 29 Mar 2018 18:20:46 +0000 (20:20 +0200)
server/sonar-web/src/main/js/apps/settings/__tests__/DefinitionActions-test.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/apps/settings/__tests__/__snapshots__/DefinitionActions-test.tsx.snap [new file with mode: 0644]

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 (file)
index 0000000..d5ab2ec
--- /dev/null
@@ -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(
+    <DefinitionActions
+      changedValue={changedValue}
+      hasError={hasError}
+      isDefault={isDefault}
+      onCancel={() => {}}
+      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 (file)
index 0000000..1209523
--- /dev/null
@@ -0,0 +1,225 @@
+// 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>
+`;