Skip to content

Commit

Permalink
Merge pull request #3085 from ONSdigital/EAR-2112-looping-grand-calcu…
Browse files Browse the repository at this point in the history
…lated-summary

EAR-2112 - Looping grand calculated summary
  • Loading branch information
sudeepkunhis authored Dec 13, 2023
2 parents 200fd2e + 836f416 commit 15a7fa1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Chip = styled(MenuItemType)`
color: ${colors.text};
float: right;
font-size: 0.8em;
margin-left: 0.8em;
`;

const CloseButton = styled.button`
Expand Down Expand Up @@ -76,13 +77,16 @@ const SelectedAnswer = ({
displayName,
properties,
type: answerType,
page,
insideListCollectorFolder,
onRemove,
}) => {
const unitType = properties.unit || false;

const [showDeleteModal, setShowDeleteModal] = useState(false);

const pageType = page?.pageType;

return (
<>
<Modal
Expand All @@ -95,6 +99,9 @@ const SelectedAnswer = ({
<Wrapper>
<Title>{displayName}</Title>
{unitType && <Chip data-test="unit-type">{unitType}</Chip>}
{pageType === "CalculatedSummaryPage" && (
<Chip>Calculated summary</Chip>
)}
{insideListCollectorFolder && <Chip>List collector follow-up</Chip>}
<Chip>{answerType}</Chip>
<CloseButton
Expand All @@ -114,6 +121,7 @@ SelectedAnswer.propTypes = {
type: PropType.string.isRequired,
insideListCollectorFolder: PropType.bool,
properties: PropType.object.isRequired, // eslint-disable-line
page: PropType.object, // eslint-disable-line
};

export default SelectedAnswer;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { render } from "tests/utils/rtl";
import SelectedAnswer from "./SelectedAnswer";

describe("Selected answer", () => {
let mockProperties, mockOnRemove, mockDisplayName, mockType;
let mockProperties, mockOnRemove, mockDisplayName, mockType, mockPage;

beforeEach(() => {
mockProperties = {
Expand Down Expand Up @@ -55,4 +55,41 @@ describe("Selected answer", () => {

expect(unitType).not.toBeInTheDocument();
});

it("displays the calculated summary page type", () => {
mockType = "Number";
mockPage = {
pageType: "CalculatedSummaryPage",
};

const { getByText } = render(
<SelectedAnswer
properties={mockProperties}
onRemove={mockOnRemove}
displayName={mockDisplayName}
type={mockType}
page={mockPage}
/>
);

const pageType = getByText("Calculated summary");
expect(pageType).toBeInTheDocument();
});

it("displays the list collector follow-up page type", () => {
mockType = "Number";

const { getByText } = render(
<SelectedAnswer
properties={mockProperties}
onRemove={mockOnRemove}
displayName={mockDisplayName}
type={mockType}
insideListCollectorFolder
/>
);

const pageType = getByText("List collector follow-up");
expect(pageType).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ AnswerSelector.fragments = {
properties
page {
id
pageType
folder {
id
... on ListCollectorFolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ mutation UpdateCalculatedSummaryPage(
page {
id
displayName
pageType
folder {
id
... on ListCollectorFolder {
listId
}
}
section {
id
displayName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("withUpdateCalculatedSummaryPage", () => {
props = mapMutateToProps({ mutate });
page = {
displayName: "123",
summaryAnswers: [],
summaryAnswers: [{ id: "1" }],
};
});

Expand All @@ -22,7 +22,7 @@ describe("withUpdateCalculatedSummaryPage", () => {
it("should call mutate", () => {
props.onUpdateCalculatedSummaryPage(page);
expect(mutate).toHaveBeenCalledWith({
variables: { input: { summaryAnswers: [] } },
variables: { input: { summaryAnswers: ["1"] } },
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const TableHeadCol = styled.div`

const VariableItem = styled(SubMenuItem)`
display: table-row;
height: 3.5em;
`;

const VariableItemList = styled.ul`
Expand Down

0 comments on commit 15a7fa1

Please sign in to comment.