diff --git a/webapp/src/utils/regex_utils.test.js b/webapp/src/utils/regex_utils.test.ts similarity index 92% rename from webapp/src/utils/regex_utils.test.js rename to webapp/src/utils/regex_utils.test.ts index 74dc76e4..990569ba 100644 --- a/webapp/src/utils/regex_utils.test.js +++ b/webapp/src/utils/regex_utils.test.ts @@ -1,4 +1,5 @@ import {validateGitlabURL} from './regex_utils'; +import {describe, expect, it} from "@jest/globals"; describe('validateGitlabURL should work as expected', () => { it('Should return true for valid GitLab repository URL', () => { diff --git a/webapp/src/utils/regex_utils.js b/webapp/src/utils/regex_utils.ts similarity index 71% rename from webapp/src/utils/regex_utils.js rename to webapp/src/utils/regex_utils.ts index c1e9c38d..453d6a75 100644 --- a/webapp/src/utils/regex_utils.js +++ b/webapp/src/utils/regex_utils.ts @@ -1,4 +1,4 @@ -export function validateGitlabURL(url) { +export function validateGitlabURL(url: string): boolean { const gitlabRegexPattern = /https?:\/\/(www\.)?.*\/([\w.?-]+)\/([\w-]+)\/-\/([\w-]+)\/([\d-]+$)/g; return gitlabRegexPattern.test(url); } diff --git a/webapp/src/utils/url_utils.test.ts b/webapp/src/utils/url_utils.test.ts new file mode 100644 index 00000000..b1011e4d --- /dev/null +++ b/webapp/src/utils/url_utils.test.ts @@ -0,0 +1,13 @@ +import {describe, expect, it} from "@jest/globals"; +import {isValidUrl} from "./url_utils"; + + +describe('url_utils', () => { + it("should return true for a valid URL", () => { + expect(isValidUrl("https://mattermost.com")).toBe(true); + }) + + it.each(["abc@example.com", "xyz", "://example.com", "example.com"])("should return false for invalid URLs %s", (input) => { + expect(isValidUrl(input)).toBe(false); + }) +}) \ No newline at end of file diff --git a/webapp/src/utils/url_utils.js b/webapp/src/utils/url_utils.ts similarity index 63% rename from webapp/src/utils/url_utils.js rename to webapp/src/utils/url_utils.ts index c8ddfe01..e96ee2fa 100644 --- a/webapp/src/utils/url_utils.js +++ b/webapp/src/utils/url_utils.ts @@ -1,4 +1,4 @@ -export const isValidUrl = (urlString) => { +export const isValidUrl = (urlString: string): boolean => { try { return Boolean(new URL(urlString)); } catch (e) { diff --git a/webapp/src/utils/user_agent.js b/webapp/src/utils/user_agent.js deleted file mode 100644 index 6f980f4e..00000000 --- a/webapp/src/utils/user_agent.js +++ /dev/null @@ -1,3 +0,0 @@ -const userAgent = window.navigator.userAgent; - -export const isDesktopApp = () => userAgent.indexOf('Mattermost') !== -1 && userAgent.indexOf('Electron') !== -1; diff --git a/webapp/src/utils/user_agent.test.ts b/webapp/src/utils/user_agent.test.ts new file mode 100644 index 00000000..bc24a286 --- /dev/null +++ b/webapp/src/utils/user_agent.test.ts @@ -0,0 +1,25 @@ +import {describe, expect, it, jest} from "@jest/globals"; +import {isDesktopApp} from "./user_agent"; + + +describe("user_agent", () => { + it("should return true if 'Mattermost' and 'Electron' are in userAgent", () => { + jest.spyOn(window.navigator, 'userAgent', 'get').mockReturnValue('Mattermost Electron') + expect(isDesktopApp()).toBe(true); + }) + + it("should return false if only 'Mattermost' present in userAgent", () => { + jest.spyOn(window.navigator, 'userAgent', 'get').mockReturnValue('Mattermost') + expect(isDesktopApp()).toBe(false); + }) + + it("should return false if only 'Electron' present in userAgent", () => { + jest.spyOn(window.navigator, 'userAgent', 'get').mockReturnValue('Electron') + expect(isDesktopApp()).toBe(false); + }) + + it("should return false if neither 'Mattermost' nor 'Electron' present in userAgent", () => { + jest.spyOn(window.navigator, 'userAgent', 'get').mockReturnValue('Google chrome') + expect(isDesktopApp()).toBe(false); + }) +}) \ No newline at end of file diff --git a/webapp/src/utils/user_agent.ts b/webapp/src/utils/user_agent.ts new file mode 100644 index 00000000..ffdda72c --- /dev/null +++ b/webapp/src/utils/user_agent.ts @@ -0,0 +1,4 @@ +export const isDesktopApp = () => { + const userAgent = window.navigator.userAgent; + return userAgent.indexOf('Mattermost') !== -1 && userAgent.indexOf('Electron') !== -1 +}; diff --git a/webapp/src/utils/user_utils.js b/webapp/src/utils/user_utils.js deleted file mode 100644 index cf2329a6..00000000 --- a/webapp/src/utils/user_utils.js +++ /dev/null @@ -1,17 +0,0 @@ -import {getFullName} from 'mattermost-redux/utils/user_utils'; - -export function displayUsernameForUser(user, config) { - if (user) { - const nameFormat = config.TeammateNameDisplay; - let name = user.username; - if (nameFormat === 'nickname_full_name' && user.nickname && user.nickname !== '') { - name = user.nickname; - } else if ((user.first_name || user.last_name) && (nameFormat === 'nickname_full_name' || nameFormat === 'full_name')) { - name = getFullName(user); - } - - return name; - } - - return ''; -}