Skip to content
Merged
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
19 changes: 15 additions & 4 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
module.exports = {
"stories": ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
"addons": ["@storybook/addon-links", "@storybook/addon-essentials", "@storybook/addon-interactions"],
"stories": ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],

"addons": [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
"@storybook/addon-webpack5-compiler-babel",
"@chromatic-com/storybook"
],

"framework": {
name: "@storybook/react-webpack5",
options: {}
},
docs: {
autodocs: true

docs: {},

typescript: {
reactDocgen: "react-docgen-typescript"
}
};
4 changes: 2 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export const decorators = [(story, context) => {
}];

export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Action Logging May Be Affected by Removal of actions Parameter

No manual action declarations (actions:) were found in the story files. Removing the automatic actions parameter might lead to missing action logs in Storybook.

🔗 Analysis chain

Verify the removal of automatic action logging.

The actions property has been removed from the parameters object. This property was previously used to automatically add actions for props matching the regex pattern "^on[A-Z].*".

Please confirm if this removal was intentional. If so, consider the following:

  1. How will action logging be handled for components now?
  2. Is there a new strategy for managing actions in Storybook?
  3. Does this change align with the PR objective of enhancing testing?

If this removal was unintentional, consider restoring the actions property:

export const parameters = {
  controls: {
    matchers: {
      color: /(background|color)$/i,
      date: /Date$/,
    },
  },
+ actions: { argTypesRegex: "^on[A-Z].*" },
}

To verify the impact of this change, we can run the following script:

This script will help us understand if there are manual action declarations in place that might compensate for the removal of automatic action logging.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for manual action declarations in story files

# Search for manual action declarations in story files
echo "Searching for manual action declarations in story files:"
rg --type js --type ts 'actions:' src

Length of output: 721

export const tags = ["autodocs"];
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Unit Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/jest/bin/jest.js",
"--config",
"${workspaceRoot}/build/src/test/jest.config.js",
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"outFiles": ["${workspaceFolder}/build/**/*.js", "!**/node_modules/**"]
}
]
}
31 changes: 31 additions & 0 deletions __tests__/fixtures/participantInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ParticipantInfo } from "@careevolution/mydatahelps-js";

export const mockParticipantInfo : ParticipantInfo = {
participantID: "123",
participantIdentifier: "123",
secondaryIdentifier: "123",
linkIdentifier: "123",
demographics: {
city: 'Naples',
utcOffset: '-05:00:00',
email: "[email protected]",
firstName: "John",
lastName: "Doe",
mobilePhone: "1234567890",
state: "FL",
middleName: "",
dateOfBirth: "",
gender: "",
preferredLanguage: "",
street1: "",
street2: "",
postalCode: "",
unsubscribedFromEmails: "",
timeZone: "",
unsubscribedFromSms: ""
},
enrollmentDate: new Date().toString(),
projectID: "123",
customFields: {
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { awardConnectExternalAccountActivityPoints, ConnectExternalAccountActivity } from "../../../src/helpers/BasicPointsAndBadges/ConnectExternalAccountActivity";

jest.mock('@careevolution/mydatahelps-js', () => {

const externalAccounts = [{
"id" : 1,
"provider": { "id": 11, "name": "Garmin", "category": "Device Manufacturer"},
status: "fetchComplete"
},
{
"id" : 2,
"provider": { "id": 22, "name": "Fitbit", "category": "Device Manufacturer"},
status: "fetchComplete"
},
{
"id" : 3,
"provider": { "id": 22, "name": "FitBit", "category": "Device Manufacturer"} ,
status: "unauthorized"
},
{
"id" : 4,
"provider": { "id": 44, "name": "Health Plan 1", "category": "Health Plan"} ,
status: "fetchComplete"
}];

return {
__esModule: true,
default: {
token: { access_token: '1' },
getCurrentLanguage: () => jest.fn(),
getExternalAccounts: jest.fn(() => {
return Promise.resolve(externalAccounts);
}),
on: jest.fn(),
off: jest.fn()
}
}
});

describe("ConnectExternalAccountActivity Awards", () => {
it("should award points for connecting a single external account", async () => {
const activity = {
type: "connectExternalAccount",
points: 10,
providerCategories: ["Health Plan"]
} as ConnectExternalAccountActivity;
const activityState = {
pointsAwarded: 0,
providersConnected: []
};
const newActivityState = await awardConnectExternalAccountActivityPoints(activity, activityState);
expect(newActivityState.pointsAwarded).toBe(10);
expect(newActivityState.providersConnected).toEqual([44]);
});

it("should award points for connecting multiple external accounts", async () => {
const activity = {
type: "connectExternalAccount",
points: 10,
providerCategories: ["Health Plan", 'Provider', 'Device Manufacturer']
} as ConnectExternalAccountActivity;
const activityState = {
pointsAwarded: 0,
providersConnected: []
};
const newActivityState = await awardConnectExternalAccountActivityPoints(activity, activityState);
expect(newActivityState.pointsAwarded).toBe(30);
expect(newActivityState.providersConnected).toEqual([11, 22, 44]);
});

it("should NOT award points for multiple external accounts connected to same provider", async () => {
const activity = {
type: "connectExternalAccount",
points: 10,
providerCategories: ["Device Manufacturer"]
} as ConnectExternalAccountActivity;
const activityState = {
pointsAwarded: 0,
providersConnected: []
};
const newActivityState = await awardConnectExternalAccountActivityPoints(activity, activityState);
expect(newActivityState.pointsAwarded).toBe(20);
expect(newActivityState.providersConnected).toEqual([11, 22]);
});

it("should recalculate points across all providers. Awarding points should be based on newly connected", async () => {
const activity = {
type: "connectExternalAccount",
points: 10,
providerCategories: ["Health Plan"]
} as ConnectExternalAccountActivity;
const activityState = {
pointsAwarded: 20,
providersConnected: [1,2]
};
const newActivityState = await awardConnectExternalAccountActivityPoints(activity, activityState);
expect(newActivityState.pointsAwarded).toBe(30);
expect(newActivityState.providersConnected).toEqual([1, 2, 44]);
});

it("should NOT award points when the ppt does not have this provider connected", async () => {
const activity = {
type: "connectExternalAccount",
points: 10,
providerCategories: ["Provider"]
} as ConnectExternalAccountActivity;
const activityState = {
pointsAwarded: 0,
providersConnected: []
};
const newActivityState = await awardConnectExternalAccountActivityPoints(activity, activityState);
expect(newActivityState.pointsAwarded).toBe(0);
expect(newActivityState.providersConnected).toEqual([]);
});
});
47 changes: 47 additions & 0 deletions __tests__/helpers/BasicPointsAndBadges/CustomActivity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { mockParticipantInfo } from "../../fixtures/participantInfo";
import { awardCustomActivityPoints, CustomActivity } from "../../../src/helpers/BasicPointsAndBadges/CustomActivity";

describe("Custom Activity Awards", () => {
const pptInfo = {...mockParticipantInfo, customFields: { DailyGoals: "8" }};

it("should award points based on custom field value", async () => {
const activity : CustomActivity = {
key: "CustomGoals",
type: "custom",
points: 10,
customField: "DailyGoals"
};

const newActivityState = await awardCustomActivityPoints(activity, pptInfo);
expect(newActivityState.pointsAwarded).toBe(80);
});


it("should NOT award points where missing custom field value", async () => {
const activity : CustomActivity = {
key: "CustomGoals",
type: "custom",
points: 10,
customField: "DailyGoalsMissing"
};

const newActivityState = await awardCustomActivityPoints(activity, pptInfo);
expect(newActivityState.pointsAwarded).toBe(0);
});

it("should handle decimal values in custom field", async () => {
const pptInfoWithDecimal = {
...pptInfo,
customFields: { DailyGoals: "1.2" }
};
const activity: CustomActivity = {
key: "CustomGoals",
type: "custom",
points: 8,
customField: "DailyGoals"
};

const newActivityState = await awardCustomActivityPoints(activity, pptInfoWithDecimal);
expect(newActivityState.pointsAwarded).toBe(9.6);
});
});
1 change: 1 addition & 0 deletions amplify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ frontend:
- npm ci
build:
commands:
- npm run test
- npm run build-storybook
artifacts:
baseDirectory: /storybook-static/
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
testPathIgnorePatterns: ['/fixtures/']
};
Loading