-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
436 utils folder typescript migration (#442)
* refactor. migrated date_utils file to typescript, add tests Signed-off-by: titanventura <aswath7862001@gmail.com> * refactor. migrated other utils to typescript, add tests Signed-off-by: titanventura <aswath7862001@gmail.com> --------- Signed-off-by: titanventura <aswath7862001@gmail.com>
- Loading branch information
1 parent
ee780c1
commit eab8193
Showing
8 changed files
with
45 additions
and
22 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
webapp/src/utils/regex_utils.test.js → webapp/src/utils/regex_utils.test.ts
This file contains 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
2 changes: 1 addition & 1 deletion
2
webapp/src/utils/regex_utils.js → webapp/src/utils/regex_utils.ts
This file contains 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 |
---|---|---|
@@ -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); | ||
} |
This file contains 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,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); | ||
}) | ||
}) |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,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); | ||
}) | ||
}) |
This file contains 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,4 @@ | ||
export const isDesktopApp = () => { | ||
const userAgent = window.navigator.userAgent; | ||
return userAgent.indexOf('Mattermost') !== -1 && userAgent.indexOf('Electron') !== -1 | ||
}; |
This file was deleted.
Oops, something went wrong.