-
Notifications
You must be signed in to change notification settings - Fork 2
fix: APM phone field — required validation + { dialing_code, number } alignment #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
roshan-gorasia-cko
wants to merge
5
commits into
master
Choose a base branch
from
fix/apm-phone-required-validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ae6e265
fix: enforce required validation on APM phone field
roshan-gorasia-cko fb03ab0
fix: align APM phone value to the API's { dialing_code, number } shape
roshan-gorasia-cko fa0d03c
fix: coerce numeric phone prefill and clarify InitialData docs
roshan-gorasia-cko f775126
docs: clarify test navigator shim default in loader
roshan-gorasia-cko 9a2bd67
fix: render prefilled APM phone value in the input
roshan-gorasia-cko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -27,5 +27,8 @@ jobs: | |
| - name: Lint | ||
| run: yarn lint | ||
|
|
||
| - name: Test | ||
| run: yarn test | ||
|
|
||
| - name: Build | ||
| run: yarn build | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,79 @@ | ||
| import { describe, expect, it } from "vitest" | ||
| import { loadApmUtils } from "../support/loadNamespace" | ||
|
|
||
| const { getComparableFieldValue } = loadApmUtils() | ||
|
|
||
| /** | ||
| * Regression coverage for the phone "required" validation bug: the Phone | ||
| * component emits its value under `number`, while the initial/prefilled seed | ||
| * uses `value`. The validator normalises both via getComparableFieldValue, so | ||
| * an empty phone number is recognised as empty regardless of which shape is | ||
| * present (previously the `number` shape was treated as a non-empty object and | ||
| * the required check silently passed). | ||
| */ | ||
| describe("getComparableFieldValue", () => { | ||
| it("returns primitives unchanged", () => { | ||
| expect(getComparableFieldValue("hello")).toBe("hello") | ||
| expect(getComparableFieldValue("")).toBe("") | ||
| expect(getComparableFieldValue(0)).toBe(0) | ||
| expect(getComparableFieldValue(undefined)).toBe(undefined) | ||
| }) | ||
|
|
||
| it("reads the number from the seed/prefill `value` shape", () => { | ||
| expect( | ||
| getComparableFieldValue({ dialing_code: "+44", value: "7911123456" }), | ||
| ).toBe("7911123456") | ||
| expect(getComparableFieldValue({ dialing_code: "+44", value: "" })).toBe("") | ||
| }) | ||
|
|
||
| it("reads the number from the emitted `number` shape", () => { | ||
| expect( | ||
| getComparableFieldValue({ dialing_code: "+44", number: "7911123456" }), | ||
| ).toBe("7911123456") | ||
| }) | ||
|
|
||
| it("returns an empty string for a cleared `number` (the reported bug)", () => { | ||
| // Shopper typed a number then removed it: the value is now { number: "" }. | ||
| // This must resolve to "" so the required check fires. | ||
| expect(getComparableFieldValue({ dialing_code: "+44", number: "" })).toBe("") | ||
| }) | ||
|
|
||
| it("prefers the canonical `number` when both keys are present", () => { | ||
| expect( | ||
| getComparableFieldValue({ value: "from-value", number: "from-number" }), | ||
| ).toBe("from-number") | ||
| }) | ||
|
|
||
| it("returns the object unchanged when neither key is present", () => { | ||
| const obj = { dialing_code: "+44" } | ||
| expect(getComparableFieldValue(obj)).toBe(obj) | ||
| }) | ||
| }) | ||
|
|
||
| /** | ||
| * Mirrors form.ts validateField's required rule against the normalised value, | ||
| * documenting the end-to-end expectation the SDK relies on. | ||
| */ | ||
| function isMissingRequired(value: unknown): boolean { | ||
| const actualValue = getComparableFieldValue(value) | ||
| return ( | ||
| typeof value === "undefined" || | ||
| (typeof actualValue === "string" && actualValue.length === 0) | ||
| ) | ||
| } | ||
|
|
||
| describe("required check on phone values", () => { | ||
| it("flags an empty phone number in either shape", () => { | ||
| expect(isMissingRequired({ dialing_code: "+44", value: "" })).toBe(true) | ||
| expect(isMissingRequired({ dialing_code: "+44", number: "" })).toBe(true) | ||
| }) | ||
|
|
||
| it("accepts a provided phone number in either shape", () => { | ||
| expect(isMissingRequired({ dialing_code: "+44", value: "7911123456" })).toBe( | ||
| false, | ||
| ) | ||
| expect( | ||
| isMissingRequired({ dialing_code: "+44", number: "7911123456" }), | ||
| ).toBe(false) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.