Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
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);
}
13 changes: 13 additions & 0 deletions webapp/src/utils/url_utils.test.ts
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);
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const isValidUrl = (urlString) => {
export const isValidUrl = (urlString: string): boolean => {
try {
return Boolean(new URL(urlString));
} catch (e) {
Expand Down
3 changes: 0 additions & 3 deletions webapp/src/utils/user_agent.js

This file was deleted.

25 changes: 25 additions & 0 deletions webapp/src/utils/user_agent.test.ts
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);
})
})
4 changes: 4 additions & 0 deletions webapp/src/utils/user_agent.ts
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
};
17 changes: 0 additions & 17 deletions webapp/src/utils/user_utils.js

This file was deleted.