feat: Adds support for logo in portal settings page [CW-2585] (#8354)
This commit is contained in:
committed by
GitHub
parent
7380f0e7ce
commit
0af27a2387
@@ -96,3 +96,15 @@ export const getArticleSearchURL = ({
|
||||
|
||||
return `${host}/${portalSlug}/articles?${queryParams.toString()}`;
|
||||
};
|
||||
|
||||
export const hasValidAvatarUrl = avatarUrl => {
|
||||
try {
|
||||
const { host: avatarUrlHost } = new URL(avatarUrl);
|
||||
const isFromGravatar = ['www.gravatar.com', 'gravatar'].includes(
|
||||
avatarUrlHost
|
||||
);
|
||||
return avatarUrl && !isFromGravatar;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
isValidURL,
|
||||
conversationListPageURL,
|
||||
getArticleSearchURL,
|
||||
hasValidAvatarUrl,
|
||||
} from '../URLHelper';
|
||||
|
||||
describe('#URL Helpers', () => {
|
||||
@@ -164,4 +165,29 @@ describe('#URL Helpers', () => {
|
||||
expect(url).toBe('myurl.com/news/articles?page=1&locale=en');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasValidAvatarUrl', () => {
|
||||
test('should return true for valid non-Gravatar URL', () => {
|
||||
expect(hasValidAvatarUrl('https://chatwoot.com/avatar.jpg')).toBe(true);
|
||||
});
|
||||
|
||||
test('should return false for a Gravatar URL (www.gravatar.com)', () => {
|
||||
expect(hasValidAvatarUrl('https://www.gravatar.com/avatar.jpg')).toBe(
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
test('should return false for a Gravatar URL (gravatar)', () => {
|
||||
expect(hasValidAvatarUrl('https://gravatar/avatar.jpg')).toBe(false);
|
||||
});
|
||||
|
||||
test('should handle invalid URL', () => {
|
||||
expect(hasValidAvatarUrl('invalid-url')).toBe(false); // or expect an error, depending on function design
|
||||
});
|
||||
|
||||
test('should return false for empty or undefined URL', () => {
|
||||
expect(hasValidAvatarUrl('')).toBe(false);
|
||||
expect(hasValidAvatarUrl()).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user