|
7 | 7 | validButtonContent,
|
8 | 8 | getCredentialsFromLocalStorage,
|
9 | 9 | storeCredentialsToLocalStorage,
|
| 10 | + isLastMessageForIndex, |
10 | 11 | } from 'helpers'
|
11 | 12 |
|
12 | 13 | describe('Test the helper utilities', () => {
|
@@ -50,5 +51,46 @@ describe('Test the helper utilities', () => {
|
50 | 51 | storeCredentialsToLocalStorage('chatId', 'conversation-Id', 1, 'channelId')
|
51 | 52 | assert.propertyVal(getCredentialsFromLocalStorage('channelId', 1), 'conversationId', 'conversation-Id')
|
52 | 53 | })
|
| 54 | + |
| 55 | + it('Test isLastMessageForIndex', () => { |
| 56 | + assert.isFalse(isLastMessageForIndex(), 'No params') |
| 57 | + assert.isFalse(isLastMessageForIndex([], 0), 'Empty params') |
| 58 | + assert.isTrue(isLastMessageForIndex([{ attachment: { type: 'foo' } }], 0), 'Is first and last message') |
| 59 | + assert.isTrue(isLastMessageForIndex([ |
| 60 | + { attachment: { type: 'quickreplies' } }, |
| 61 | + { attachment: { type: 'client_data' } }], 0), 'Has client data after the first (quickreplies) message') |
| 62 | + assert.isFalse(isLastMessageForIndex([ |
| 63 | + { attachment: { type: 'text' } }, |
| 64 | + { attachment: { type: 'client_data' } }], 0), 'Has client data after the first (text) message') |
| 65 | + assert.isTrue(isLastMessageForIndex([ |
| 66 | + { attachment: { type: 'quickreplies' } }, |
| 67 | + { attachment: { type: 'client_data' } }, |
| 68 | + { attachment: { type: 'client_data' } }], 0), 'Has two client data after the first message') |
| 69 | + assert.isTrue(isLastMessageForIndex([{ attachment: { type: 'client_data' } }], 0), 'Only client data') |
| 70 | + assert.isFalse(isLastMessageForIndex([ |
| 71 | + { attachment: { type: 'quickreplies' } }, |
| 72 | + { attachment: { type: 'client_data' } }, |
| 73 | + { attachment: { type: 'buttons' } }, |
| 74 | + { attachment: { type: 'client_data' } }], 0)) |
| 75 | + assert.isFalse(isLastMessageForIndex([ |
| 76 | + { attachment: { type: 'quickreplies' } }, |
| 77 | + { attachment: { type: 'client_data' } }, |
| 78 | + { attachment: { type: 'buttons' } }, |
| 79 | + { attachment: { type: 'client_data' } }], 1)) |
| 80 | + assert.isTrue(isLastMessageForIndex([ |
| 81 | + { attachment: { type: 'button' } }, |
| 82 | + { attachment: { type: 'client_data' } }, |
| 83 | + { attachment: { type: 'quickreplies' } }, |
| 84 | + { attachment: { type: 'client_data' } }], 2)) |
| 85 | + assert.isFalse(isLastMessageForIndex([ |
| 86 | + { attachment: { type: 'quickreplies' } }, |
| 87 | + { attachment: { type: 'buttons' } }], 2), 'Test out of range') |
| 88 | + assert.isTrue(isLastMessageForIndex([ |
| 89 | + { attachment: { type: 'quickreplies' } }, |
| 90 | + { attachment: { type: 'buttons' } }], 1), 'Test is Last one') |
| 91 | + assert.isFalse(isLastMessageForIndex([ |
| 92 | + { attachment: { type: 'quickreplies' } }, |
| 93 | + { attachment: { type: 'buttons' } }], 0), 'Is First message') |
| 94 | + }) |
53 | 95 | })
|
54 | 96 |
|
0 commit comments