2021-09-13 10:26:18 +00:00
|
|
|
import {
|
|
|
|
getTypingUsersText,
|
|
|
|
createPendingMessage,
|
2022-07-26 06:45:01 +00:00
|
|
|
convertToAttributeSlug,
|
|
|
|
convertToCategorySlug,
|
2021-09-13 10:26:18 +00:00
|
|
|
} from '../commons';
|
2020-05-04 17:37:56 +00:00
|
|
|
|
|
|
|
describe('#getTypingUsersText', () => {
|
|
|
|
it('returns the correct text is there is only one typing user', () => {
|
|
|
|
expect(getTypingUsersText([{ name: 'Pranav' }])).toEqual(
|
|
|
|
'Pranav is typing'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the correct text is there are two typing users', () => {
|
|
|
|
expect(
|
|
|
|
getTypingUsersText([{ name: 'Pranav' }, { name: 'Nithin' }])
|
|
|
|
).toEqual('Pranav and Nithin are typing');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the correct text is there are more than two users are typing', () => {
|
|
|
|
expect(
|
|
|
|
getTypingUsersText([
|
|
|
|
{ name: 'Pranav' },
|
|
|
|
{ name: 'Nithin' },
|
|
|
|
{ name: 'Subin' },
|
|
|
|
{ name: 'Sojan' },
|
|
|
|
])
|
|
|
|
).toEqual('Pranav and 3 others are typing');
|
|
|
|
});
|
|
|
|
});
|
2020-12-25 07:45:01 +00:00
|
|
|
|
|
|
|
describe('#createPendingMessage', () => {
|
|
|
|
const message = {
|
|
|
|
message: 'hi',
|
|
|
|
};
|
|
|
|
it('returns the pending message with expected new keys', () => {
|
|
|
|
expect(createPendingMessage(message)).toHaveProperty(
|
|
|
|
'content',
|
|
|
|
'id',
|
|
|
|
'status',
|
|
|
|
'echo_id',
|
|
|
|
'status',
|
|
|
|
'created_at',
|
|
|
|
'message_type',
|
|
|
|
'conversation_id'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the pending message with status progress', () => {
|
|
|
|
expect(createPendingMessage(message)).toMatchObject({
|
|
|
|
status: 'progress',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the pending message with same id and echo_id', () => {
|
|
|
|
const pending = createPendingMessage(message);
|
|
|
|
expect(pending).toMatchObject({
|
|
|
|
echo_id: pending.id,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-06 12:26:29 +00:00
|
|
|
it('returns the pending message with attachmnet key if file is passed', () => {
|
|
|
|
const messageWithFile = {
|
|
|
|
message: 'hi',
|
|
|
|
file: {},
|
|
|
|
};
|
|
|
|
expect(createPendingMessage(messageWithFile)).toHaveProperty(
|
2020-12-25 07:45:01 +00:00
|
|
|
'content',
|
|
|
|
'id',
|
|
|
|
'status',
|
|
|
|
'echo_id',
|
|
|
|
'status',
|
|
|
|
'created_at',
|
|
|
|
'message_type',
|
|
|
|
'conversation_id',
|
|
|
|
'attachments',
|
|
|
|
'private'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the pending message to have one attachment', () => {
|
2021-01-06 12:26:29 +00:00
|
|
|
const messageWithFile = {
|
|
|
|
message: 'hi',
|
|
|
|
file: {},
|
|
|
|
};
|
|
|
|
const pending = createPendingMessage(messageWithFile);
|
2020-12-25 07:45:01 +00:00
|
|
|
expect(pending.attachments.length).toBe(1);
|
|
|
|
});
|
|
|
|
});
|
2021-09-13 10:26:18 +00:00
|
|
|
|
2022-07-26 06:45:01 +00:00
|
|
|
describe('convertToAttributeSlug', () => {
|
2021-09-13 10:26:18 +00:00
|
|
|
it('should convert to slug', () => {
|
2022-07-26 06:45:01 +00:00
|
|
|
expect(convertToAttributeSlug('Test@%^&*(){}>.!@`~_ ing')).toBe(
|
|
|
|
'test__ing'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('convertToCategorySlug', () => {
|
|
|
|
it('should convert to slug', () => {
|
|
|
|
expect(convertToCategorySlug('User profile guide')).toBe(
|
|
|
|
'user-profile-guide'
|
|
|
|
);
|
2021-09-13 10:26:18 +00:00
|
|
|
});
|
|
|
|
});
|