Skip to content

Commit d559d0e

Browse files
committed
fix: [AB#13064] remove edit button on deferred location question
1 parent a4f175d commit d559d0e

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

web/src/components/DeferredLocationQuestion.test.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,29 @@ describe("<DeferredLocationQuestion />", () => {
8383
expect(screen.queryByTestId("city-success-banner")).not.toBeInTheDocument();
8484
});
8585

86-
it("shows inner content without question nor success banner when already location saved", () => {
86+
it("shows inner content with success banner when already location saved", () => {
8787
const municipality = generateMunicipality({});
8888
const business = generateBusiness({ profileData: generateProfileData({ municipality }) });
8989
renderComponent({ initialBusiness: business, innerContent: "inner-content" });
9090
expect(screen.queryByText(Config.deferredLocation.header)).not.toBeInTheDocument();
9191
expect(screen.getByText("inner-content")).toBeInTheDocument();
92+
expect(screen.getByTestId("city-success-banner")).toBeInTheDocument();
93+
});
94+
95+
it("shows question form when Remove City is clicked from saved location", async () => {
96+
const municipality = generateMunicipality({ displayName: "Allendale" });
97+
const business = generateBusiness({ profileData: generateProfileData({ municipality }) });
98+
renderComponent({ initialBusiness: business, innerContent: "inner-content" });
99+
100+
expect(screen.getByTestId("city-success-banner")).toBeInTheDocument();
101+
expect(screen.getByText("inner-content")).toBeInTheDocument();
102+
expect(screen.queryByText(Config.deferredLocation.header)).not.toBeInTheDocument();
103+
104+
fireEvent.click(screen.getByText(Config.deferredLocation.removeText));
105+
106+
expect(screen.getByText(Config.deferredLocation.header)).toBeInTheDocument();
92107
expect(screen.queryByTestId("city-success-banner")).not.toBeInTheDocument();
108+
expect(screen.queryByText("inner-content")).not.toBeInTheDocument();
93109
});
94110

95111
describe("when saving location", () => {
@@ -122,22 +138,6 @@ describe("<DeferredLocationQuestion />", () => {
122138
expect(screen.getByText("inner-content")).toBeInTheDocument();
123139
});
124140

125-
it("shows location question when edit button is clicked", async () => {
126-
await selectNewarkAndSave();
127-
fireEvent.click(screen.getByText(Config.deferredLocation.editText));
128-
expect(screen.getByText(Config.deferredLocation.header)).toBeInTheDocument();
129-
expect(screen.queryByTestId("city-success-banner")).not.toBeInTheDocument();
130-
});
131-
132-
it("shows inner content when saving location after editing", async () => {
133-
await selectNewarkAndSave();
134-
fireEvent.click(screen.getByText(Config.deferredLocation.editText));
135-
selectLocationByText("Absecon");
136-
fireEvent.click(screen.getByText(Config.deferredLocation.deferredOnboardingSaveButtonText));
137-
await screen.findByTestId("city-success-banner");
138-
expect(screen.getByText("inner-content")).toBeInTheDocument();
139-
});
140-
141141
it("removes municipality from user profile when clicking remove button", async () => {
142142
await selectNewarkAndSave();
143143
fireEvent.click(screen.getByText(Config.deferredLocation.removeText));

web/src/components/DeferredLocationQuestion.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useUserData } from "@/lib/data-hooks/useUserData";
88
import analytics from "@/lib/utils/analytics";
99
import { templateEval } from "@/lib/utils/helpers";
1010
import { Business } from "@businessnjgovnavigator/shared/userData";
11-
import { ReactElement, ReactNode, useState } from "react";
11+
import { ReactElement, ReactNode } from "react";
1212

1313
interface Props {
1414
innerContent: string;
@@ -22,10 +22,8 @@ export const DeferredLocationQuestion = (props: Props): ReactElement => {
2222
const business = props.CMS_ONLY_fakeBusiness ?? userDataFromHook.business;
2323
const updateQueue = userDataFromHook.updateQueue;
2424

25-
const [showSuccessBanner, setShowSuccessBanner] = useState<boolean>(
26-
props.CMS_ONLY_showSuccessBanner ?? false,
27-
);
28-
const [showEditLocation, setShowEditLocation] = useState<boolean>(false);
25+
const showSuccessBanner =
26+
props.CMS_ONLY_showSuccessBanner ?? business?.profileData.municipality !== undefined;
2927

3028
const label = (
3129
<>
@@ -34,11 +32,9 @@ export const DeferredLocationQuestion = (props: Props): ReactElement => {
3432
</>
3533
);
3634

37-
const shouldShowQuestion = business?.profileData.municipality === undefined || showEditLocation;
35+
const shouldShowQuestion = business?.profileData.municipality === undefined;
3836

3937
const onSaveNewLocation = (): void => {
40-
setShowSuccessBanner(true);
41-
setShowEditLocation(false);
4238
business?.profileData.municipality === undefined &&
4339
updateQueue?.currentBusiness().profileData.municipality !== undefined &&
4440
analytics.event.task_location_question.submit.location_entered_for_first_time();
@@ -65,10 +61,6 @@ export const DeferredLocationQuestion = (props: Props): ReactElement => {
6561
})}
6662
</Content>
6763
</div>
68-
<UnStyledButton isUnderline onClick={(): void => setShowEditLocation(true)}>
69-
{Config.deferredLocation.editText}
70-
</UnStyledButton>
71-
<span className="margin-x-105">|</span>
7264
<UnStyledButton isUnderline onClick={onRemoveLocation}>
7365
{Config.deferredLocation.removeText}
7466
</UnStyledButton>

0 commit comments

Comments
 (0)