add new globalSearch resolver + update useSearchRecords hook (#10457)
# Context To enable search records sorting by ts_rank_cd / ts_rank, we have decided to add a new search resolver serving `GlobalSearchRecordDTO`. ----- - [x] Test to add - work in progress closes https://github.com/twentyhq/core-team-issues/issues/357
This commit is contained in:
@ -1,3 +1,2 @@
|
||||
export * from './constants/AppLocales';
|
||||
export * from './constants/SourceLocale';
|
||||
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
import {
|
||||
getLogoUrlFromDomainName,
|
||||
sanitizeURL,
|
||||
} from '../getLogoUrlFromDomainName';
|
||||
|
||||
describe('sanitizeURL', () => {
|
||||
test('should sanitize the URL correctly', () => {
|
||||
expect(sanitizeURL('http://example.com/')).toBe('example.com');
|
||||
expect(sanitizeURL('https://www.example.com/')).toBe('example.com');
|
||||
expect(sanitizeURL('www.example.com')).toBe('example.com');
|
||||
expect(sanitizeURL('example.com')).toBe('example.com');
|
||||
expect(sanitizeURL('example.com/')).toBe('example.com');
|
||||
});
|
||||
|
||||
test('should handle undefined input', () => {
|
||||
expect(sanitizeURL(undefined)).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLogoUrlFromDomainName', () => {
|
||||
test('should return the correct logo URL for a given domain', () => {
|
||||
expect(getLogoUrlFromDomainName('example.com')).toBe(
|
||||
'https://twenty-icons.com/example.com',
|
||||
);
|
||||
|
||||
expect(getLogoUrlFromDomainName('http://example.com/')).toBe(
|
||||
'https://twenty-icons.com/example.com',
|
||||
);
|
||||
|
||||
expect(getLogoUrlFromDomainName('https://www.example.com/')).toBe(
|
||||
'https://twenty-icons.com/example.com',
|
||||
);
|
||||
|
||||
expect(getLogoUrlFromDomainName('www.example.com')).toBe(
|
||||
'https://twenty-icons.com/example.com',
|
||||
);
|
||||
|
||||
expect(getLogoUrlFromDomainName('example.com/')).toBe(
|
||||
'https://twenty-icons.com/example.com',
|
||||
);
|
||||
|
||||
expect(getLogoUrlFromDomainName('apple.com')).toBe(
|
||||
'https://twenty-icons.com/apple.com',
|
||||
);
|
||||
});
|
||||
|
||||
test('should handle undefined input', () => {
|
||||
expect(getLogoUrlFromDomainName(undefined)).toBe(undefined);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,14 @@
|
||||
export const sanitizeURL = (link: string | null | undefined) => {
|
||||
return link
|
||||
? link.replace(/(https?:\/\/)|(www\.)/g, '').replace(/\/$/, '')
|
||||
: '';
|
||||
};
|
||||
|
||||
export const getLogoUrlFromDomainName = (
|
||||
domainName?: string,
|
||||
): string | undefined => {
|
||||
const sanitizedDomain = sanitizeURL(domainName);
|
||||
return sanitizedDomain
|
||||
? `https://twenty-icons.com/${sanitizedDomain}`
|
||||
: undefined;
|
||||
};
|
||||
@ -1 +1,2 @@
|
||||
export * from './getImageAbsoluteURI';
|
||||
export * from './getLogoUrlFromDomainName';
|
||||
|
||||
Reference in New Issue
Block a user