Skip to content

Commit

Permalink
fix:default value for PhoneInput set to text which is invalid(#34594)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshithazemoso committed Jul 5, 2024
1 parent cc6bc16 commit 18261b7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
agHelper,
locators,
entityExplorer,
propPane,
} from "../../../../../support/Objects/ObjectsCore";
const commonlocators = require("../../../../../locators/commonlocators.json");

describe(
"Phone Input widget Tests",
{ tags: ["@tag.Widget", "@tag.PhoneInput"] },
function () {
before(() => {
entityExplorer.DragDropWidgetNVerify("phoneinputwidget", 550, 100);
});

it("1.Verify with text widget when number is default value", () => {
agHelper.UpdateCodeInput(propPane._propertyContentDefaultValueField, '9872139');
entityExplorer.DragDropWidgetNVerify("textwidget", 550, 300);
propPane.UpdatePropertyFieldValue("Text", "{{PhoneInput1.text}}");
agHelper.ClickOutside();
agHelper.GetNAssertContains(commonlocators.textwidget,"(987) 213-9")
});
it("2.Verify that error is shown when default value is not a number",() =>{
agHelper.GetNClick(locators._input);
agHelper.UpdateCodeInput(propPane._propertyContentDefaultValueField, 'jkwhejw');
agHelper.VerifyEvaluatedErrorMessage('This value must be number');
})
},
);

1 change: 1 addition & 0 deletions app/client/cypress/support/Pages/PropertyPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export class PropertyPane {
_dataIcon = (icon: string) => `[data-icon="${icon}"]`;
_iconDropdown = "[data-test-id='virtuoso-scroller']";
_dropdownControlError = "[data-testid='t---dropdown-control-error']";
_propertyContentDefaultValueField = ".t--property-control-defaultvalue";

public OpenJsonFormFieldSettings(fieldName: string) {
this.agHelper.GetNClick(this._jsonFieldEdit(fieldName));
Expand Down
12 changes: 12 additions & 0 deletions app/client/src/widgets/PhoneInputWidget/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export function defaultValueValidation(
name: "TypeError",
message: "This value must be string",
};
const NUMBER_ERROR_MESSAGE = {
name: "TypeError",
message: "This value must be number",
};
const EMPTY_ERROR_MESSAGE = { name: "", message: "" };
if (_.isObject(value)) {
return {
Expand All @@ -72,6 +76,14 @@ export function defaultValueValidation(
};
}
}
const parsedValue: any = Number(value);
if (!Number.isFinite(parsedValue)) {
return {
isValid: false,
parsed: undefined,
messages: [NUMBER_ERROR_MESSAGE],
};
}
return {
isValid: _.isString(parsed),
parsed: parsed,
Expand Down

0 comments on commit 18261b7

Please sign in to comment.