From d4fb7e3ee16aa5edbcd7fb814f97332481c9a160 Mon Sep 17 00:00:00 2001 From: Marco Araujo Date: Thu, 5 Jan 2017 20:36:07 -0200 Subject: [PATCH 1/7] Update paths --- public/service-worker.js | 6 +++--- webpack.config.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/public/service-worker.js b/public/service-worker.js index 092bbf0..94a004f 100644 --- a/public/service-worker.js +++ b/public/service-worker.js @@ -1,9 +1,9 @@ var CACHE_NAME = 'v1::iClient'; var urlsToCache = [ '/', - '/index.html', - '/dist/bundle.min.js', - '/favicons/favicon-16x16.png', + 'index.html', + 'dist/bundle.min.js', + 'favicons/favicon-16x16.png', 'https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-with-addons.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/react-router/2.8.1/ReactRouter.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.min.js', diff --git a/webpack.config.js b/webpack.config.js index f296cab..9738dca 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -63,7 +63,7 @@ module.exports = { entry: "./app/App.js", output: { path: 'public/dist/', - publicPath: '/dist/', + publicPath: 'dist/', filename: "bundle.min.js", }, module: { From 855adcb6d80507fe929b15849787bfc8e3383a99 Mon Sep 17 00:00:00 2001 From: Marco Araujo Date: Sun, 8 Jan 2017 14:09:22 -0200 Subject: [PATCH 2/7] Add stup json version --- app/constants/Server.js | 1 - app/services/Area.js | 10 ++++++++-- app/services/Client.js | 10 ++++++++-- app/services/User.js | 15 ++++++++++++++- app/services/Visit.js | 10 ++++++++-- webpack.config.js | 1 + 6 files changed, 39 insertions(+), 8 deletions(-) delete mode 100644 app/constants/Server.js diff --git a/app/constants/Server.js b/app/constants/Server.js deleted file mode 100644 index cfb16ad..0000000 --- a/app/constants/Server.js +++ /dev/null @@ -1 +0,0 @@ -export const HOST = 'http://localhost:3000'; diff --git a/app/services/Area.js b/app/services/Area.js index 816e580..ecedd1e 100644 --- a/app/services/Area.js +++ b/app/services/Area.js @@ -7,11 +7,17 @@ const Area = { }, getConfig() { - return { + let config = { headers: { Authorization : window.localStorage.getItem('token') - } + }, + data: {} }; + + if (jsonStubHeaders != undefined && jsonStubHeaders != '') { + Object.assign(config.headers, JSON.parse(jsonStubHeaders)); + } + return config; }, getAll() { diff --git a/app/services/Client.js b/app/services/Client.js index a94a923..6659863 100644 --- a/app/services/Client.js +++ b/app/services/Client.js @@ -7,11 +7,17 @@ const Client = { }, getConfig() { - return { + let config = { headers: { Authorization : window.localStorage.getItem('token') - } + }, + data: {} }; + + if (jsonStubHeaders != undefined && jsonStubHeaders != '') { + Object.assign(config.headers, JSON.parse(jsonStubHeaders)); + } + return config; }, getClients() { diff --git a/app/services/User.js b/app/services/User.js index d05f311..4c0cec1 100644 --- a/app/services/User.js +++ b/app/services/User.js @@ -1,12 +1,25 @@ import axios from 'axios'; const User = { + + getConfig() { + let config = { + headers: { + } + }; + + if (jsonStubHeaders != undefined && jsonStubHeaders != '') { + Object.assign(config.headers, JSON.parse(jsonStubHeaders)); + } + return config; + }, + login(username, password) { let auth = { username: username, password: password }; - return axios.post(`${HOST}/authenticate`, auth); + return axios.post(`${HOST}/authenticate`, auth, this.getConfig()); } }; diff --git a/app/services/Visit.js b/app/services/Visit.js index 8c46aa5..8bae0e9 100644 --- a/app/services/Visit.js +++ b/app/services/Visit.js @@ -7,11 +7,17 @@ const Visit = { }, getConfig() { - return { + let config = { headers: { Authorization : window.localStorage.getItem('token') - } + }, + data: {} }; + + if (jsonStubHeaders != undefined && jsonStubHeaders != '') { + Object.assign(config.headers, JSON.parse(jsonStubHeaders)); + } + return config; }, getGroupByArea() { diff --git a/webpack.config.js b/webpack.config.js index 9738dca..7916925 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -40,6 +40,7 @@ var uglifyJsPlugin = new webpack.optimize.UglifyJsPlugin({ }); var definePlugin = new webpack.DefinePlugin({ + jsonStubHeaders: JSON.stringify(process.env.jsonStubHeaders || ''), HOST: JSON.stringify(process.env.HOST || 'http://localhost:3000'), 'process.env': { 'NODE_ENV': JSON.stringify('production') From 964213cf05e169732bde202f1ca3efa538dde8d2 Mon Sep 17 00:00:00 2001 From: Marco Araujo Date: Sun, 8 Jan 2017 15:51:42 -0200 Subject: [PATCH 3/7] Add globals --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 31da7b2..1c9dec6 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ ], "collectCoverage": true, "globals": { - "HOST": "http://localhost:3000" + "HOST": "http://localhost:3000", + "jsonStubHeaders": "{}" }, "moduleNameMapper": { "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/tests/__mocks__/fileMock.js", From d979d82e6a38be13b342c9db4784d880cd0089a2 Mon Sep 17 00:00:00 2001 From: Marco Araujo Date: Mon, 9 Jan 2017 20:44:21 -0200 Subject: [PATCH 4/7] Add coverage to json stub --- package.json | 2 +- tests/Area.test.js | 31 +++++++++++++++++++++++++++++++ tests/List.Area.test.js | 30 ++++++++++++++++++++++++++++++ tests/List.Client.test.js | 29 +++++++++++++++++++++++++++++ tests/Login.test.js | 31 +++++++++++++++++++++++++++++++ 5 files changed, 122 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1c9dec6..955a8fc 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "collectCoverage": true, "globals": { "HOST": "http://localhost:3000", - "jsonStubHeaders": "{}" + "jsonStubHeaders": "" }, "moduleNameMapper": { "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/tests/__mocks__/fileMock.js", diff --git a/tests/Area.test.js b/tests/Area.test.js index 008a66d..ca8535f 100644 --- a/tests/Area.test.js +++ b/tests/Area.test.js @@ -89,4 +89,35 @@ describe('Test Area', () => { }, 0); }); + it('Should show headers to stub json', (done) => { + + let response = require('AreasResponseMock').default; + let Area; + let component; + let mockAdapter = new MockAdapter(axios); + jsonStubHeaders = '{ "JsonStub-User-Key": "user-key", "JsonStub-Project-Key": "project-key" }'; + + mockAdapter.onGet(HOST + '/api/v1/visit/group/area').reply(200, response); + + Area = require('components/Area/Area').default; + + component = shallow( + + ); + + setTimeout(() => { + expect( + shallow( + component.state().areas[0] + ).find('.title').at(0).text() + ).toEqual('Center'); + expect( + shallow( + component.state().areas[1] + ).find('.title').at(0).text() + ).toEqual('South'); + done(); + }, 0); + }); + }); diff --git a/tests/List.Area.test.js b/tests/List.Area.test.js index e358bda..dfb21fe 100644 --- a/tests/List.Area.test.js +++ b/tests/List.Area.test.js @@ -101,5 +101,35 @@ describe('Test Area', () => { }, 0); }); + it('Should show headers to stub json', (done) => { + let response = { + areas: [ + {_id: 'South', parent: 'Center', ancestors: 'Center'}, + {_id: 'North', parent: 'Center', ancestors: 'Center'}, + ] + }; + let Area; + let component; + let mockAdapter = new MockAdapter(axios); + jsonStubHeaders = '{ "JsonStub-User-Key": "user-key", "JsonStub-Project-Key": "project-key" }'; + + mockAdapter.onGet(HOST + '/api/v1/area').reply(200, response); + + Area = require('components/Area/List/Area').default; + + component = shallow( + + ); + + setTimeout(() => { + try { + component.update(); + expect(component.find('tbody td').at(0).text()).toEqual('South'); + done(); + } catch (e) { + console.log(e); + } + }, 0); + }); }); diff --git a/tests/List.Client.test.js b/tests/List.Client.test.js index 7e1a576..be0cadc 100644 --- a/tests/List.Client.test.js +++ b/tests/List.Client.test.js @@ -89,5 +89,34 @@ describe('Test Client', () => { }, 0); }); + it('Should show headers to stub json', (done) => { + + let response = { + clients: [ + {name: 'Jon Snow', address: '7 Street', city: 'Winterfell'}, + {name: 'Cotter Pyke', address: '0 Street', city: 'Castle Black'}, + ] + }; + let Client; + let component; + let mockAdapter = new MockAdapter(axios); + jsonStubHeaders = '{ "JsonStub-User-Key": "user-key", "JsonStub-Project-Key": "project-key" }'; + + mockAdapter.onGet(HOST + '/api/v1/client').reply(200, response); + + Client = require('components/Client/List/Client').default; + + component = shallow( + + ); + + setTimeout(() => { + component.update(); + expect(component.find('tbody td').at(0).text()).toEqual('Jon Snow'); + expect(component.find('tbody td').at(1).text()).toEqual('7 Street - Winterfell'); + done(); + }, 0); + }); + }); diff --git a/tests/Login.test.js b/tests/Login.test.js index fdd4286..d47e6fa 100644 --- a/tests/Login.test.js +++ b/tests/Login.test.js @@ -161,5 +161,36 @@ describe('Test Login', () => { }, 0); }); + it('Should show headers to stub json', (done) => { + + let Login = require('components/Login/Login').default; + let response = { error:"User Not Found" }; + let mockAdapter = new MockAdapter(axios); + jsonStubHeaders = '{ "JsonStub-User-Key": "user-key", "JsonStub-Project-Key": "project-key" }'; + + mockAdapter.onPost(HOST + '/authenticate').reply(401, response); + + let component = mount( + , + { context } + ); + + let inputLogin = component.find('form div p input[type="text"]'); + let inputPassword = component.find('form div p input[type="password"]'); + + inputLogin.node.value = 'Astolfo'; + inputLogin.simulate('change', inputLogin); + + inputPassword.node.value = 'abcd'; + inputPassword.simulate('change', inputPassword); + + component.find('form').simulate('submit', { target: component.find('form').get(0) }); + + setTimeout(() => { + expect(component.state().error).toEqual('User Not Found'); + done(); + }, 0); + }); + }); From 5f315b9f6ff1d5066c1d543489713b25e1d6dc3e Mon Sep 17 00:00:00 2001 From: Gabriel Goncalves Date: Tue, 10 Jan 2017 19:43:42 -0200 Subject: [PATCH 5/7] * Improve message about offline on mobile --- app/components/IClient/styles.css | 14 ++++++++++++++ app/components/NavMenu/NavMenu.js | 29 ++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/components/IClient/styles.css b/app/components/IClient/styles.css index dab9c29..33d0997 100644 --- a/app/components/IClient/styles.css +++ b/app/components/IClient/styles.css @@ -3,3 +3,17 @@ background-color: #00d1b2; color: #333; } + +.withPadding { + padding-top: 30px; +} + +.withoutPadding { + padding-top: 0px; +} + +@media screen and (max-width: 768px) { + .body-primary { + padding-top: 30px; + } +} diff --git a/app/components/NavMenu/NavMenu.js b/app/components/NavMenu/NavMenu.js index c05ba92..625df10 100644 --- a/app/components/NavMenu/NavMenu.js +++ b/app/components/NavMenu/NavMenu.js @@ -7,6 +7,8 @@ class NavMenu extends React.Component constructor(props, context) { super(props, context); this.toggleNavStatus = this.toggleNavStatus.bind(this); + this.isMobile = this.isMobile.bind(this); + this.isNotMobile = this.isNotMobile.bind(this); this.hide = this.hide.bind(this); this.state = { toggleNavStatus: '' @@ -28,17 +30,38 @@ class NavMenu extends React.Component this.setState({toggleNavStatus: isActive}); } + isMobile() { + if (window.screen.width < 768) { + return this.showOfflineInfo(); + } + return ''; + } + + isNotMobile() { + if (window.screen.width > 768) { + return this.showOfflineInfo(); + } + return ''; + } + + showOfflineInfo() { + return ( + + + + ); + } + render() { return (