diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /browser/components/newtab/test/unit/asrouter/templates/isEmailOrPhoneNumber.test.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/newtab/test/unit/asrouter/templates/isEmailOrPhoneNumber.test.js')
-rw-r--r-- | browser/components/newtab/test/unit/asrouter/templates/isEmailOrPhoneNumber.test.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/browser/components/newtab/test/unit/asrouter/templates/isEmailOrPhoneNumber.test.js b/browser/components/newtab/test/unit/asrouter/templates/isEmailOrPhoneNumber.test.js new file mode 100644 index 0000000000..32eaf2160e --- /dev/null +++ b/browser/components/newtab/test/unit/asrouter/templates/isEmailOrPhoneNumber.test.js @@ -0,0 +1,56 @@ +import { isEmailOrPhoneNumber } from "content-src/asrouter/templates/SendToDeviceSnippet/isEmailOrPhoneNumber"; + +const CONTENT = {}; + +describe("isEmailOrPhoneNumber", () => { + it("should return 'email' for emails", () => { + assert.equal(isEmailOrPhoneNumber("foobar@asd.com", CONTENT), "email"); + assert.equal(isEmailOrPhoneNumber("foobar@asd.co.uk", CONTENT), "email"); + }); + it("should return 'phone' for valid en-US/en-CA phone numbers", () => { + assert.equal( + isEmailOrPhoneNumber("14582731273", { locale: "en-US" }), + "phone" + ); + assert.equal( + isEmailOrPhoneNumber("4582731273", { locale: "en-CA" }), + "phone" + ); + }); + it("should return an empty string for invalid phone number lengths in en-US/en-CA", () => { + // Not enough digits + assert.equal(isEmailOrPhoneNumber("4522", { locale: "en-US" }), ""); + assert.equal(isEmailOrPhoneNumber("4522", { locale: "en-CA" }), ""); + }); + it("should return 'phone' for valid German phone numbers", () => { + assert.equal( + isEmailOrPhoneNumber("145827312732", { locale: "de" }), + "phone" + ); + }); + it("should return 'phone' for any number of digits in other locales", () => { + assert.equal(isEmailOrPhoneNumber("4", CONTENT), "phone"); + }); + it("should return an empty string for other invalid inputs", () => { + assert.equal( + isEmailOrPhoneNumber("abc", CONTENT), + "", + "abc should be invalid" + ); + assert.equal( + isEmailOrPhoneNumber("abc@", CONTENT), + "", + "abc@ should be invalid" + ); + assert.equal( + isEmailOrPhoneNumber("abc@foo", CONTENT), + "", + "abc@foo should be invalid" + ); + assert.equal( + isEmailOrPhoneNumber("123d1232", CONTENT), + "", + "123d1232 should be invalid" + ); + }); +}); |