Skip to content

Commit a4f97bf

Browse files
committed
Add tests for emoji normalisation
1 parent 3822b10 commit a4f97bf

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

packages/blocks/slack/test/request-action-message.test.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,99 @@ describe('requestActionMessageAction', () => {
397397
expect(mockContextWithHeader.store.put).not.toHaveBeenCalled();
398398
});
399399
});
400+
401+
describe('emoji normalization', () => {
402+
test('should normalize action labels when button text contains emojis', async () => {
403+
onReceivedInteractionMock.mockResolvedValue({
404+
user: 'a user',
405+
action: ':game_die: Reroll',
406+
isExpired: false,
407+
message: 'aaaa',
408+
userSelection: {
409+
value: ':game_die: Reroll',
410+
displayText: ':game_die: Reroll',
411+
},
412+
});
413+
414+
const mockContext = buildMockContext('Header', true);
415+
mockContext.propsValue.actions = [
416+
{
417+
buttonText: '🎲 Reroll',
418+
buttonStyle: 'primary',
419+
confirmationPrompt: false,
420+
confirmationPromptText: '',
421+
},
422+
];
423+
mockContext.store.get.mockResolvedValueOnce('aaaa');
424+
mockContext.executionType = ExecutionType.RESUME;
425+
426+
await requestActionMessageAction.run(mockContext);
427+
428+
expect(onReceivedInteractionMock).toHaveBeenCalledWith(
429+
'aaaa',
430+
[':game_die: Reroll'],
431+
mockContext,
432+
mockContext.currentExecutionPath,
433+
);
434+
});
435+
436+
test('should normalize action labels when button text contains custom emojis', async () => {
437+
onReceivedInteractionMock.mockResolvedValue({
438+
user: 'a user',
439+
action: ':custom_emoji: Action',
440+
isExpired: false,
441+
message: 'aaaa',
442+
userSelection: {
443+
value: ':custom_emoji: Action',
444+
displayText: ':custom_emoji: Action',
445+
},
446+
});
447+
448+
const mockContext = buildMockContext('Header', true);
449+
mockContext.propsValue.actions = [
450+
{
451+
buttonText: ':custom_emoji: Action',
452+
buttonStyle: 'primary',
453+
confirmationPrompt: false,
454+
confirmationPromptText: '',
455+
},
456+
];
457+
mockContext.store.get.mockResolvedValueOnce('aaaa');
458+
mockContext.executionType = ExecutionType.RESUME;
459+
460+
await requestActionMessageAction.run(mockContext);
461+
462+
expect(onReceivedInteractionMock).toHaveBeenCalledWith(
463+
'aaaa',
464+
[':custom_emoji: Action'],
465+
mockContext,
466+
mockContext.currentExecutionPath,
467+
);
468+
});
469+
470+
test('should normalize action labels when button text has no emojis', async () => {
471+
onReceivedInteractionMock.mockResolvedValue({
472+
user: 'a user',
473+
action: 'Approve',
474+
isExpired: false,
475+
message: 'aaaa',
476+
userSelection: { value: 'Approve', displayText: 'Approve' },
477+
});
478+
479+
const mockContext = buildMockContext('Header', true);
480+
mockContext.store.get.mockResolvedValueOnce('aaaa');
481+
mockContext.executionType = ExecutionType.RESUME;
482+
483+
await requestActionMessageAction.run(mockContext);
484+
485+
expect(onReceivedInteractionMock).toHaveBeenCalledWith(
486+
'aaaa',
487+
['Approve'],
488+
mockContext,
489+
mockContext.currentExecutionPath,
490+
);
491+
});
492+
});
400493
});
401494

402495
function buildMockContext(header: string, containsActions: boolean): any {

0 commit comments

Comments
 (0)