From 5bb924b96d9d42b4291eb6ed841c9e1a4bdcd8aa Mon Sep 17 00:00:00 2001 From: amitbadala Date: Wed, 15 Nov 2023 14:45:52 +0530 Subject: [PATCH 01/18] Show required sign only if label is valid --- lib/build/emailpassword-shared7.js | 2 +- lib/ts/recipe/emailpassword/components/library/label.tsx | 2 +- test/end-to-end/signup.test.js | 6 ++++++ test/end-to-end/thirdpartyemailpassword.test.js | 7 +++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/build/emailpassword-shared7.js b/lib/build/emailpassword-shared7.js index db90a2acb..018028673 100644 --- a/lib/build/emailpassword-shared7.js +++ b/lib/build/emailpassword-shared7.js @@ -425,7 +425,7 @@ function Label(_a) { "div", genericComponentOverrideContext.__assign( { "data-supertokens": "label" }, - { children: [t(value), showIsRequired && " *"] } + { children: [t(value), showIsRequired && value !== "" && " *"] } ) ); } diff --git a/lib/ts/recipe/emailpassword/components/library/label.tsx b/lib/ts/recipe/emailpassword/components/library/label.tsx index 5096b636a..319b04760 100644 --- a/lib/ts/recipe/emailpassword/components/library/label.tsx +++ b/lib/ts/recipe/emailpassword/components/library/label.tsx @@ -26,7 +26,7 @@ export default function Label({ value, showIsRequired }: LabelProps): JSX.Elemen return (
{t(value)} - {showIsRequired && " *"} + {showIsRequired && value !== "" && " *"}
); } diff --git a/test/end-to-end/signup.test.js b/test/end-to-end/signup.test.js index 1285e6ec0..b7cae7bc3 100644 --- a/test/end-to-end/signup.test.js +++ b/test/end-to-end/signup.test.js @@ -367,6 +367,12 @@ describe("SuperTokens SignUp", function () { // check if checbox is loaded const checkboxExists = await waitForSTElement(page, 'input[type="checkbox"]'); assert.ok(checkboxExists, "Checkbox exists"); + + // check if labels are loaded correctly + // non-optional field with empty labels should'nt show * sign + const expectedLabels = ["Email *", "Password *", "Select Dropdown", ""]; + const labelNames = await getLabelsText(page); + assert.deepStrictEqual(labelNames, expectedLabels); }); it("Should show error messages, based on optional flag", async function () { diff --git a/test/end-to-end/thirdpartyemailpassword.test.js b/test/end-to-end/thirdpartyemailpassword.test.js index bff13ae99..9779b00fd 100644 --- a/test/end-to-end/thirdpartyemailpassword.test.js +++ b/test/end-to-end/thirdpartyemailpassword.test.js @@ -46,6 +46,7 @@ import { backendBeforeEach, setSelectDropdownValue, getInputField, + getLabelsText, } from "../helpers"; import { TEST_CLIENT_BASE_URL, @@ -531,6 +532,12 @@ describe("SuperTokens Third Party Email Password", function () { // check if checbox is loaded const checkboxExists = await waitForSTElement(page, 'input[type="checkbox"]'); assert.ok(checkboxExists, "Checkbox exists"); + + // check if labels are loaded correctly + // non-optional field with empty labels should'nt show * sign + const expectedLabels = ["Email *", "Password *", "Select Dropdown", ""]; + const labelNames = await getLabelsText(page); + assert.deepStrictEqual(labelNames, expectedLabels); }); it("Should show error messages, based on optional flag", async function () { From 3907af90de507d3bab83e0f21d5257dbc7385f34 Mon Sep 17 00:00:00 2001 From: amitbadala Date: Thu, 16 Nov 2023 11:16:55 +0530 Subject: [PATCH 02/18] Better func names & consistent return type --- examples/for-tests/src/App.js | 48 ++++++++++++++++------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/examples/for-tests/src/App.js b/examples/for-tests/src/App.js index 62b155995..29d292a39 100644 --- a/examples/for-tests/src/App.js +++ b/examples/for-tests/src/App.js @@ -713,7 +713,7 @@ function getEmailVerificationConfigs({ disableDefaultUI }) { }); } -function getFormFields() { +function getSignUpFormFields() { if (localStorage.getItem("SHOW_INCORRECT_FIELDS") === "YES") { if (localStorage.getItem("INCORRECT_ONCHANGE") === "YES") { // since page-error blocks all the other errors @@ -737,29 +737,25 @@ function getSignInFormFields() { let showDefaultFields = localStorage.getItem("SHOW_SIGNIN_DEFAULT_FIELDS"); let showFieldsWithNonOptionalErrMsg = localStorage.getItem("SHOW_SIGNIN_WITH_NON_OPTIONAL_ERROR_MESSAGE"); if (showDefaultFields === "YES") { - return { - formFields: [ - { - id: "email", - getDefaultValue: () => "abc@xyz.com", - }, - { - id: "password", - getDefaultValue: () => "fakepassword123", - }, - ], - }; + return [ + { + id: "email", + getDefaultValue: () => "abc@xyz.com", + }, + { + id: "password", + getDefaultValue: () => "fakepassword123", + }, + ]; } else if (showFieldsWithNonOptionalErrMsg === "YES") { - return { - formFields: [ - { - id: "email", - nonOptionalErrorMsg: "Please add email", - }, - ], - }; + return [ + { + id: "email", + nonOptionalErrorMsg: "Please add email", + }, + ]; } - return {}; + return []; } function getEmailPasswordConfigs({ disableDefaultUI }) { @@ -842,13 +838,13 @@ function getEmailPasswordConfigs({ disableDefaultUI }) { defaultToSignUp, signInForm: { style: theme, - ...getSignInFormFields(), + formFields: getSignInFormFields(), }, signUpForm: { style: theme, privacyPolicyLink: "https://supertokens.com/legal/privacy-policy", termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions", - formFields: getFormFields(), + formFields: getSignUpFormFields(), }, }, }); @@ -1372,10 +1368,10 @@ function getThirdPartyEmailPasswordConfigs({ staticProviderList, disableDefaultU signInAndUpFeature: { disableDefaultUI, signInForm: { - ...getSignInFormFields(), + formFields: getSignInFormFields(), }, signUpForm: { - formFields: getFormFields(), + formFields: getSignUpFormFields(), privacyPolicyLink: "https://supertokens.com/legal/privacy-policy", termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions", }, From 354a1522a8d5d189a678eae6a6204f20b27c1ec3 Mon Sep 17 00:00:00 2001 From: amitbadala Date: Thu, 16 Nov 2023 12:40:24 +0530 Subject: [PATCH 03/18] Use assert instead of throw error --- test/end-to-end/signin.test.js | 21 +++---------- test/end-to-end/signup.test.js | 57 +++++++++++----------------------- 2 files changed, 23 insertions(+), 55 deletions(-) diff --git a/test/end-to-end/signin.test.js b/test/end-to-end/signin.test.js index 160a66c09..6ecdd81fa 100644 --- a/test/end-to-end/signin.test.js +++ b/test/end-to-end/signin.test.js @@ -714,11 +714,8 @@ describe("SuperTokens SignIn", function () { const postData = JSON.parse(request.postData()); expectedDefautlValues.forEach(({ id, value }) => { let findFormData = postData.formFields.find((inputData) => inputData.id === id); - if (findFormData) { - assert.strictEqual(findFormData["value"], value, `Mismatch in payload for key: ${id}`); - } else { - throw new Error("Field not found in req.data"); - } + assert.ok(findFormData, "Field not found in req.data"); + assert.strictEqual(findFormData["value"], value, `Mismatch in payload for key: ${id}`); }); interceptionPassed = true; return request.respond({ @@ -748,14 +745,8 @@ describe("SuperTokens SignIn", function () { page.off("request", requestHandler); await page.setRequestInterception(false); } - - if (assertionError) { - throw assertionError; - } - - if (!interceptionPassed) { - throw new Error("test failed"); - } + assert.ok(!assertionError, assertionError?.message); + assert.ok(interceptionPassed, "Test Failed"); }); }); @@ -797,9 +788,7 @@ describe("SuperTokens SignIn", function () { await page.setRequestInterception(false); } - if (apiCallMade) { - throw new Error("Empty form making API request to signin"); - } + assert.ok(!apiCallMade, "Empty form making API request to signin"); }); }); }); diff --git a/test/end-to-end/signup.test.js b/test/end-to-end/signup.test.js index b7cae7bc3..726d98fd4 100644 --- a/test/end-to-end/signup.test.js +++ b/test/end-to-end/signup.test.js @@ -423,15 +423,12 @@ describe("SuperTokens SignUp", function () { const postData = JSON.parse(request.postData()); Object.keys(customFields).forEach((key) => { let findFormData = postData.formFields.find((inputData) => inputData.id === key); - if (findFormData) { - assert.strictEqual( - findFormData["value"], - customFields[key], - `Mismatch in payload for key: ${key}` - ); - } else { - throw new Error("Field not found in req.data"); - } + assert.ok(findFormData, "Field not found in req.data"); + assert.strictEqual( + findFormData["value"], + customFields[key], + `Mismatch in payload for key: ${key}` + ); }); interceptionPassed = true; return request.respond({ @@ -474,13 +471,8 @@ describe("SuperTokens SignUp", function () { await page.setRequestInterception(false); } - if (assertionError) { - throw assertionError; - } - - if (!interceptionPassed) { - throw new Error("test failed"); - } + assert.ok(!assertionError, assertionError?.message); + assert.ok(interceptionPassed, "Test Failed"); }); it("Check on blank form submit nonOptionalErrorMsg gets displayed as expected", async function () { @@ -514,9 +506,7 @@ describe("SuperTokens SignUp", function () { await page.setRequestInterception(false); } - if (apiCallMade) { - throw new Error("Empty form making API request to sign-up"); - } + assert.ok(!apiCallMade, "Empty form making signup API request"); }); it("Check if nonOptionalErrorMsg overwrites server error message for non-optional fields", async function () { @@ -656,11 +646,8 @@ describe("SuperTokens SignUp", function () { const postData = JSON.parse(request.postData()); expectedDefautlValues.forEach(({ id, value }) => { let findFormData = postData.formFields.find((inputData) => inputData.id === id); - if (findFormData) { - assert.strictEqual(findFormData["value"], value, `Mismatch in payload for key: ${id}`); - } else { - throw new Error("Field not found in req.data"); - } + assert.ok(findFormData, "Field not found in req.data"); + assert.strictEqual(findFormData["value"], value, `Mismatch in payload for key: ${id}`); }); interceptionPassed = true; return request.respond({ @@ -691,13 +678,8 @@ describe("SuperTokens SignUp", function () { await page.setRequestInterception(false); } - if (assertionError) { - throw assertionError; - } - - if (!interceptionPassed) { - throw new Error("test failed"); - } + assert.ok(!assertionError, assertionError?.message); + assert.ok(interceptionPassed, "Test Failed"); }); }); @@ -768,14 +750,11 @@ describe("SuperTokens SignUp", function () { waitUntil: "domcontentloaded", }); - if (pageErrorMessage !== "") { - assert( - pageErrorMessage.includes(expectedErrorMessage), - `Expected "${expectedErrorMessage}" to be included in page-error` - ); - } else { - throw "Empty nonOptionalErrorMsg should throw error"; - } + assert.ok(pageErrorMessage !== "", "Empty nonOptionalErrorMsg should throw error"); + assert( + pageErrorMessage.includes(expectedErrorMessage), + `Expected "${expectedErrorMessage}" to be included in page-error` + ); }); }); }); From 20680548074ceaf0b43d0efe38aa719f5a8a0082 Mon Sep 17 00:00:00 2001 From: amitbadala Date: Thu, 16 Nov 2023 13:01:44 +0530 Subject: [PATCH 04/18] Consistent tests description --- test/end-to-end/signin.test.js | 6 +++--- test/end-to-end/signup.test.js | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/test/end-to-end/signin.test.js b/test/end-to-end/signin.test.js index 6ecdd81fa..6a71798cb 100644 --- a/test/end-to-end/signin.test.js +++ b/test/end-to-end/signin.test.js @@ -671,7 +671,7 @@ describe("SuperTokens SignIn", function () { }); }); - describe("SignIn default field tests", function () { + describe("Default fields", function () { it("Should contain email and password fields prefilled", async function () { await page.evaluate(() => window.localStorage.setItem("SHOW_SIGNIN_DEFAULT_FIELDS", "YES")); @@ -750,8 +750,8 @@ describe("SuperTokens SignIn", function () { }); }); - describe("Check if nonOptionalErrorMsg works as expected", function () { - it("Check on blank form submit nonOptionalErrorMsg gets displayed as expected", async function () { + describe("nonOptionalErrorMsg", function () { + it("Should be displayed on a blank form submit", async function () { await page.evaluate(() => localStorage.removeItem("SHOW_SIGNIN_DEFAULT_FIELDS")); // set cookie and reload which loads the form with custom field diff --git a/test/end-to-end/signup.test.js b/test/end-to-end/signup.test.js index 726d98fd4..b964160fc 100644 --- a/test/end-to-end/signup.test.js +++ b/test/end-to-end/signup.test.js @@ -345,7 +345,7 @@ describe("SuperTokens SignUp", function () { }); }); - describe("Signup custom fields test", function () { + describe("Custom fields tests", function () { beforeEach(async function () { // set cookie and reload which loads the form with custom field await page.evaluate(() => window.localStorage.setItem("SHOW_CUSTOM_FIELDS", "YES")); @@ -356,7 +356,7 @@ describe("SuperTokens SignUp", function () { await toggleSignInSignUp(page); }); - it("Check if the custom fields are loaded", async function () { + it("Should load the custom fields", async function () { let text = await getAuthPageHeaderText(page); assert.deepStrictEqual(text, "Sign Up"); @@ -409,7 +409,7 @@ describe("SuperTokens SignUp", function () { assert.deepStrictEqual(formFieldErrors, ["Please check Terms and conditions"]); }); - it("Check if custom values are part of the signup payload", async function () { + it("Should be part of the signup payload", async function () { const customFields = { terms: "true", "select-dropdown": "option 3", @@ -475,7 +475,7 @@ describe("SuperTokens SignUp", function () { assert.ok(interceptionPassed, "Test Failed"); }); - it("Check on blank form submit nonOptionalErrorMsg gets displayed as expected", async function () { + it("Should display nonOptionalErrorMsg on blank form submit", async function () { let apiCallMade = false; const requestHandler = (request) => { @@ -509,7 +509,7 @@ describe("SuperTokens SignUp", function () { assert.ok(!apiCallMade, "Empty form making signup API request"); }); - it("Check if nonOptionalErrorMsg overwrites server error message for non-optional fields", async function () { + it("Should overwrite server error message for non-optional fields with nonOptionalErrorMsg", async function () { const requestHandler = (request) => { if (request.method() === "POST" && request.url() === SIGN_UP_API) { request.respond({ @@ -569,7 +569,7 @@ describe("SuperTokens SignUp", function () { }); // Default values test - describe("Signup default value for fields test", function () { + describe("Default fields tests", function () { beforeEach(async function () { // set cookie and reload which loads the form fields with default values await page.evaluate(() => window.localStorage.setItem("SHOW_CUSTOM_FIELDS_WITH_DEFAULT_VALUES", "YES")); @@ -580,7 +580,7 @@ describe("SuperTokens SignUp", function () { await toggleSignInSignUp(page); }); - it("Check if default values are set already", async function () { + it("Should prefill the fields with default values", async function () { const fieldsWithDefault = { country: "India", "select-dropdown": "option 2", @@ -607,7 +607,7 @@ describe("SuperTokens SignUp", function () { assert.strictEqual(defaultValue, fieldsWithDefault["terms"].toString()); }); - it("Check if changing the field value actually overwrites the default value", async function () { + it("Should be able to overwrite the default values", async function () { const updatedFields = { country: "USA", "select-dropdown": "option 3", @@ -627,7 +627,7 @@ describe("SuperTokens SignUp", function () { assert.strictEqual(updatedOption, updatedFields["select-dropdown"]); }); - it("Check if default values are getting sent in signup-payload", async function () { + it("Should ensure signup-payload contains default values", async function () { // directly submit the form and test the payload const expectedDefautlValues = [ { id: "email", value: "test@one.com" }, @@ -693,7 +693,7 @@ describe("SuperTokens SignUp", function () { }); }); - it("Check if incorrect getDefaultValue throws error", async function () { + it("Should throw error for incorrect getDefaultValue func call", async function () { await page.evaluate(() => window.localStorage.setItem("INCORRECT_GETDEFAULT", "YES")); let pageErrorMessage = ""; page.on("pageerror", (err) => { @@ -712,7 +712,7 @@ describe("SuperTokens SignUp", function () { ); }); - it("Check if non-string params to onChange throws error", async function () { + it("Should throw error for non-string params to onChange", async function () { await page.evaluate(() => window.localStorage.removeItem("INCORRECT_GETDEFAULT")); await page.evaluate(() => window.localStorage.setItem("INCORRECT_ONCHANGE", "YES")); await page.reload({ @@ -736,7 +736,7 @@ describe("SuperTokens SignUp", function () { ); }); - it("Check if empty string for nonOptionalErrorMsg throws error", async function () { + it("Should throw error for empty string for nonOptionalErrorMsg", async function () { const expectedErrorMessage = "nonOptionalErrorMsg for field city cannot be an empty string"; let pageErrorMessage = ""; page.on("pageerror", (err) => { From 35a788c55c409c58bfd5add3cdd4b3ca17296ccc Mon Sep 17 00:00:00 2001 From: amitbadala Date: Thu, 16 Nov 2023 13:49:58 +0530 Subject: [PATCH 05/18] Remove unecessary code --- test/end-to-end/signin.test.js | 3 --- test/end-to-end/signup.test.js | 2 -- 2 files changed, 5 deletions(-) diff --git a/test/end-to-end/signin.test.js b/test/end-to-end/signin.test.js index 6a71798cb..8cac767bd 100644 --- a/test/end-to-end/signin.test.js +++ b/test/end-to-end/signin.test.js @@ -773,8 +773,6 @@ describe("SuperTokens SignIn", function () { request.continue(); } }; - - await page.setRequestInterception(true); page.on("request", requestHandler); try { @@ -785,7 +783,6 @@ describe("SuperTokens SignIn", function () { assert.deepStrictEqual(formFieldErrors, ["Please add email", "Field is not optional"]); } finally { page.off("request", requestHandler); - await page.setRequestInterception(false); } assert.ok(!apiCallMade, "Empty form making API request to signin"); diff --git a/test/end-to-end/signup.test.js b/test/end-to-end/signup.test.js index b964160fc..c16c12894 100644 --- a/test/end-to-end/signup.test.js +++ b/test/end-to-end/signup.test.js @@ -488,7 +488,6 @@ describe("SuperTokens SignUp", function () { } }; - await page.setRequestInterception(true); page.on("request", requestHandler); try { @@ -503,7 +502,6 @@ describe("SuperTokens SignUp", function () { ]); } finally { page.off("request", requestHandler); - await page.setRequestInterception(false); } assert.ok(!apiCallMade, "Empty form making signup API request"); From ca5d800442b565dccc2f288ebb845e7f81011daf Mon Sep 17 00:00:00 2001 From: amitbadala Date: Thu, 16 Nov 2023 14:46:16 +0530 Subject: [PATCH 06/18] Add correct version number --- CHANGELOG.md | 2 +- lib/build/version.d.ts | 2 +- lib/ts/version.ts | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d966973be..13a9da4b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) -## [0.36.0] - 2023-10-30 +## [0.35.7] - 2023-10-30 ### Added diff --git a/lib/build/version.d.ts b/lib/build/version.d.ts index e85100a93..61197a780 100644 --- a/lib/build/version.d.ts +++ b/lib/build/version.d.ts @@ -1 +1 @@ -export declare const package_version = "0.36.0"; +export declare const package_version = "0.35.7"; diff --git a/lib/ts/version.ts b/lib/ts/version.ts index 1fd0f9cc7..8d697de72 100644 --- a/lib/ts/version.ts +++ b/lib/ts/version.ts @@ -12,4 +12,4 @@ * License for the specific language governing permissions and limitations * under the License. */ -export const package_version = "0.36.0"; +export const package_version = "0.35.7"; diff --git a/package-lock.json b/package-lock.json index d49cefd40..f2efb65d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "supertokens-auth-react", - "version": "0.36.0", + "version": "0.35.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "supertokens-auth-react", - "version": "0.36.0", + "version": "0.35.7", "license": "Apache-2.0", "dependencies": { "intl-tel-input": "^17.0.19", diff --git a/package.json b/package.json index f666f121f..eedec85f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "supertokens-auth-react", - "version": "0.36.0", + "version": "0.35.7", "description": "ReactJS SDK that provides login functionality with SuperTokens.", "main": "./index.js", "engines": { From 16e02a9de9c65869bc4d3cc0d684e9bac4c7cab4 Mon Sep 17 00:00:00 2001 From: amitbadala Date: Thu, 16 Nov 2023 16:00:19 +0530 Subject: [PATCH 07/18] Update changelog, add thirdparty example --- CHANGELOG.md | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13a9da4b3..5fe1a8147 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,13 +5,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) -## [0.35.7] - 2023-10-30 +## [0.35.7] - 2023-11-16 ### Added -- Introduced the capability to utilize custom components in the Email-Password based recipes' signup form fields by exposing inputComponent types. -- Implemented the functionality to assign default values to the form fields in the Email-Password based recipes. -- Simplified onChange prop usage in inputComponent - id attribute removed. +- Email-Password and Third-Party Email Password Recipes Enhancements: + - Introduced the capability to utilize custom components in the Email-Password by exposing inputComponent types. + - Allow setting default values in signup/signin form fields. + - Made onChange prop in inputComponent simpler by removing the need for an id attribute. + - Added a feature to customize the "Field is not optional" error message for each form field with the nonOptionalErrorMsg prop. Following is an example of how to use above features. @@ -24,6 +26,7 @@ EmailPassword.init({ id: "select-dropdown", label: "Select Option", getDefaultValue: () => "option 2", + nonOptionalErrorMsg: "Select dropdown is required", inputComponent: ({ value, name, onChange }) => ( onChange(e.target.checked.toString())}> + I agree to the terms and conditions + + ), + }, + ], + }, + }, +}); ``` ## [0.35.6] - 2023-10-16 From 928da9ab3e0da3559021233bc1e7d5b9cd1080dc Mon Sep 17 00:00:00 2001 From: amitbadala Date: Thu, 16 Nov 2023 16:12:23 +0530 Subject: [PATCH 08/18] Minor fox --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fe1a8147..1787ab3a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,7 +56,6 @@ ThirdPartyEmailPassword.init({ label: "", optional: false, getDefaultValue: () => "true", - optional: false, nonOptionalErrorMsg: "You must accept the terms and conditions", inputComponent: ({ name, onChange, value }) => (
Date: Thu, 16 Nov 2023 17:28:55 +0530 Subject: [PATCH 09/18] Read from testContext --- examples/for-tests/src/App.js | 45 +++++++++++++++++---------- examples/for-tests/src/testContext.js | 12 +++++++ 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/examples/for-tests/src/App.js b/examples/for-tests/src/App.js index 29d292a39..96ddc7dc8 100644 --- a/examples/for-tests/src/App.js +++ b/examples/for-tests/src/App.js @@ -713,29 +713,36 @@ function getEmailVerificationConfigs({ disableDefaultUI }) { }); } -function getSignUpFormFields() { - if (localStorage.getItem("SHOW_INCORRECT_FIELDS") === "YES") { - if (localStorage.getItem("INCORRECT_ONCHANGE") === "YES") { +function getSignUpFormFields(formFieldConfig) { + const { + showIncorrectFields, + incorrectOnChange, + incorrectNonOptionalErrorMsg, + incorrectGetDefault, + customFieldsWithDefault, + showCustomFields, + } = formFieldConfig; + if (showIncorrectFields === "YES") { + if (incorrectOnChange === "YES") { // since page-error blocks all the other errors // use this filter to test specific error return incorrectFormFields.filter(({ id }) => id === "terms"); - } else if (localStorage.getItem("INCORRECT_NON_OPTIONAL_ERROR_MSG") === "YES") { + } else if (incorrectNonOptionalErrorMsg === "YES") { return incorrectFormFields.filter(({ id }) => id === "city"); - } else if (localStorage.getItem("INCORRECT_GETDEFAULT") === "YES") { + } else if (incorrectGetDefault === "YES") { return incorrectFormFields.filter(({ id }) => id === "country"); } return incorrectFormFields; - } else if (localStorage.getItem("SHOW_CUSTOM_FIELDS_WITH_DEFAULT_VALUES") === "YES") { + } else if (customFieldsWithDefault === "YES") { return formFieldsWithDefault; - } else if (localStorage.getItem("SHOW_CUSTOM_FIELDS") === "YES") { + } else if (showCustomFields === "YES") { return customFields; } return formFields; } -function getSignInFormFields() { - let showDefaultFields = localStorage.getItem("SHOW_SIGNIN_DEFAULT_FIELDS"); - let showFieldsWithNonOptionalErrMsg = localStorage.getItem("SHOW_SIGNIN_WITH_NON_OPTIONAL_ERROR_MESSAGE"); +function getSignInFormFields(signInFormFieldConfig) { + const { showDefaultFields, showFieldsWithNonOptionalErrMsg } = signInFormFieldConfig; if (showDefaultFields === "YES") { return [ { @@ -758,7 +765,7 @@ function getSignInFormFields() { return []; } -function getEmailPasswordConfigs({ disableDefaultUI }) { +function getEmailPasswordConfigs({ disableDefaultUI, signUpFormFieldConfig, signInFormFieldConfig }) { return EmailPassword.init({ style: ` [data-supertokens~=container] { @@ -838,13 +845,13 @@ function getEmailPasswordConfigs({ disableDefaultUI }) { defaultToSignUp, signInForm: { style: theme, - formFields: getSignInFormFields(), + formFields: getSignInFormFields(signInFormFieldConfig), }, signUpForm: { style: theme, privacyPolicyLink: "https://supertokens.com/legal/privacy-policy", termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions", - formFields: getSignUpFormFields(), + formFields: getSignUpFormFields(signUpFormFieldConfig), }, }, }); @@ -1188,7 +1195,13 @@ function getThirdPartyConfigs({ staticProviderList, disableDefaultUI, thirdParty }); } -function getThirdPartyEmailPasswordConfigs({ staticProviderList, disableDefaultUI, thirdPartyRedirectURL }) { +function getThirdPartyEmailPasswordConfigs({ + staticProviderList, + disableDefaultUI, + thirdPartyRedirectURL, + signUpFormFieldConfig, + signInFormFieldConfig, +}) { let providers = [ ThirdParty.Github.init(), ThirdParty.Google.init(), @@ -1368,10 +1381,10 @@ function getThirdPartyEmailPasswordConfigs({ staticProviderList, disableDefaultU signInAndUpFeature: { disableDefaultUI, signInForm: { - formFields: getSignInFormFields(), + formFields: getSignInFormFields(signInFormFieldConfig), }, signUpForm: { - formFields: getSignUpFormFields(), + formFields: getSignUpFormFields(signUpFormFieldConfig), privacyPolicyLink: "https://supertokens.com/legal/privacy-policy", termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions", }, diff --git a/examples/for-tests/src/testContext.js b/examples/for-tests/src/testContext.js index 618e990ba..1d133fa83 100644 --- a/examples/for-tests/src/testContext.js +++ b/examples/for-tests/src/testContext.js @@ -14,6 +14,18 @@ export function getTestContext() { staticProviderList: localStorage.getItem("staticProviderList"), mockTenantId: localStorage.getItem("mockTenantId"), clientType: localStorage.getItem("clientType") || undefined, + signUpFormFieldConfig: { + showIncorrectFields: localStorage.getItem("SHOW_INCORRECT_FIELDS"), + incorrectOnChange: localStorage.getItem("INCORRECT_ONCHANGE"), + incorrectNonOptionalErrorMsg: localStorage.getItem("INCORRECT_NON_OPTIONAL_ERROR_MSG"), + incorrectGetDefault: localStorage.getItem("INCORRECT_GETDEFAULT"), + customFieldsWithDefault: localStorage.getItem("SHOW_CUSTOM_FIELDS_WITH_DEFAULT_VALUES"), + showCustomFields: localStorage.getItem("SHOW_CUSTOM_FIELDS"), + }, + signInFormFieldConfig: { + showDefaultFields: localStorage.getItem("SHOW_SIGNIN_DEFAULT_FIELDS"), + showFieldsWithNonOptionalErrMsg: localStorage.getItem("SHOW_SIGNIN_WITH_NON_OPTIONAL_ERROR_MESSAGE"), + }, }; return ret; } From d9ec3a0162402ecb64bc71ef954487f375b34a24 Mon Sep 17 00:00:00 2001 From: amitbadala Date: Fri, 17 Nov 2023 11:31:29 +0530 Subject: [PATCH 10/18] Refactor tests to ensure its easy to maintain different configurations --- examples/for-tests/src/App.js | 91 ++++++++++++--------------- examples/for-tests/src/testContext.js | 14 +---- test/end-to-end/signin.test.js | 8 +-- test/end-to-end/signup.test.js | 21 ++++--- 4 files changed, 60 insertions(+), 74 deletions(-) diff --git a/examples/for-tests/src/App.js b/examples/for-tests/src/App.js index 96ddc7dc8..298a5a705 100644 --- a/examples/for-tests/src/App.js +++ b/examples/for-tests/src/App.js @@ -713,59 +713,51 @@ function getEmailVerificationConfigs({ disableDefaultUI }) { }); } -function getSignUpFormFields(formFieldConfig) { - const { - showIncorrectFields, - incorrectOnChange, - incorrectNonOptionalErrorMsg, - incorrectGetDefault, - customFieldsWithDefault, - showCustomFields, - } = formFieldConfig; - if (showIncorrectFields === "YES") { - if (incorrectOnChange === "YES") { - // since page-error blocks all the other errors - // use this filter to test specific error +function getSignUpFormFields(formType) { + switch (formType) { + case "INCORRECT_FIELDS": + return incorrectFormFields; + case "INCORRECT_ONCHANGE": return incorrectFormFields.filter(({ id }) => id === "terms"); - } else if (incorrectNonOptionalErrorMsg === "YES") { + case "INCORRECT_NON_OPTIONAL_ERROR_MSG": return incorrectFormFields.filter(({ id }) => id === "city"); - } else if (incorrectGetDefault === "YES") { + case "INCORRECT_GETDEFAULT": return incorrectFormFields.filter(({ id }) => id === "country"); - } - return incorrectFormFields; - } else if (customFieldsWithDefault === "YES") { - return formFieldsWithDefault; - } else if (showCustomFields === "YES") { - return customFields; + case "CUSTOM_FIELDS_WITH_DEFAULT_VALUES": + return formFieldsWithDefault; + case "CUSTOM_FIELDS": + return customFields; + default: + return formFields; } - return formFields; } -function getSignInFormFields(signInFormFieldConfig) { - const { showDefaultFields, showFieldsWithNonOptionalErrMsg } = signInFormFieldConfig; - if (showDefaultFields === "YES") { - return [ - { - id: "email", - getDefaultValue: () => "abc@xyz.com", - }, - { - id: "password", - getDefaultValue: () => "fakepassword123", - }, - ]; - } else if (showFieldsWithNonOptionalErrMsg === "YES") { - return [ - { - id: "email", - nonOptionalErrorMsg: "Please add email", - }, - ]; +function getSignInFormFields(formType) { + switch (formType) { + case "DEFAULT_FIELDS": + return [ + { + id: "email", + getDefaultValue: () => "abc@xyz.com", + }, + { + id: "password", + getDefaultValue: () => "fakepassword123", + }, + ]; + case "FIELDS_WITH_NON_OPTIONAL_ERROR_MESSAGE": + return [ + { + id: "email", + nonOptionalErrorMsg: "Please add email", + }, + ]; + default: + return []; } - return []; } -function getEmailPasswordConfigs({ disableDefaultUI, signUpFormFieldConfig, signInFormFieldConfig }) { +function getEmailPasswordConfigs({ disableDefaultUI, formFieldType }) { return EmailPassword.init({ style: ` [data-supertokens~=container] { @@ -845,13 +837,13 @@ function getEmailPasswordConfigs({ disableDefaultUI, signUpFormFieldConfig, sign defaultToSignUp, signInForm: { style: theme, - formFields: getSignInFormFields(signInFormFieldConfig), + formFields: getSignInFormFields(formFieldType.signIn), }, signUpForm: { style: theme, privacyPolicyLink: "https://supertokens.com/legal/privacy-policy", termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions", - formFields: getSignUpFormFields(signUpFormFieldConfig), + formFields: getSignUpFormFields(formFieldType.signUp), }, }, }); @@ -1199,8 +1191,7 @@ function getThirdPartyEmailPasswordConfigs({ staticProviderList, disableDefaultUI, thirdPartyRedirectURL, - signUpFormFieldConfig, - signInFormFieldConfig, + formFieldType, }) { let providers = [ ThirdParty.Github.init(), @@ -1381,10 +1372,10 @@ function getThirdPartyEmailPasswordConfigs({ signInAndUpFeature: { disableDefaultUI, signInForm: { - formFields: getSignInFormFields(signInFormFieldConfig), + formFields: getSignInFormFields(formFieldType.signIn), }, signUpForm: { - formFields: getSignUpFormFields(signUpFormFieldConfig), + formFields: getSignUpFormFields(formFieldType.signUp), privacyPolicyLink: "https://supertokens.com/legal/privacy-policy", termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions", }, diff --git a/examples/for-tests/src/testContext.js b/examples/for-tests/src/testContext.js index 1d133fa83..3021a9b92 100644 --- a/examples/for-tests/src/testContext.js +++ b/examples/for-tests/src/testContext.js @@ -14,17 +14,9 @@ export function getTestContext() { staticProviderList: localStorage.getItem("staticProviderList"), mockTenantId: localStorage.getItem("mockTenantId"), clientType: localStorage.getItem("clientType") || undefined, - signUpFormFieldConfig: { - showIncorrectFields: localStorage.getItem("SHOW_INCORRECT_FIELDS"), - incorrectOnChange: localStorage.getItem("INCORRECT_ONCHANGE"), - incorrectNonOptionalErrorMsg: localStorage.getItem("INCORRECT_NON_OPTIONAL_ERROR_MSG"), - incorrectGetDefault: localStorage.getItem("INCORRECT_GETDEFAULT"), - customFieldsWithDefault: localStorage.getItem("SHOW_CUSTOM_FIELDS_WITH_DEFAULT_VALUES"), - showCustomFields: localStorage.getItem("SHOW_CUSTOM_FIELDS"), - }, - signInFormFieldConfig: { - showDefaultFields: localStorage.getItem("SHOW_SIGNIN_DEFAULT_FIELDS"), - showFieldsWithNonOptionalErrMsg: localStorage.getItem("SHOW_SIGNIN_WITH_NON_OPTIONAL_ERROR_MESSAGE"), + formFieldType: { + signIn: localStorage.getItem("SIGNIN_SETTING_TYPE"), + signUp: localStorage.getItem("SIGNUP_SETTING_TYPE"), }, }; return ret; diff --git a/test/end-to-end/signin.test.js b/test/end-to-end/signin.test.js index 8cac767bd..b701afc65 100644 --- a/test/end-to-end/signin.test.js +++ b/test/end-to-end/signin.test.js @@ -673,7 +673,7 @@ describe("SuperTokens SignIn", function () { describe("Default fields", function () { it("Should contain email and password fields prefilled", async function () { - await page.evaluate(() => window.localStorage.setItem("SHOW_SIGNIN_DEFAULT_FIELDS", "YES")); + await page.evaluate(() => window.localStorage.setItem("SIGNIN_SETTING_TYPE", "DEFAULT_FIELDS")); await page.reload({ waitUntil: "domcontentloaded", @@ -694,7 +694,7 @@ describe("SuperTokens SignIn", function () { }); it("Should have default values in the signin request payload", async function () { - await page.evaluate(() => window.localStorage.setItem("SHOW_SIGNIN_DEFAULT_FIELDS", "YES")); + await page.evaluate(() => window.localStorage.setItem("SIGNIN_SETTING_TYPE", "DEFAULT_FIELDS")); await page.reload({ waitUntil: "domcontentloaded", @@ -752,11 +752,11 @@ describe("SuperTokens SignIn", function () { describe("nonOptionalErrorMsg", function () { it("Should be displayed on a blank form submit", async function () { - await page.evaluate(() => localStorage.removeItem("SHOW_SIGNIN_DEFAULT_FIELDS")); + // await page.evaluate(() => localStorage.removeItem("SHOW_SIGNIN_DEFAULT_FIELDS")); // set cookie and reload which loads the form with custom field await page.evaluate(() => - window.localStorage.setItem("SHOW_SIGNIN_WITH_NON_OPTIONAL_ERROR_MESSAGE", "YES") + window.localStorage.setItem("SIGNIN_SETTING_TYPE", "FIELDS_WITH_NON_OPTIONAL_ERROR_MESSAGE") ); await page.reload({ waitUntil: "domcontentloaded", diff --git a/test/end-to-end/signup.test.js b/test/end-to-end/signup.test.js index c16c12894..9b032cb83 100644 --- a/test/end-to-end/signup.test.js +++ b/test/end-to-end/signup.test.js @@ -348,7 +348,7 @@ describe("SuperTokens SignUp", function () { describe("Custom fields tests", function () { beforeEach(async function () { // set cookie and reload which loads the form with custom field - await page.evaluate(() => window.localStorage.setItem("SHOW_CUSTOM_FIELDS", "YES")); + await page.evaluate(() => window.localStorage.setItem("SIGNUP_SETTING_TYPE", "CUSTOM_FIELDS")); await page.reload({ waitUntil: "domcontentloaded", @@ -570,7 +570,9 @@ describe("SuperTokens SignUp", function () { describe("Default fields tests", function () { beforeEach(async function () { // set cookie and reload which loads the form fields with default values - await page.evaluate(() => window.localStorage.setItem("SHOW_CUSTOM_FIELDS_WITH_DEFAULT_VALUES", "YES")); + await page.evaluate(() => + window.localStorage.setItem("SIGNUP_SETTING_TYPE", "CUSTOM_FIELDS_WITH_DEFAULT_VALUES") + ); await page.reload({ waitUntil: "domcontentloaded", @@ -684,7 +686,7 @@ describe("SuperTokens SignUp", function () { describe("Incorrect field config test", function () { beforeEach(async function () { // set cookie and reload which loads the form fields with default values - await page.evaluate(() => window.localStorage.setItem("SHOW_INCORRECT_FIELDS", "YES")); + await page.evaluate(() => window.localStorage.setItem("SIGNUP_SETTING_TYPE", "INCORRECT_FIELDS")); await page.reload({ waitUntil: "domcontentloaded", @@ -692,7 +694,7 @@ describe("SuperTokens SignUp", function () { }); it("Should throw error for incorrect getDefaultValue func call", async function () { - await page.evaluate(() => window.localStorage.setItem("INCORRECT_GETDEFAULT", "YES")); + await page.evaluate(() => window.localStorage.setItem("SIGNUP_SETTING_TYPE", "INCORRECT_GETDEFAULT")); let pageErrorMessage = ""; page.on("pageerror", (err) => { pageErrorMessage = err.message; @@ -711,8 +713,7 @@ describe("SuperTokens SignUp", function () { }); it("Should throw error for non-string params to onChange", async function () { - await page.evaluate(() => window.localStorage.removeItem("INCORRECT_GETDEFAULT")); - await page.evaluate(() => window.localStorage.setItem("INCORRECT_ONCHANGE", "YES")); + await page.evaluate(() => window.localStorage.setItem("SIGNUP_SETTING_TYPE", "INCORRECT_ONCHANGE")); await page.reload({ waitUntil: "domcontentloaded", }); @@ -741,9 +742,11 @@ describe("SuperTokens SignUp", function () { pageErrorMessage = err.message; }); - await page.evaluate(() => window.localStorage.removeItem("INCORRECT_GETDEFAULT")); - await page.evaluate(() => window.localStorage.removeItem("INCORRECT_ONCHANGE")); - await page.evaluate(() => window.localStorage.setItem("INCORRECT_NON_OPTIONAL_ERROR_MSG", "YES")); + // await page.evaluate(() => window.localStorage.removeItem("INCORRECT_GETDEFAULT")); + // await page.evaluate(() => window.localStorage.removeItem("INCORRECT_ONCHANGE")); + await page.evaluate(() => + window.localStorage.setItem("SIGNUP_SETTING_TYPE", "INCORRECT_NON_OPTIONAL_ERROR_MSG") + ); await page.reload({ waitUntil: "domcontentloaded", }); From 591ceb732eab1e373c811de9555d8c47554c457f Mon Sep 17 00:00:00 2001 From: amitbadala Date: Fri, 17 Nov 2023 11:46:13 +0530 Subject: [PATCH 11/18] Update third party tests --- .../thirdpartyemailpassword.test.js | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/test/end-to-end/thirdpartyemailpassword.test.js b/test/end-to-end/thirdpartyemailpassword.test.js index 9779b00fd..cf1008edc 100644 --- a/test/end-to-end/thirdpartyemailpassword.test.js +++ b/test/end-to-end/thirdpartyemailpassword.test.js @@ -446,7 +446,7 @@ describe("SuperTokens Third Party Email Password", function () { describe("SignIn default field tests", function () { it("Should contain email and password fields prefilled", async function () { - await page.evaluate(() => window.localStorage.setItem("SHOW_SIGNIN_DEFAULT_FIELDS", "YES")); + await page.evaluate(() => window.localStorage.setItem("SIGNIN_SETTING_TYPE", "DEFAULT_FIELDS")); await page.reload({ waitUntil: "domcontentloaded", @@ -467,11 +467,11 @@ describe("SuperTokens Third Party Email Password", function () { }); it("Check on blank form submit nonOptionalErrorMsg gets displayed as expected", async function () { - await page.evaluate(() => window.localStorage.removeItem("SHOW_SIGNIN_DEFAULT_FIELDS")); + // await page.evaluate(() => window.localStorage.removeItem("SHOW_SIGNIN_DEFAULT_FIELDS")); // set cookie and reload which loads the form with custom field await page.evaluate(() => - window.localStorage.setItem("SHOW_SIGNIN_WITH_NON_OPTIONAL_ERROR_MESSAGE", "YES") + window.localStorage.setItem("SIGNIN_SETTING_TYPE", "FIELDS_WITH_NON_OPTIONAL_ERROR_MESSAGE") ); await page.reload({ waitUntil: "domcontentloaded", @@ -513,7 +513,7 @@ describe("SuperTokens Third Party Email Password", function () { describe("Third Party signup config supports custom fields tests", function () { beforeEach(async function () { - await page.evaluate(() => window.localStorage.setItem("SHOW_CUSTOM_FIELDS", "YES")); + await page.evaluate(() => window.localStorage.setItem("SIGNUP_SETTING_TYPE", "CUSTOM_FIELDS")); await page.reload({ waitUntil: "domcontentloaded", @@ -747,7 +747,9 @@ describe("SuperTokens Third Party Email Password", function () { describe("Third Party signup default value for fields test", function () { beforeEach(async function () { // set cookie and reload which loads the form fields with default values - await page.evaluate(() => window.localStorage.setItem("SHOW_CUSTOM_FIELDS_WITH_DEFAULT_VALUES", "YES")); + await page.evaluate(() => + window.localStorage.setItem("SIGNUP_SETTING_TYPE", "CUSTOM_FIELDS_WITH_DEFAULT_VALUES") + ); await page.reload({ waitUntil: "domcontentloaded", @@ -869,7 +871,7 @@ describe("SuperTokens Third Party Email Password", function () { describe("Third Party signup config Incorrect field message test", function () { beforeEach(async function () { // set cookie and reload which loads the form fields with default values - await page.evaluate(() => window.localStorage.setItem("SHOW_INCORRECT_FIELDS", "YES")); + await page.evaluate(() => window.localStorage.setItem("SIGNUP_SETTING_TYPE", "INCORRECT_FIELDS")); await page.reload({ waitUntil: "domcontentloaded", @@ -877,7 +879,7 @@ describe("SuperTokens Third Party Email Password", function () { }); it("Check if incorrect getDefaultValue throws error", async function () { - await page.evaluate(() => window.localStorage.setItem("INCORRECT_GETDEFAULT", "YES")); + await page.evaluate(() => window.localStorage.setItem("SIGNUP_SETTING_TYPE", "INCORRECT_GETDEFAULT")); let pageErrorMessage = ""; page.on("pageerror", (err) => { pageErrorMessage = err.message; @@ -896,8 +898,8 @@ describe("SuperTokens Third Party Email Password", function () { }); it("Check if non-string params to onChange throws error", async function () { - await page.evaluate(() => window.localStorage.removeItem("INCORRECT_GETDEFAULT")); - await page.evaluate(() => window.localStorage.setItem("INCORRECT_ONCHANGE", "YES")); + // await page.evaluate(() => window.localStorage.removeItem("INCORRECT_GETDEFAULT")); + await page.evaluate(() => window.localStorage.setItem("SIGNUP_SETTING_TYPE", "INCORRECT_ONCHANGE")); await page.reload({ waitUntil: "domcontentloaded", }); @@ -926,9 +928,11 @@ describe("SuperTokens Third Party Email Password", function () { pageErrorMessage = err.message; }); - await page.evaluate(() => window.localStorage.removeItem("INCORRECT_GETDEFAULT")); - await page.evaluate(() => window.localStorage.removeItem("INCORRECT_ONCHANGE")); - await page.evaluate(() => window.localStorage.setItem("INCORRECT_NON_OPTIONAL_ERROR_MSG", "YES")); + // await page.evaluate(() => window.localStorage.removeItem("INCORRECT_GETDEFAULT")); + // await page.evaluate(() => window.localStorage.removeItem("INCORRECT_ONCHANGE")); + await page.evaluate(() => + window.localStorage.setItem("SIGNUP_SETTING_TYPE", "INCORRECT_NON_OPTIONAL_ERROR_MSG") + ); await page.reload({ waitUntil: "domcontentloaded", }); From 746356ad4374aaf335687f25edb0ef7b9077e701 Mon Sep 17 00:00:00 2001 From: amitbadala Date: Fri, 17 Nov 2023 11:49:25 +0530 Subject: [PATCH 12/18] Clean up --- test/end-to-end/signin.test.js | 2 -- test/end-to-end/signup.test.js | 2 -- test/end-to-end/thirdpartyemailpassword.test.js | 5 ----- 3 files changed, 9 deletions(-) diff --git a/test/end-to-end/signin.test.js b/test/end-to-end/signin.test.js index b701afc65..49f20b9a9 100644 --- a/test/end-to-end/signin.test.js +++ b/test/end-to-end/signin.test.js @@ -752,8 +752,6 @@ describe("SuperTokens SignIn", function () { describe("nonOptionalErrorMsg", function () { it("Should be displayed on a blank form submit", async function () { - // await page.evaluate(() => localStorage.removeItem("SHOW_SIGNIN_DEFAULT_FIELDS")); - // set cookie and reload which loads the form with custom field await page.evaluate(() => window.localStorage.setItem("SIGNIN_SETTING_TYPE", "FIELDS_WITH_NON_OPTIONAL_ERROR_MESSAGE") diff --git a/test/end-to-end/signup.test.js b/test/end-to-end/signup.test.js index 9b032cb83..81b5b4bd8 100644 --- a/test/end-to-end/signup.test.js +++ b/test/end-to-end/signup.test.js @@ -742,8 +742,6 @@ describe("SuperTokens SignUp", function () { pageErrorMessage = err.message; }); - // await page.evaluate(() => window.localStorage.removeItem("INCORRECT_GETDEFAULT")); - // await page.evaluate(() => window.localStorage.removeItem("INCORRECT_ONCHANGE")); await page.evaluate(() => window.localStorage.setItem("SIGNUP_SETTING_TYPE", "INCORRECT_NON_OPTIONAL_ERROR_MSG") ); diff --git a/test/end-to-end/thirdpartyemailpassword.test.js b/test/end-to-end/thirdpartyemailpassword.test.js index cf1008edc..fddbc41eb 100644 --- a/test/end-to-end/thirdpartyemailpassword.test.js +++ b/test/end-to-end/thirdpartyemailpassword.test.js @@ -467,8 +467,6 @@ describe("SuperTokens Third Party Email Password", function () { }); it("Check on blank form submit nonOptionalErrorMsg gets displayed as expected", async function () { - // await page.evaluate(() => window.localStorage.removeItem("SHOW_SIGNIN_DEFAULT_FIELDS")); - // set cookie and reload which loads the form with custom field await page.evaluate(() => window.localStorage.setItem("SIGNIN_SETTING_TYPE", "FIELDS_WITH_NON_OPTIONAL_ERROR_MESSAGE") @@ -898,7 +896,6 @@ describe("SuperTokens Third Party Email Password", function () { }); it("Check if non-string params to onChange throws error", async function () { - // await page.evaluate(() => window.localStorage.removeItem("INCORRECT_GETDEFAULT")); await page.evaluate(() => window.localStorage.setItem("SIGNUP_SETTING_TYPE", "INCORRECT_ONCHANGE")); await page.reload({ waitUntil: "domcontentloaded", @@ -928,8 +925,6 @@ describe("SuperTokens Third Party Email Password", function () { pageErrorMessage = err.message; }); - // await page.evaluate(() => window.localStorage.removeItem("INCORRECT_GETDEFAULT")); - // await page.evaluate(() => window.localStorage.removeItem("INCORRECT_ONCHANGE")); await page.evaluate(() => window.localStorage.setItem("SIGNUP_SETTING_TYPE", "INCORRECT_NON_OPTIONAL_ERROR_MSG") ); From 52a97254d0fd9819bce8a586c48bcfd7d2d730c1 Mon Sep 17 00:00:00 2001 From: amitbadala Date: Fri, 17 Nov 2023 11:54:38 +0530 Subject: [PATCH 13/18] Minor copy update --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1787ab3a1..de2305b29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Email-Password and Third-Party Email Password Recipes Enhancements: - - Introduced the capability to utilize custom components in the Email-Password by exposing inputComponent types. +- Email-Password and Third-Party Email Password Recipes Enhancements as follows: + - Introduced the capability to utilize custom components by exposing inputComponent types. - Allow setting default values in signup/signin form fields. - Made onChange prop in inputComponent simpler by removing the need for an id attribute. - Added a feature to customize the "Field is not optional" error message for each form field with the nonOptionalErrorMsg prop. From 3184292fab30b0879df07fc1bb6d534cb261b74c Mon Sep 17 00:00:00 2001 From: amitbadala Date: Fri, 17 Nov 2023 12:49:31 +0530 Subject: [PATCH 14/18] Trim the label text --- lib/ts/recipe/emailpassword/components/library/label.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ts/recipe/emailpassword/components/library/label.tsx b/lib/ts/recipe/emailpassword/components/library/label.tsx index 319b04760..11985c7ef 100644 --- a/lib/ts/recipe/emailpassword/components/library/label.tsx +++ b/lib/ts/recipe/emailpassword/components/library/label.tsx @@ -26,7 +26,7 @@ export default function Label({ value, showIsRequired }: LabelProps): JSX.Elemen return (
{t(value)} - {showIsRequired && value !== "" && " *"} + {showIsRequired && value.trim() !== "" && " *"}
); } From b9db8511fba6797fabe8ef1ef2e2fb003bad49ca Mon Sep 17 00:00:00 2001 From: amitbadala Date: Fri, 17 Nov 2023 13:02:57 +0530 Subject: [PATCH 15/18] Add build --- lib/build/emailpassword-shared7.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build/emailpassword-shared7.js b/lib/build/emailpassword-shared7.js index 018028673..484fc4738 100644 --- a/lib/build/emailpassword-shared7.js +++ b/lib/build/emailpassword-shared7.js @@ -425,7 +425,7 @@ function Label(_a) { "div", genericComponentOverrideContext.__assign( { "data-supertokens": "label" }, - { children: [t(value), showIsRequired && value !== "" && " *"] } + { children: [t(value), showIsRequired && value.trim() !== "" && " *"] } ) ); } From 8faf03ffb26723da7bb0b981e091852a8d56417b Mon Sep 17 00:00:00 2001 From: amitbadala Date: Fri, 17 Nov 2023 13:09:47 +0530 Subject: [PATCH 16/18] Handle if label is not supplied --- lib/build/emailpassword-shared7.js | 2 +- lib/ts/recipe/emailpassword/components/library/label.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/build/emailpassword-shared7.js b/lib/build/emailpassword-shared7.js index 484fc4738..e48dc5334 100644 --- a/lib/build/emailpassword-shared7.js +++ b/lib/build/emailpassword-shared7.js @@ -425,7 +425,7 @@ function Label(_a) { "div", genericComponentOverrideContext.__assign( { "data-supertokens": "label" }, - { children: [t(value), showIsRequired && value.trim() !== "" && " *"] } + { children: [t(value), showIsRequired && value && value.trim() !== "" && " *"] } ) ); } diff --git a/lib/ts/recipe/emailpassword/components/library/label.tsx b/lib/ts/recipe/emailpassword/components/library/label.tsx index 11985c7ef..428122455 100644 --- a/lib/ts/recipe/emailpassword/components/library/label.tsx +++ b/lib/ts/recipe/emailpassword/components/library/label.tsx @@ -26,7 +26,7 @@ export default function Label({ value, showIsRequired }: LabelProps): JSX.Elemen return (
{t(value)} - {showIsRequired && value.trim() !== "" && " *"} + {showIsRequired && value && value.trim() !== "" && " *"}
); } From 282ca65ffa95b29d53e8538b1f2d56af0061a628 Mon Sep 17 00:00:00 2001 From: amitbadala Date: Fri, 17 Nov 2023 18:41:05 +0530 Subject: [PATCH 17/18] Highlight var in changelog, minor update --- CHANGELOG.md | 8 ++++---- examples/for-tests/src/App.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de2305b29..1c84f6e6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Email-Password and Third-Party Email Password Recipes Enhancements as follows: - - Introduced the capability to utilize custom components by exposing inputComponent types. +- EmailPassword and ThirdPartyEmailPassword recipe enhancements: + - Introduced the capability to utilize custom components by exposing `inputComponent` types. - Allow setting default values in signup/signin form fields. - - Made onChange prop in inputComponent simpler by removing the need for an id attribute. - - Added a feature to customize the "Field is not optional" error message for each form field with the nonOptionalErrorMsg prop. + - Made the `onChange` prop in `inputComponent` simpler by removing the need for an `id` attribute. + - Added a feature to customize the "Field is not optional" error message for each form field with the `nonOptionalErrorMsg` prop. Following is an example of how to use above features. diff --git a/examples/for-tests/src/App.js b/examples/for-tests/src/App.js index 298a5a705..3800cd9b8 100644 --- a/examples/for-tests/src/App.js +++ b/examples/for-tests/src/App.js @@ -753,7 +753,7 @@ function getSignInFormFields(formType) { }, ]; default: - return []; + return; } } From 4fcc16d4a19bf437e24732f65f0862663606332c Mon Sep 17 00:00:00 2001 From: amitbadala Date: Mon, 20 Nov 2023 14:21:39 +0530 Subject: [PATCH 18/18] Update custom payload to test for trimmed-version label --- examples/for-tests/src/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/for-tests/src/App.js b/examples/for-tests/src/App.js index 3800cd9b8..add8541e8 100644 --- a/examples/for-tests/src/App.js +++ b/examples/for-tests/src/App.js @@ -306,7 +306,7 @@ const customFields = [ }, { id: "terms", - label: "", + label: " ", optional: false, nonOptionalErrorMsg: "You must accept the terms and conditions", inputComponent: ({ name, onChange }) => (