Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add diary entry plugin #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions diary-entry/__tests__/diaryentry-create.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import DiaryentriesCreateComponent from '../diaryentry-create.component';

describe('Diaryentry Create', function() {

beforeEach(angular.mock.module('ripple-ui'));

let scope, ctrl, controller, template, state;

beforeEach(inject(($injector, $controller, _$state_, _$stateParams_, _$ngRedux_, _diaryentriesActions_, _serviceRequests_) => {
controller = $controller;
scope = $injector.get('$rootScope').$new();
state = _$state_;

template = DiaryentriesCreateComponent.template;
ctrl = controller(DiaryentriesCreateComponent.controller, {
$scope: scope,
$state: state,
$stateParams: _$stateParams_,
$ngRedux: _$ngRedux_,
diaryentriesActions: _diaryentriesActions_,
serviceRequests: _serviceRequests_
});
}));

beforeEach(function() {
spyOn(ctrl, 'goList');
spyOn(ctrl, 'cancel');
spyOn(ctrl, 'setCurrentPageData');
spyOn(scope, 'actionLoadList');
spyOn(scope, 'actionCreateDetail');
spyOn(scope, 'create');

ctrl.goList();
ctrl.cancel();
ctrl.setCurrentPageData();
scope.actionLoadList();
scope.actionCreateDetail();
scope.create();
});

it('Template exist', function() {
expect(template).toBeDefined();
});
it('goList was called', function() {
expect(ctrl.goList).toHaveBeenCalled();
});
it('cancel was called', function() {
expect(ctrl.cancel).toHaveBeenCalled();
});
it('setCurrentPageData was called', function() {
expect(ctrl.setCurrentPageData).toHaveBeenCalled();
});

it('actionLoadList was called', function() {
expect(scope.actionLoadList).toHaveBeenCalled();
});
it('actionCreateDetail was called', function() {
expect(scope.actionCreateDetail).toHaveBeenCalled();
});
it('create was called', function() {
expect(scope.create).toHaveBeenCalled();
});
});
77 changes: 77 additions & 0 deletions diary-entry/__tests__/diaryentry-detail.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use strict';
import DiaryentriesCreateComponent from '../diaryentry-detail.component';

describe('Diaryentry Details', function() {

beforeEach(angular.mock.module('ripple-ui'));

let scope, ctrl, controller, template, stateParams, state, ngRedux, diaryentriesActions, usSpinnerService;

beforeEach(inject(($injector, $controller, _$state_, _$stateParams_, _$ngRedux_, _diaryentriesActions_, _usSpinnerService_) => {
controller = $controller;
scope = $injector.get('$rootScope').$new();
state = _$state_;
ngRedux = _$ngRedux_;
stateParams = _$stateParams_;
diaryentriesActions = _diaryentriesActions_;
usSpinnerService = _usSpinnerService_;

template = DiaryentriesCreateComponent.template;
ctrl = controller(DiaryentriesCreateComponent.controller, {
$scope: scope,
$state: state,
$stateParams: stateParams,
$ngRedux: ngRedux,
diaryentriesActions: diaryentriesActions,
usSpinnerService: usSpinnerService
});
}));

beforeEach(function() {
spyOn(ctrl, 'actionLoadList');
spyOn(ctrl, 'actionLoadDetail');
spyOn(ctrl, 'edit');
spyOn(ctrl, 'cancelEdit');
spyOn(ctrl, 'setCurrentPageData');
spyOn(scope, 'actionUpdateDetail');
spyOn(scope, 'confirmEdit');

ctrl.actionLoadList();
ctrl.actionLoadDetail();
ctrl.edit();
ctrl.cancelEdit();
ctrl.setCurrentPageData();
scope.actionUpdateDetail();
scope.confirmEdit();
});

it('Template exist', function() {
expect(template).toBeDefined();
});
it('Controller exist', function() {
expect(ctrl).toBeDefined();
});

it('actionLoadList was called', function() {
expect(ctrl.actionLoadList).toHaveBeenCalled();
});
it('actionLoadDetail was called', function() {
expect(ctrl.actionLoadDetail).toHaveBeenCalled();
});
it('edit was called', function() {
expect(ctrl.edit).toHaveBeenCalled();
});
it('cancelEdit was called', function() {
expect(ctrl.cancelEdit).toHaveBeenCalled();
});
it('setCurrentPageData was called', function() {
expect(ctrl.setCurrentPageData).toHaveBeenCalled();
});

it('actionUpdateDetail was called', function() {
expect(scope.actionUpdateDetail).toHaveBeenCalled();
});
it('confirmEdit was called', function() {
expect(scope.confirmEdit).toHaveBeenCalled();
});
});
94 changes: 94 additions & 0 deletions diary-entry/__tests__/diaryentry-list.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
'use strict';
import DiaryentryListComponent from '../diaryentry-list.component';
import * as types from '../action-types';
import diaryentry from '../diaryentry-actions';

describe('Diaryentry List', function() {

beforeEach(angular.mock.module('ripple-ui'));

let scope,
ctrl,
controller,
template,
stateParams,
state,
ngRedux,
diaryentriesActions,
serviceRequests,
usSpinnerService,
fakeCall,
actions;

beforeEach(inject(($injector, $controller, _$state_, _$stateParams_, _$ngRedux_, _diaryentriesActions_, _serviceRequests_, _usSpinnerService_) => {
controller = $controller;
scope = $injector.get('$rootScope').$new();
state = _$state_;
serviceRequests = _serviceRequests_;
ngRedux = _$ngRedux_;
stateParams = _$stateParams_;
diaryentriesActions = _diaryentriesActions_;
usSpinnerService = _usSpinnerService_;

template = DiaryentryListComponent.template;

ctrl = controller(DiaryentryListComponent.controller, {
$scope: scope,
$state: state,
$stateParams: stateParams,
$ngRedux: ngRedux,
diaryentriesActions: diaryentriesActions,
serviceRequests: serviceRequests,
usSpinnerService: usSpinnerService
});

actions = $injector.get('diaryentriesActions');
// scope.$digest();
}));

beforeEach(function() {
fakeCall = {
calldiaryentry: diaryentry
};

spyOn(fakeCall, 'calldiaryentry');

spyOn(ctrl, 'actionLoadList');
spyOn(ctrl, 'create');
spyOn(ctrl, 'go');
spyOn(ctrl, 'setCurrentPageData');

fakeCall.calldiaryentry({}, types.DIATY_ENTRIES);

ctrl.actionLoadList();
ctrl.create();
ctrl.go();
ctrl.setCurrentPageData();
});

it('Template exist', function() {
expect(template).toBeDefined();
});
it('Controller exist', function() {
expect(ctrl).toBeDefined();
});
it('Include diaryentriesActions in index actions file', function() {
expect(actions).toBeDefined();
});
it('Diaryentry reducer was called', function() {
expect(fakeCall.calldiaryentry).toHaveBeenCalled();
});

it('actionLoadList was called', function() {
expect(ctrl.actionLoadList).toHaveBeenCalled();
});
it('create was called', function() {
expect(ctrl.create).toHaveBeenCalled();
});
it('go was called', function() {
expect(ctrl.go).toHaveBeenCalled();
});
it('setCurrentPageData was called', function() {
expect(ctrl.setCurrentPageData).toHaveBeenCalled();
});
});
16 changes: 16 additions & 0 deletions diary-entry/action-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const DIATY_ENTRIES = 'DIATY_ENTRIES';
export const DIATY_ENTRIES_SUCCESS = 'DIATY_ENTRIES_SUCCESS';
export const DIATY_ENTRIES_ERROR = 'DIATY_ENTRIES_ERROR';
export const DIATY_ENTRIES__CLEAR = 'DIATY_ENTRIES__CLEAR';

export const DIATY_ENTRIES_GET = 'DIATY_ENTRIES_GET';
export const DIATY_ENTRIES_GET_SUCCESS = 'DIATY_ENTRIES_GET_SUCCESS';
export const DIATY_ENTRIES_GET_ERROR = 'DIATY_ENTRIES_GET_ERROR';

export const DIATY_ENTRIES_CREATE = 'DIATY_ENTRIES_CREATE';
export const DIATY_ENTRIES_CREATE_SUCCESS = 'DIATY_ENTRIES_CREATE_SUCCESS';
export const DIATY_ENTRIES_CREATE_ERROR = 'DIATY_ENTRIES_CREATE_ERROR';

export const DIATY_ENTRIES_UPDATE = 'DIATY_ENTRIES_UPDATE';
export const DIATY_ENTRIES_UPDATE_SUCCESS = 'DIATY_ENTRIES_UPDATE_SUCCESS';
export const DIATY_ENTRIES_UPDATE_ERROR = 'DIATY_ENTRIES_UPDATE_ERROR';
99 changes: 99 additions & 0 deletions diary-entry/diaryentry-actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
~ Copyright 2017 Ripple Foundation C.I.C. Ltd
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0

~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
*/

import { bindActionCreators } from 'redux';
import * as types from './action-types';

export function clear() {
return { type: types.DIATY_ENTRIES__CLEAR }
}
export function all(patientId) {
return {
types: [types.DIATY_ENTRIES, types.DIATY_ENTRIES_SUCCESS, types.DIATY_ENTRIES_ERROR],

shouldCallAPI: (state) => !state.diaryentries.response,

config: {
method: 'get',
url: '/api/patients/' + patientId + '/diaryentries'
},

meta: {
patientId: patientId,
timestamp: Date.now()
}
};
}
export function get(patientId, compositionId, source) {
return {
types: [types.DIATY_ENTRIES_GET, types.DIATY_ENTRIES_GET_SUCCESS, types.DIATY_ENTRIES_GET_ERROR],

shouldCallAPI: (state) => !state.diaryentries.response,

config: {
method: 'get',
url: '/api/patients/' + patientId + '/diaryentries/' + compositionId
},

meta: {
timestamp: Date.now()
}
};
}
export function create(patientId, composition) {
return {
types: [types.DIATY_ENTRIES_CREATE, types.DIATY_ENTRIES_CREATE_SUCCESS, types.DIATY_ENTRIES_CREATE_ERROR],

shouldCallAPI: (state) => !state.diaryentries.response,

config: {
method: 'post',
url: '/api/patients/' + patientId + '/diaryentries',
data: composition
},

meta: {
timestamp: Date.now()
}
};
}
export function update(patientId, sourceId, composition) {
return {
types: [types.DIATY_ENTRIES_UPDATE, types.DIATY_ENTRIES_UPDATE_SUCCESS, types.DIATY_ENTRIES_UPDATE_ERROR],

shouldCallAPI: (state) => !state.diaryentries.response,

config: {
method: 'put',
url: '/api/patients/' + patientId + '/diaryentries/' + sourceId,
data: composition
},

meta: {
timestamp: Date.now()
}
};
}

export default function diaryentriesActions($ngRedux) {
let actionCreator = {
all, clear, get, create, update
};

return bindActionCreators(actionCreator, $ngRedux.dispatch);
}

diaryentriesActions.$inject = ['$ngRedux'];
Loading