-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DIA-927): conditionally display email enrollment checkbox during…
… sign-up (#11020) * conditionally display email enrollment checkbox during sign-up * added tests for automatic email subscription * code review
- Loading branch information
Showing
7 changed files
with
211 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { useCountryCodeQuery } from "__generated__/useCountryCodeQuery.graphql" | ||
import { useClientQuery } from "app/utils/useClientQuery" | ||
import { useEffect, useState } from "react" | ||
import { getIpAddress } from "react-native-device-info" | ||
import { graphql } from "react-relay" | ||
|
||
const USE_COUNTRY_CODE_QUERY = graphql` | ||
query useCountryCodeQuery($ip: String!) { | ||
requestLocation(ip: $ip) { | ||
countryCode | ||
} | ||
} | ||
` | ||
|
||
export const useCountryCode = () => { | ||
const [ip, setIp] = useState("0.0.0.0") | ||
|
||
useEffect(() => { | ||
getIpAddress().then((ip) => { | ||
setIp(ip) | ||
}) | ||
}, []) | ||
|
||
const { data, loading, error } = useClientQuery<useCountryCodeQuery>({ | ||
query: USE_COUNTRY_CODE_QUERY, | ||
variables: { | ||
ip, | ||
}, | ||
cacheConfig: { | ||
networkCacheConfig: { | ||
force: false, | ||
}, | ||
}, | ||
}) | ||
|
||
const countryCode = data?.requestLocation?.countryCode | ||
|
||
const isAutomaticallySubscribed = !!(countryCode && !GDPR_COUNTRY_CODES.includes(countryCode)) | ||
|
||
return { | ||
countryCode, | ||
error, | ||
isAutomaticallySubscribed, | ||
loading, | ||
} | ||
} | ||
|
||
export const GDPR_COUNTRY_CODES = [ | ||
"AT", | ||
"BE", | ||
"BG", | ||
"CY", | ||
"CZ", | ||
"DE", | ||
"DK", | ||
"EE", | ||
"ES", | ||
"FI", | ||
"FR", | ||
"GB", | ||
"GR", | ||
"HR", | ||
"HU", | ||
"IE", | ||
"IT", | ||
"LT", | ||
"LU", | ||
"LV", | ||
"MT", | ||
"NL", | ||
"PL", | ||
"PT", | ||
"RO", | ||
"SE", | ||
"SI", | ||
"SK", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
src/app/Scenes/Onboarding/Auth2/scenes/__tests__/SignUpNameStep.test.tsx
This file was deleted.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
src/app/Scenes/Onboarding/Auth2/scenes/__tests__/SignUpNameStep.tests.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { fireEvent, screen, waitFor } from "@testing-library/react-native" | ||
import { useCountryCode } from "app/Scenes/Onboarding/Auth2/hooks/useCountryCode" | ||
import { SignUpNameStep } from "app/Scenes/Onboarding/Auth2/scenes/SignUpNameStep" | ||
import { GlobalStore } from "app/store/GlobalStore" | ||
import { renderWithWrappers } from "app/utils/tests/renderWithWrappers" | ||
|
||
jest.mock("@artsy/palette-mobile", () => ({ | ||
...jest.requireActual("@artsy/palette-mobile"), | ||
useTheme: jest.fn().mockReturnValue({ | ||
color: jest.fn(), | ||
}), | ||
})) | ||
|
||
const mockUseCountryCode = useCountryCode as jest.Mock | ||
|
||
jest.mock("app/Scenes/Onboarding/Auth2/hooks/useCountryCode", () => ({ | ||
useCountryCode: jest.fn().mockReturnValue({ | ||
loading: false, | ||
isAutomaticallySubscribed: false, | ||
}), | ||
})) | ||
|
||
jest.mock("app/Scenes/Onboarding/Auth2/hooks/useAuthNavigation", () => ({ | ||
useAuthNavigation: jest.fn(), | ||
useAuthScreen: jest.fn().mockReturnValue({ | ||
currentScreen: "SignUpNameStep", | ||
}), | ||
})) | ||
|
||
jest.mock("app/store/GlobalStore", () => ({ | ||
...jest.requireActual("app/store/GlobalStore"), | ||
GlobalStore: { | ||
...jest.requireActual("app/store/GlobalStore").GlobalStore, | ||
actions: { | ||
auth: { | ||
signUp: jest.fn(), | ||
}, | ||
}, | ||
}, | ||
})) | ||
|
||
describe("SignUpNameStep", () => { | ||
it("renders the full name input", () => { | ||
renderWithWrappers(<SignUpNameStep />) | ||
|
||
expect(screen.getByA11yHint("Enter your full name")).toBeTruthy() | ||
}) | ||
|
||
it("renders the terms and privacy policy checkbox", () => { | ||
renderWithWrappers(<SignUpNameStep />) | ||
|
||
expect( | ||
screen.getByA11yHint("Check this element to accept Artsy's terms and privacy policy") | ||
).toBeTruthy() | ||
}) | ||
|
||
it("renders the email subscription checkbox", () => { | ||
renderWithWrappers(<SignUpNameStep />) | ||
|
||
expect(screen.getByA11yHint("Check this element to receive Artsy's emails")).toBeTruthy() | ||
}) | ||
|
||
describe("user is automatically subscribed", () => { | ||
beforeEach(() => { | ||
mockUseCountryCode.mockReturnValue({ | ||
isAutomaticallySubscribed: true, | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it("does not render the email opt-in checkbox if the user is automatically subscribed", () => { | ||
renderWithWrappers(<SignUpNameStep />) | ||
|
||
expect(screen.queryByA11yHint("Check this element to receive Artsy's emails")).toBeNull() | ||
}) | ||
|
||
it("agrees to receive emails if the user is automatically ", async () => { | ||
renderWithWrappers(<SignUpNameStep />) | ||
|
||
fireEvent.changeText(screen.getByA11yHint("Enter your full name"), "Percy Cat") | ||
fireEvent.press( | ||
screen.getByA11yHint("Check this element to accept Artsy's terms and privacy policy") | ||
) | ||
|
||
fireEvent.press(screen.getByText("Continue")) | ||
|
||
await waitFor(() => { | ||
expect(GlobalStore.actions.auth.signUp).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
agreedToReceiveEmails: true, | ||
}) | ||
) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters