chore: Repalce message formatter mixin with useMessageFormatter [CW-3470] (#9986)
# Pull Request Template ## Description Replaced the old messageFormatterMixin with a useMessageFormatter composable
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
import MessageFormatter from '../helpers/MessageFormatter';
|
||||
|
||||
export default {
|
||||
methods: {
|
||||
formatMessage(message, isATweet, isAPrivateNote) {
|
||||
const messageFormatter = new MessageFormatter(
|
||||
message,
|
||||
isATweet,
|
||||
isAPrivateNote
|
||||
);
|
||||
return messageFormatter.formattedMessage;
|
||||
},
|
||||
getPlainText(message, isATweet) {
|
||||
const messageFormatter = new MessageFormatter(message, isATweet);
|
||||
return messageFormatter.plainText;
|
||||
},
|
||||
truncateMessage(description = '') {
|
||||
if (description.length < 100) {
|
||||
return description;
|
||||
}
|
||||
|
||||
return `${description.slice(0, 97)}...`;
|
||||
},
|
||||
|
||||
highlightContent(content = '', searchTerm = '', highlightClass = '') {
|
||||
const plainTextContent = this.getPlainText(content);
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
|
||||
const escapedSearchTerm = searchTerm.replace(
|
||||
/[.*+?^${}()|[\]\\]/g,
|
||||
'\\$&'
|
||||
);
|
||||
|
||||
return plainTextContent.replace(
|
||||
new RegExp(`(${escapedSearchTerm})`, 'ig'),
|
||||
`<span class="${highlightClass}">$1</span>`
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
import { shallowMount } from '@vue/test-utils';
|
||||
import messageFormatterMixin from '../messageFormatterMixin';
|
||||
|
||||
describe('messageFormatterMixin', () => {
|
||||
it('returns correct plain text', () => {
|
||||
const Component = {
|
||||
render() {},
|
||||
mixins: [messageFormatterMixin],
|
||||
};
|
||||
const wrapper = shallowMount(Component);
|
||||
const message =
|
||||
'<b>Chatwoot is an opensource tool. https://www.chatwoot.com</b>';
|
||||
expect(wrapper.vm.getPlainText(message)).toMatch(
|
||||
'Chatwoot is an opensource tool. https://www.chatwoot.com'
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user