Skip to content

Commit

Permalink
preserve capitalization of basal schedule or profiles names except fo…
Browse files Browse the repository at this point in the history
…r MedT + updated (& new) tests
  • Loading branch information
jebeck committed Nov 7, 2016
1 parent b8817e7 commit 211351b
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 69 deletions.
8 changes: 3 additions & 5 deletions src/components/settings/nontandem/NonTandem.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ const NonTandem = (props) => {
const schedules = data.getScheduleNames(pumpSettings.basalSchedules);

const tables = _.map(schedules, (schedule) => {
let scheduleName = pumpSettings.basalSchedules[schedule].name;
if (manufacturerKey === 'carelink') {
scheduleName = _.map(scheduleName.split(' '), (part) => (_.capitalize(part))).join(' ');
}
const scheduleName = pumpSettings.basalSchedules[schedule].name;
const label = data.getScheduleLabel(
scheduleName,
pumpSettings.activeSchedule,
deviceKey
);

if (pumpSettings.basalSchedules[schedule].name === pumpSettings.activeSchedule) {
if (scheduleName === pumpSettings.activeSchedule) {
return (
<div className={styles.categoryContainer} key={schedule}>
<CollapsibleContainer
Expand Down
2 changes: 1 addition & 1 deletion src/components/settings/tandem/Tandem.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Tandem = (props) => {
const tables = _.map(schedules, (schedule) => (
<div key={schedule.name}>
<CollapsibleContainer
label={data.getScheduleLabel(schedule.name, pumpSettings.activeSchedule, true)}
label={data.getScheduleLabel(schedule.name, pumpSettings.activeSchedule, deviceKey, true)}
labelClass={styles.collapsibleLabel}
openByDefault={schedule.name === pumpSettings.activeSchedule}
twoLineLabel={false}
Expand Down
15 changes: 11 additions & 4 deletions src/utils/settings/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,21 @@ export function getTotalBasalRates(scheduleData) {

/**
* getScheduleLabel
* @param {String} scheduleName basal schedule name
* @param {String} activeName basal name active at upload timestamp
* @param {String} scheduleName basal schedule name
* @param {String} activeName name of active basal schedule at time of upload
* @param {String} deviceKey one of: animas, carelink, insulet, medtronic, tandem
* @param {Boolean} noUnits whether units should be included in label object
*
* @return {Object} object representing basal schedule label
*/
export function getScheduleLabel(scheduleName, activeName, noUnits) {
export function getScheduleLabel(scheduleName, activeName, deviceKey, noUnits) {
const CAPITALIZED = ['carelink', 'medtronic'];
let displayName = scheduleName;
if (_.includes(CAPITALIZED, deviceKey)) {
displayName = _.map(scheduleName.split(' '), (part) => (_.capitalize(part))).join(' ');
}
return {
main: scheduleName,
main: displayName,
secondary: scheduleName === activeName ? 'Active at upload' : '',
units: noUnits ? '' : 'U/hr',
};
Expand Down
2 changes: 1 addition & 1 deletion test/components/settings/common/Header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Header', () => {
it('should expand to show serial number on click of device name', () => {
const wrapper = shallow(
<Header
deviceType="Testing"
deviceDisplayName="Testing"
deviceMeta={{ name: 'SN123', uploaded: 'Jul 12th 2016' }}
/>
);
Expand Down
86 changes: 65 additions & 21 deletions test/components/settings/nontandem/NonTandem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import { mount } from 'enzyme';
import { getChart } from '../../../../src/utils/settings/factory';
import { MGDL_UNITS } from '../../../../src/utils/constants';

const animasFlatRateData = require('../../../../data/pumpSettings/animas/flatrate.json');
const animasMultiRateData = require('../../../../data/pumpSettings/animas/multirate.json');
const omnipodFlatRateData = require('../../../../data/pumpSettings/omnipod/flatrate.json');
const omnipodMultiRateData = require('../../../../data/pumpSettings/omnipod/multirate.json');
const medtronicMultiRateData = require('../../../../data/pumpSettings/medtronic/multirate.json');

Expand All @@ -39,8 +41,8 @@ describe('NonTandem', () => {
console.error = sinon.stub();
mount(
<Animas
pumpSettings={animasMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={animasMultiRateData}
timePrefs={timePrefs}
/>
);
Expand All @@ -50,30 +52,30 @@ describe('NonTandem', () => {
it('should have a header', () => {
const wrapper = mount(
<Animas
pumpSettings={animasMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={animasMultiRateData}
timePrefs={timePrefs}
/>
);
expect(wrapper.find('Header')).to.have.length(1);
});

it('should have Animas as the Header deviceType', () => {
it('should have Animas as the Header deviceDisplayName', () => {
const wrapper = mount(
<Animas
pumpSettings={animasMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={animasMultiRateData}
timePrefs={timePrefs}
/>
);
expect(wrapper.find('Header').props().deviceType).to.equal('Animas');
expect(wrapper.find('Header').props().deviceDisplayName).to.equal('Animas');
});

it('should have four Tables', () => {
const wrapper = mount(
<Animas
pumpSettings={animasMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={animasMultiRateData}
timePrefs={timePrefs}
/>
);
Expand All @@ -83,19 +85,33 @@ describe('NonTandem', () => {
it('should have three CollapsibleContainers', () => {
const wrapper = mount(
<Animas
pumpSettings={animasMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={animasMultiRateData}
timePrefs={timePrefs}
/>
);
expect(wrapper.find('CollapsibleContainer')).to.have.length(3);
});

it('should preserve user capitalization of schedule name', () => {
const wrapper = mount(
<Animas
bgUnits={MGDL_UNITS}
pumpSettings={animasFlatRateData}
timePrefs={timePrefs}
/>
);
expect(wrapper.find('.label').someWhere(n => (n.text().search('normal') !== -1)))
.to.be.true;
expect(wrapper.find('.label').someWhere(n => (n.text().search('Weekday') !== -1)))
.to.be.true;
});

it('should have `Active at Upload` text somewhere', () => {
const wrapper = mount(
<Animas
pumpSettings={animasMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={animasMultiRateData}
timePrefs={timePrefs}
/>
);
Expand All @@ -110,8 +126,8 @@ describe('NonTandem', () => {
console.error = sinon.stub();
mount(
<Insulet
pumpSettings={omnipodMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={omnipodMultiRateData}
timePrefs={timePrefs}
/>
);
Expand All @@ -121,30 +137,30 @@ describe('NonTandem', () => {
it('should have a header', () => {
const wrapper = mount(
<Insulet
pumpSettings={omnipodMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={omnipodMultiRateData}
timePrefs={timePrefs}
/>
);
expect(wrapper.find('Header')).to.have.length(1);
});

it('should have OmniPod as the Header deviceType', () => {
it('should have OmniPod as the Header deviceDisplayName', () => {
const wrapper = mount(
<Insulet
pumpSettings={omnipodMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={omnipodMultiRateData}
timePrefs={timePrefs}
/>
);
expect(wrapper.find('Header').props().deviceType).to.equal('OmniPod');
expect(wrapper.find('Header').props().deviceDisplayName).to.equal('OmniPod');
});

it('should have four Tables', () => {
const wrapper = mount(
<Insulet
pumpSettings={omnipodMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={omnipodMultiRateData}
timePrefs={timePrefs}
/>
);
Expand All @@ -154,19 +170,31 @@ describe('NonTandem', () => {
it('should have two CollapsibleContainers', () => {
const wrapper = mount(
<Insulet
pumpSettings={omnipodMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={omnipodMultiRateData}
timePrefs={timePrefs}
/>
);
expect(wrapper.find('CollapsibleContainer')).to.have.length(2);
});

it('should preserve user capitalization of schedule name', () => {
const wrapper = mount(
<Insulet
bgUnits={MGDL_UNITS}
pumpSettings={omnipodFlatRateData}
timePrefs={timePrefs}
/>
);
expect(wrapper.find('.label').someWhere(n => (n.text().search('normal') !== -1)))
.to.be.true;
});

it('should have `Active at Upload` text somewhere', () => {
const wrapper = mount(
<Insulet
pumpSettings={omnipodMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={omnipodMultiRateData}
timePrefs={timePrefs}
/>
);
Expand All @@ -181,8 +209,8 @@ describe('NonTandem', () => {
console.error = sinon.stub();
mount(
<Medtronic
pumpSettings={medtronicMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={medtronicMultiRateData}
timePrefs={timePrefs}
/>
);
Expand All @@ -192,30 +220,46 @@ describe('NonTandem', () => {
it('should have a header', () => {
const wrapper = mount(
<Medtronic
pumpSettings={medtronicMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={medtronicMultiRateData}
timePrefs={timePrefs}
/>
);
expect(wrapper.find('Header')).to.have.length(1);
});

it('should have Medtronic as the Header deviceType', () => {
it('should have Medtronic as the Header deviceDisplayName', () => {
const wrapper = mount(
<Medtronic
bgUnits={MGDL_UNITS}
pumpSettings={medtronicMultiRateData}
timePrefs={timePrefs}
/>
);
expect(wrapper.find('Header').props().deviceDisplayName).to.equal('Medtronic');
});

it('should capitalize all basal schedule names', () => {
const wrapper = mount(
<Medtronic
bgUnits={MGDL_UNITS}
pumpSettings={medtronicMultiRateData}
timePrefs={timePrefs}
/>
);
expect(wrapper.find('Header').props().deviceType).to.equal('Medtronic');
expect(wrapper.find('.label').someWhere(n => (n.text().search('Standard') !== -1)))
.to.be.true;
expect(wrapper.find('.label').someWhere(n => (n.text().search('Pattern A') !== -1)))
.to.be.true;
expect(wrapper.find('.label').someWhere(n => (n.text().search('Pattern B') !== -1)))
.to.be.true;
});

it('should have `Active at Upload` text somewhere', () => {
const wrapper = mount(
<Medtronic
pumpSettings={medtronicMultiRateData}
bgUnits={MGDL_UNITS}
pumpSettings={medtronicMultiRateData}
timePrefs={timePrefs}
/>
);
Expand Down
Loading

0 comments on commit 211351b

Please sign in to comment.