diff --git a/front/src/WebRtc/DiscussionManager.ts b/front/src/WebRtc/DiscussionManager.ts
index a2da32b2..7653bc7a 100644
--- a/front/src/WebRtc/DiscussionManager.ts
+++ b/front/src/WebRtc/DiscussionManager.ts
@@ -151,15 +151,6 @@ export class DiscussionManager {
this.nbpParticipants.innerText = `PARTICIPANTS (${nb})`;
}
- private urlify(text: string) {
- const urlRegex = /(https?:\/\/[^\s]+)/g;
- return text.replace(urlRegex, (url: string) => {
- return '' + url + '';
- })
- // or alternatively
- // return text.replace(urlRegex, '$1')
- }
-
public addMessage(name: string, message: string, isMe: boolean = false) {
const divMessage: HTMLDivElement = document.createElement('div');
divMessage.classList.add('message');
@@ -179,7 +170,7 @@ export class DiscussionManager {
divMessage.appendChild(pMessage);
const userMessage: HTMLParagraphElement = document.createElement('p');
- userMessage.innerHTML = this.urlify(message);
+ userMessage.innerHTML = HtmlUtils.urlify(message);
userMessage.classList.add('body');
divMessage.appendChild(userMessage);
this.divMessages?.appendChild(divMessage);
diff --git a/front/src/WebRtc/HtmlUtils.ts b/front/src/WebRtc/HtmlUtils.ts
index b7cb2124..81f069b3 100644
--- a/front/src/WebRtc/HtmlUtils.ts
+++ b/front/src/WebRtc/HtmlUtils.ts
@@ -17,4 +17,11 @@ export class HtmlUtils {
elem.remove();
return elem as T;
}
+
+ public static urlify(text: string): string {
+ const urlRegex = /(https?:\/\/[^\s]+)/g;
+ return text.replace(urlRegex, (url: string) => {
+ return '' + url + '';
+ })
+ }
}
diff --git a/front/tests/Phaser/Game/HtmlUtilsTest.ts b/front/tests/Phaser/Game/HtmlUtilsTest.ts
new file mode 100644
index 00000000..8ef1d476
--- /dev/null
+++ b/front/tests/Phaser/Game/HtmlUtilsTest.ts
@@ -0,0 +1,14 @@
+import "jasmine";
+import {HtmlUtils} from "../../../src/WebRtc/HtmlUtils";
+
+describe("urlify()", () => {
+ it("should transform an url into a link", () => {
+ const text = HtmlUtils.urlify('https://google.com');
+ expect(text).toEqual('https://google.com');
+ });
+
+ it("should not transform a normal text into a link", () => {
+ const text = HtmlUtils.urlify('hello');
+ expect(text).toEqual('hello');
+ });
+});
\ No newline at end of file