summaryrefslogtreecommitdiff
path: root/web-ui/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'web-ui/src/common')
-rw-r--r--web-ui/src/common/app.js2
-rw-r--r--web-ui/src/common/footer/footer.spec.js17
-rw-r--r--web-ui/src/common/header/header.spec.js17
-rw-r--r--web-ui/src/common/i18n.js40
-rw-r--r--web-ui/src/common/input_field/input_field.js2
-rw-r--r--web-ui/src/common/input_field/input_field.scss (renamed from web-ui/src/common/input_field/input-field.scss)0
-rw-r--r--web-ui/src/common/input_field/input_field.spec.js20
-rw-r--r--web-ui/src/common/submit_button/submit_button.js2
-rw-r--r--web-ui/src/common/submit_button/submit_button.scss (renamed from web-ui/src/common/submit_button/submit-button.scss)0
-rw-r--r--web-ui/src/common/submit_button/submit_button.spec.js16
-rw-r--r--web-ui/src/common/util.js8
-rw-r--r--web-ui/src/common/util.spec.js20
12 files changed, 141 insertions, 3 deletions
diff --git a/web-ui/src/common/app.js b/web-ui/src/common/app.js
index f6594557..03a69fc9 100644
--- a/web-ui/src/common/app.js
+++ b/web-ui/src/common/app.js
@@ -18,7 +18,7 @@
import React from 'react';
import { I18nextProvider } from 'react-i18next';
-import internationalization from '../i18n';
+import internationalization from 'src/common/i18n';
const App = ({ i18n = internationalization, child }) => (
<I18nextProvider i18n={i18n}>
diff --git a/web-ui/src/common/footer/footer.spec.js b/web-ui/src/common/footer/footer.spec.js
new file mode 100644
index 00000000..f1247233
--- /dev/null
+++ b/web-ui/src/common/footer/footer.spec.js
@@ -0,0 +1,17 @@
+import { shallow } from 'enzyme';
+import expect from 'expect';
+import React from 'react';
+import { Footer } from 'src/common/footer/footer';
+
+describe('Footer', () => {
+ let footer;
+
+ beforeEach(() => {
+ const mockTranslations = key => key;
+ footer = shallow(<Footer t={mockTranslations} />);
+ });
+
+ it('renders the footer content', () => {
+ expect(footer.find('footer').text()).toContain('footer-text');
+ });
+});
diff --git a/web-ui/src/common/header/header.spec.js b/web-ui/src/common/header/header.spec.js
new file mode 100644
index 00000000..82e29e1c
--- /dev/null
+++ b/web-ui/src/common/header/header.spec.js
@@ -0,0 +1,17 @@
+import { shallow } from 'enzyme';
+import expect from 'expect';
+import React from 'react';
+import { Header } from 'src/common/header/header';
+
+describe('Header', () => {
+ let header;
+
+ beforeEach(() => {
+ const mockTranslations = key => key;
+ header = shallow(<Header t={mockTranslations} />);
+ });
+
+ it('renders the header content', () => {
+ expect(header.find('header').text()).toContain('logout');
+ });
+});
diff --git a/web-ui/src/common/i18n.js b/web-ui/src/common/i18n.js
new file mode 100644
index 00000000..db107dc7
--- /dev/null
+++ b/web-ui/src/common/i18n.js
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2017 ThoughtWorks, Inc.
+ *
+ * Pixelated is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pixelated 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+ */
+import i18n from 'i18next';
+import i18nBackend from 'i18nextXHRBackend';
+import I18nDetector from 'i18nextBrowserLanguageDetector';
+
+const detector = new I18nDetector();
+const detect = detector.detect.bind(detector);
+
+detector.detect = (detectionOrder) => {
+ const result = detect(detectionOrder);
+ return result.replace('-', '_');
+};
+
+i18n
+ .use(i18nBackend)
+ .use(detector)
+ .init({
+ fallbackLng: 'en_US',
+ parseMissingKeyHandler: key => (`"${key} untranslated"`),
+ backend: {
+ loadPath: 'public/locales/{{lng}}/{{ns}}.json'
+ }
+ });
+
+export default i18n;
diff --git a/web-ui/src/common/input_field/input_field.js b/web-ui/src/common/input_field/input_field.js
index d4876d9f..a92faeb9 100644
--- a/web-ui/src/common/input_field/input_field.js
+++ b/web-ui/src/common/input_field/input_field.js
@@ -17,7 +17,7 @@
import React from 'react';
-import './input-field.scss';
+import './input_field.scss';
const InputField = ({ label, name, type = 'text' }) => (
<div className='input-field-group'>
diff --git a/web-ui/src/common/input_field/input-field.scss b/web-ui/src/common/input_field/input_field.scss
index dd8e8927..dd8e8927 100644
--- a/web-ui/src/common/input_field/input-field.scss
+++ b/web-ui/src/common/input_field/input_field.scss
diff --git a/web-ui/src/common/input_field/input_field.spec.js b/web-ui/src/common/input_field/input_field.spec.js
new file mode 100644
index 00000000..0c044ce1
--- /dev/null
+++ b/web-ui/src/common/input_field/input_field.spec.js
@@ -0,0 +1,20 @@
+import { shallow } from 'enzyme';
+import expect from 'expect';
+import React from 'react';
+import InputField from 'src/common/input_field/input_field';
+
+describe('InputField', () => {
+ let inputField;
+
+ beforeEach(() => {
+ inputField = shallow(<InputField label='Email' name='email' />);
+ });
+
+ it('renders an input of type text for email', () => {
+ expect(inputField.find('input[type="text"]').props().name).toEqual('email');
+ });
+
+ it('renders a label for the email', () => {
+ expect(inputField.find('label').text()).toEqual('Email');
+ });
+});
diff --git a/web-ui/src/common/submit_button/submit_button.js b/web-ui/src/common/submit_button/submit_button.js
index fb87bf7d..4754e042 100644
--- a/web-ui/src/common/submit_button/submit_button.js
+++ b/web-ui/src/common/submit_button/submit_button.js
@@ -17,7 +17,7 @@
import React from 'react';
-import './submit-button.scss';
+import './submit_button.scss';
const SubmitButton = ({ buttonText }) => (
<input type='submit' className='submit-button' value={buttonText} />
diff --git a/web-ui/src/common/submit_button/submit-button.scss b/web-ui/src/common/submit_button/submit_button.scss
index 13cb7607..13cb7607 100644
--- a/web-ui/src/common/submit_button/submit-button.scss
+++ b/web-ui/src/common/submit_button/submit_button.scss
diff --git a/web-ui/src/common/submit_button/submit_button.spec.js b/web-ui/src/common/submit_button/submit_button.spec.js
new file mode 100644
index 00000000..8279547c
--- /dev/null
+++ b/web-ui/src/common/submit_button/submit_button.spec.js
@@ -0,0 +1,16 @@
+import { shallow } from 'enzyme';
+import expect from 'expect';
+import React from 'react';
+import SubmitButton from 'src/common/submit_button/submit_button';
+
+describe('SubmitButton', () => {
+ let submitButton;
+
+ beforeEach(() => {
+ submitButton = shallow(<SubmitButton buttonText='Add Email' />);
+ });
+
+ it('renders an input of type submit for add email', () => {
+ expect(submitButton.find('input[type="submit"]').props().value).toEqual('Add Email');
+ });
+});
diff --git a/web-ui/src/common/util.js b/web-ui/src/common/util.js
new file mode 100644
index 00000000..effb3d9c
--- /dev/null
+++ b/web-ui/src/common/util.js
@@ -0,0 +1,8 @@
+export const hasQueryParameter = (param) => {
+ const decodedUri = decodeURIComponent(window.location.search.substring(1));
+ return !(decodedUri.split('&').indexOf(param) < 0);
+};
+
+export default {
+ hasQueryParameter
+};
diff --git a/web-ui/src/common/util.spec.js b/web-ui/src/common/util.spec.js
new file mode 100644
index 00000000..805d9dd5
--- /dev/null
+++ b/web-ui/src/common/util.spec.js
@@ -0,0 +1,20 @@
+import expect from 'expect';
+import Util from 'src/common/util';
+
+describe('Utils', () => {
+ describe('.hasQueryParameter', () => {
+ global.window = {
+ location: {
+ search: '?auth-error&lng=pt-BR'
+ }
+ };
+
+ it('checks if param included in query parameters', () => {
+ expect(Util.hasQueryParameter('auth-error')).toBe(true);
+ });
+
+ it('checks if param not included in query parameters', () => {
+ expect(Util.hasQueryParameter('error')).toBe(false);
+ });
+ });
+});