Skip to content

Commit 748a328

Browse files
committed
Move normalisation logic and remove unnecessary tests
1 parent a4f97bf commit 748a328

4 files changed

Lines changed: 16 additions & 108 deletions

File tree

packages/blocks/slack/src/lib/actions/request-action-message.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
username,
1818
usersAndChannels,
1919
} from '../common/props';
20-
import { normalizeEmojiString, slackSendMessage } from '../common/utils';
20+
import { slackSendMessage } from '../common/utils';
2121
import {
2222
onReceivedInteraction,
2323
waitForInteraction,
@@ -72,7 +72,7 @@ export const requestActionMessageAction = createAction({
7272

7373
const actions = context.propsValue.actions as SlackActionDefinition[];
7474
const actionLabels = actions.map((action) => {
75-
return normalizeEmojiString(action.buttonText);
75+
return action.buttonText;
7676
});
7777

7878
return await onReceivedInteraction(

packages/blocks/slack/src/lib/common/utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,3 @@ export function createMessageBlocksWithActions(
455455
export function normalizeEmojiString(str: string): string {
456456
return emoji.unemojify(str);
457457
}
458-
459-
export function emojifyString(str: string): string {
460-
return emoji.emojify(str);
461-
}

packages/blocks/slack/src/lib/common/wait-for-interaction.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
UserSelection,
1313
} from './message-interactions';
1414
import { MessageInfo } from './message-result';
15-
import { emojifyString, slackUpdateMessage } from './utils';
15+
import { normalizeEmojiString, slackUpdateMessage } from './utils';
1616

1717
export interface WaitForInteractionResult {
1818
user: string;
@@ -77,9 +77,16 @@ export async function onReceivedInteraction(
7777

7878
const userSelection = JSON.parse(resumePayload.actionClicked);
7979

80-
const isResumeForActionOnThisMessage =
81-
actions.includes(resumePayload.actionType) ||
82-
actions.includes((userSelection as UserSelection)?.value);
80+
const targetValues = [
81+
resumePayload.actionType,
82+
(userSelection as UserSelection)?.value,
83+
].filter(Boolean);
84+
85+
const matchedOriginalAction = actions.find((original) =>
86+
targetValues.includes(normalizeEmojiString(original)),
87+
);
88+
89+
const isResumeForActionOnThisMessage = Boolean(matchedOriginalAction);
8390

8491
const isResumeForThisMessage =
8592
resumePayload.path === currentExecutionPath &&
@@ -115,13 +122,11 @@ export async function onReceivedInteraction(
115122
resumePayload.userName,
116123
);
117124

118-
const emojifiedAction = Array.isArray(userSelection)
119-
? userSelection.map((opt) => emojifyString(opt.value))
120-
: emojifyString(userSelection.value);
121-
122125
return {
123126
user: resumePayload.userName,
124-
action: emojifiedAction,
127+
action: Array.isArray(userSelection)
128+
? userSelection.map((opt) => opt.value)
129+
: matchedOriginalAction || '',
125130
message: updatedMessage,
126131
userSelection,
127132
isExpired: false,

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

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -397,99 +397,6 @@ 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-
});
493400
});
494401

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

0 commit comments

Comments
 (0)