Skip to content

Commit

Permalink
Make Mask Enum for easy future mask constants
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsummers1 committed Sep 25, 2024
1 parent a696229 commit 3a74db6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
9 changes: 6 additions & 3 deletions services/ui-src/src/components/fields/Integer.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React, { useState } from "react";
import PropTypes from "prop-types";
import { TextField } from "@cmsgov/design-system";
import { useSelector } from "react-redux";
import { TextField } from "@cmsgov/design-system";
//utils
import { generateQuestionNumber } from "../utils/helperFunctions";
import { Mask } from "util/constants";
//types
import PropTypes from "prop-types";

const getPrevYearValue = (question, lastYearFormData) => {
let prevYearValue;
Expand Down Expand Up @@ -70,7 +73,7 @@ const Integer = ({ onChange, question, prevYear, printView, ...props }) => {
const isLessThanElevenMask = (value) => {
return (
printView &&
question.mask === "lessThanEleven" &&
question.mask === Mask.lessThanEleven &&
value <= 10 &&
value > 0
);
Expand Down
7 changes: 4 additions & 3 deletions services/ui-src/src/components/fields/Integer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import configureMockStore from "redux-mock-store";
import { shallow, mount } from "enzyme";
import Integer from "./Integer";
import { screen, render, fireEvent } from "@testing-library/react";
import { Mask } from "util/constants";

const mockStore = configureMockStore();
const lastYearFormData = [
Expand Down Expand Up @@ -114,7 +115,7 @@ describe("<Integer />", () => {
id: "2023-00-a-01-01",
label: "Example Question",
answer: { entry: "5" },
mask: "lessThanEleven",
mask: Mask.lessThanEleven,
},
printView: true,
};
Expand All @@ -130,7 +131,7 @@ describe("<Integer />", () => {
id: "2023-00-a-01-01",
label: "Example Question",
answer: { entry: "12" },
mask: "lessThanEleven",
mask: Mask.lessThanEleven,
},
printView: true,
};
Expand All @@ -145,7 +146,7 @@ describe("<Integer />", () => {
id: "2023-00-a-01-01",
label: "Example Question",
answer: { entry: "0" },
mask: "lessThanEleven",
mask: Mask.lessThanEleven,
},
printView: true,
};
Expand Down
5 changes: 3 additions & 2 deletions services/ui-src/src/components/fields/SynthesizedTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { useSelector, shallowEqual } from "react-redux";
//utils
import synthesizeValue from "../../util/synthesize";
import { Mask } from "../../util/constants";
//types
import PropTypes from "prop-types";

Expand All @@ -21,7 +22,7 @@ const SynthesizedTable = ({ question, tableTitle, printView }) => {
const rows = question.fieldset_info.rows.map((row) => {
let contents = row;
if (printView) {
contents = row.filter((cell) => cell?.mask !== "lessThanEleven");
contents = row.filter((cell) => cell?.mask !== Mask.lessThanEleven);
}
return contents.map((cell) => {
const value = synthesizeValue(
Expand All @@ -41,7 +42,7 @@ const SynthesizedTable = ({ question, tableTitle, printView }) => {

const headers = printView
? question.fieldset_info.headers.filter(
(header) => header?.mask !== "lessThanEleven"
(header) => header?.mask !== Mask.lessThanEleven
)
: question.fieldset_info.headers;

Expand Down
3 changes: 2 additions & 1 deletion services/ui-src/src/components/fields/SynthesizedValue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useSelector, shallowEqual } from "react-redux";
import Question from "./Question";
//utils
import synthesizeValue from "../../util/synthesize";
import { Mask } from "util/constants";
//types
import PropTypes from "prop-types";

Expand All @@ -21,7 +22,7 @@ const SynthesizedValue = ({ question, printView, ...props }) => {
);

const showValue = !(
printView && question.fieldset_info.mask === "lessThanEleven"
printView && question.fieldset_info.mask === Mask.lessThanEleven
);

const renderValue = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
/* eslint-disable no-unused-vars */
// import.meta.env is threaded through here in order to mock it out for jest
export const { MODE, BASE_URL } = import.meta.env;

export enum Mask {
lessThanEleven = "lessThanEleven",
}

0 comments on commit 3a74db6

Please sign in to comment.