Skip to content

Commit

Permalink
Merge pull request #1345 from RoundingWell/ws-flow-page-msgs
Browse files Browse the repository at this point in the history
Handle `ActionDueChanged`, `ActionDurationChanged`, `NameChanged` ws messages on flow page
  • Loading branch information
paulfalgout authored Oct 31, 2024
2 parents a3fbaf5 + c198a5f commit a4175c7
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/js/entities-service/entities/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ const _Model = BaseModel.extend({
StateChanged({ state, attributes = {} }) {
this.set({ _state: state.id, ...attributes });
},
ActionDueChanged({ due_date, due_time, attributes = {} }) {
this.set({ due_date, due_time, ...attributes });
},
ActionDurationChanged({ duration, attributes = {} }) {
this.set({ duration, ...attributes });
},
NameChanged({ name, attributes = {} }) {
this.set({ name, ...attributes });
},
},
urlRoot() {
if (this.isNew()) {
Expand Down
3 changes: 3 additions & 0 deletions src/js/entities-service/entities/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const _Model = BaseModel.extend({
StateChanged({ state, attributes = {} }) {
this.set({ _state: state.id, ...attributes });
},
NameChanged({ name, attributes = {} }) {
this.set({ name, ...attributes });
},
},
urlRoot() {
if (this.isNew()) return `/api/patients/${ this.get('_patient') }/relationships/flows`;
Expand Down
104 changes: 98 additions & 6 deletions test/integration/patients/patient/patient-flow.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import _ from 'underscore';

import { testTs, testTsSubtract } from 'helpers/test-timestamp';
import { testDateAdd, testDateSubtract } from 'helpers/test-date';
import { testDate, testDateAdd, testDateSubtract } from 'helpers/test-date';
import formatDate from 'helpers/format-date';
import { getErrors, getRelationship, mergeJsonApi } from 'helpers/json-api';

import { getFlow } from 'support/api/flows';
Expand Down Expand Up @@ -103,30 +104,67 @@ context('patient flow page', function() {
});

specify('patient flow action sidebar', function() {
const testFlowAction = getAction({
attributes: {
name: 'Test Action',
duration: 10,
},
relationships: {
flow: getRelationship(testFlow),
state: getRelationship(stateTodo),
owner: getRelationship(teamNurse),
},
});

cy
.routesForPatientAction()
.routeFlow(fx => {
fx.data = testFlow;
fx.data = mergeJsonApi(testFlow, {
relationships: {
state: getRelationship(stateTodo),
},
});

return fx;
})
.routeFlowActions(fx => {
fx.data = [testFlowAction];

return fx;
})
.routeFlowActions()
.routeAction(fx => {
fx.data = testAction;
fx.data = testFlowAction;

return fx;
})
.routePatientByFlow()
.routeActionActivity()
.visit(`/flow/${ testFlow.id }/action/${ testAction.id }`)
.visit(`/flow/${ testFlow.id }/action/${ testFlowAction.id }`)
.wait('@routeFlow')
.wait('@routePatientByFlow')
.wait('@routeFlowActions');
.wait('@routeFlowActions')
.wait('@routeAction');

cy
.get('.sidebar')
.find('[data-action-region] .action-sidebar__name')
.should('contain', 'Test Action');

cy.sendWs({
category: 'ActionDurationChanged',
resource: {
type: 'patient-actions',
id: testFlowAction.id,
},
payload: {
duration: 20,
},
});

cy
.get('.sidebar')
.find('[data-duration-region]')
.should('contain', '20 mins');
});

specify('done patient flow action sidebar', function() {
Expand Down Expand Up @@ -2181,6 +2219,8 @@ context('patient flow page', function() {
const testSocketAction = getAction({
attributes: {
name: 'Action Test',
due_date: testDate(),
due_time: '06:00:00',
},
relationships: {
flow: getRelationship(testSocketFlow),
Expand Down Expand Up @@ -2216,6 +2256,58 @@ context('patient flow page', function() {
getRelationship(testSocketAction).data,
]);

cy.sendWs({
category: 'NameChanged',
resource: {
type: 'flows',
id: testSocketFlow.id,
},
payload: {
name: 'New Flow Name',
},
});

cy
.get('[data-header-region]')
.find('.patient-flow__name')
.contains('New Flow Name');

cy.sendWs({
category: 'NameChanged',
resource: {
type: 'patient-actions',
id: testSocketAction.id,
},
payload: {
name: 'New Action Name',
},
});

cy
.get('.patient-flow__list')
.find('.table-list__item .patient__action-name')
.contains('New Action Name');

cy.sendWs({
category: 'ActionDueChanged',
resource: {
type: 'patient-actions',
id: testSocketAction.id,
},
payload: {
due_date: testDateAdd(1),
due_time: '07:00:00',
},
});

cy
.get('.patient-flow__list')
.find('.table-list__item')
.should($action => {
expect($action.find('[data-due-date-region]')).to.contain(formatDate(testDateAdd(1), 'SHORT'));
expect($action.find('[data-due-time-region]')).to.contain('7:00 AM');
});

cy
.get('.patient-flow__progress')
.should('have.value', 0);
Expand Down

0 comments on commit a4175c7

Please sign in to comment.