import { expect, test } from "@odoo/hoot"; import { markup } from "@odoo/owl"; import { patchWithCleanup } from "@web/../tests/web_test_helpers"; import { SocialPostFormatterMixinBase } from "@social/js/social_post_formatter_mixin"; const Markup = markup("").constructor; test("Facebook Message", () => { patchWithCleanup(SocialPostFormatterMixinBase, { _getMediaType() { return "facebook"; }, _formatPost() { this.originalPost = { account_id: { raw_value: 42 } }; return super._formatPost(...arguments); }, }); const testMessage = "Hello @[542132] Odoo-Social, check this out: https://www.odoo.com?utm=mail¶m=1,2,3 #crazydeals #odoo"; const finalMessage = SocialPostFormatterMixinBase._formatPost(testMessage); expect(finalMessage.toString()).toEqual( [ "Hello", "Odoo-Social,", "check this out:", "https://www.odoo.com?utm=mail&param=1,2,3", "#crazydeals", "#odoo", ].join(" ") ); expect(finalMessage).toBeInstanceOf(Markup); }); test("Instagram Message", () => { patchWithCleanup(SocialPostFormatterMixinBase, { _getMediaType() { return "instagram"; }, }); const testMessage = "Hello @Odoo.Social, check this out: https://www.odoo.com #crazydeals #odoo"; const finalMessage = SocialPostFormatterMixinBase._formatPost(testMessage); expect(finalMessage.toString()).toEqual( [ "Hello", "@Odoo.Social,", "check this out:", "https://www.odoo.com", "#crazydeals", "#odoo", ].join(" ") ); expect(finalMessage).toBeInstanceOf(Markup); }); test("LinkedIn Message", () => { patchWithCleanup(SocialPostFormatterMixinBase, { _getMediaType() { return "linkedin"; }, }); const testMessage = "Hello, check this out: https://www.odoo.com {hashtag|#|crazydeals} #odoo"; const finalMessage = SocialPostFormatterMixinBase._formatPost(testMessage); expect(finalMessage.toString()).toEqual( [ "Hello, check this out:", "https://www.odoo.com", "#crazydeals", "#odoo", ].join(" ") ); expect(finalMessage).toBeInstanceOf(Markup); }); test("Twitter Message", () => { patchWithCleanup(SocialPostFormatterMixinBase, { _getMediaType() { return "twitter"; }, }); const testMessage = "Hello @Odoo-Social, check this out: https://www.odoo.com #crazydeals #odoo"; const finalMessage = SocialPostFormatterMixinBase._formatPost(testMessage); expect(finalMessage.toString()).toEqual( [ "Hello", "@Odoo-Social,", "check this out:", "https://www.odoo.com", "#crazydeals", "#odoo", ].join(" ") ); expect(finalMessage).toBeInstanceOf(Markup); }); test("YouTube Message", () => { patchWithCleanup(SocialPostFormatterMixinBase, { _getMediaType() { return "youtube"; }, }); const testMessage = "Hello, check this out: https://www.odoo.com #crazydeals #odoo"; const finalMessage = SocialPostFormatterMixinBase._formatPost(testMessage); expect(finalMessage.toString()).toEqual( [ "Hello, check this out:", "https://www.odoo.com", "#crazydeals", "#odoo", ].join(" ") ); expect(finalMessage).toBeInstanceOf(Markup); }); test("URL regex supports special characters across all media types", () => { const mediaTypes = ['facebook', 'instagram', 'linkedin', 'twitter', 'youtube']; const testUrl = 'https://example.com/path(v1)/search?tags=$web,mobile*&price=$100'; const testMessage = `Check this URL: ${testUrl} #test`; const testUrlNoAnd = testUrl.replace(/&/g, '&'); expect.assertions(mediaTypes.length); mediaTypes.forEach(mediaType => { patchWithCleanup(SocialPostFormatterMixinBase, { _getMediaType() { return mediaType; }, }); const finalMessage = SocialPostFormatterMixinBase._formatPost(testMessage); const expectedUrlPattern = `${testUrlNoAnd}`; expect(finalMessage.includes(expectedUrlPattern)).toBe( true, { message: `URL with special characters (parentheses, asterisk, dollar sign, comma, apostrophe) should be properly formatted for ${mediaType}` } ); }); });