@@ -17,6 +17,7 @@ import {
1717 MESSAGE_ACTIONS ,
1818 messageHasAttachments ,
1919 messageHasReactions ,
20+ OPTIONAL_MESSAGE_ACTIONS ,
2021 validateAndGetMessage ,
2122} from '../utils' ;
2223
@@ -90,6 +91,7 @@ describe('Message utils', () => {
9091 canReply : true ,
9192 } ;
9293 const actions = Object . values ( MESSAGE_ACTIONS ) ;
94+ const optionalActions = Object . values ( OPTIONAL_MESSAGE_ACTIONS ) ;
9395
9496 it . each ( [
9597 [ 'empty' , [ ] ] ,
@@ -131,31 +133,36 @@ describe('Message utils', () => {
131133 } ) ;
132134
133135 it . each ( [
134- [ 'allow' , 'edit' , 'canEdit' , true ] ,
135- [ 'not allow' , 'edit' , 'canEdit' , false ] ,
136- [ 'allow' , 'delete' , 'canDelete' , true ] ,
137- [ 'not allow' , 'delete' , 'canDelete' , false ] ,
138- [ 'allow' , 'flag' , 'canFlag' , true ] ,
139- [ 'not allow' , 'flag' , 'canFlag' , false ] ,
140- [ 'allow' , 'markUnread' , 'canMarkUnread' , true ] ,
141- [ 'not allow' , 'markUnread' , 'canMarkUnread' , false ] ,
142- [ 'allow' , 'mute' , 'canMute' , true ] ,
143- [ 'not allow' , 'mute' , 'canMute' , false ] ,
144- [ 'allow' , 'pin' , 'canPin' , true ] ,
145- [ 'not allow' , 'pin' , 'canPin' , false ] ,
146- [ 'allow' , 'quote' , 'canQuote' , true ] ,
147- [ 'not allow' , 'quote' , 'canQuote' , false ] ,
148- ] ) ( 'it should %s %s when %s is %s' , ( _ , action , capabilityKey , capabilityValue ) => {
149- const capabilities = {
150- [ capabilityKey ] : capabilityValue ,
151- } ;
152- const result = getMessageActions ( actions , capabilities ) ;
153- if ( capabilityValue ) {
154- expect ( result ) . toStrictEqual ( [ action ] ) ;
155- } else {
156- expect ( result ) . not . toStrictEqual ( [ action ] ) ;
157- }
158- } ) ;
136+ [ 'allow' , 'edit' , 'canEdit' , true , actions ] ,
137+ [ 'not allow' , 'edit' , 'canEdit' , false , actions ] ,
138+ [ 'allow' , 'delete' , 'canDelete' , true , actions ] ,
139+ [ 'not allow' , 'delete' , 'canDelete' , false , actions ] ,
140+ [ 'allow' , 'deleteForMe' , 'canDelete' , true , optionalActions ] ,
141+ [ 'not allow' , 'deleteForMe' , 'canDelete' , false , optionalActions ] ,
142+ [ 'allow' , 'flag' , 'canFlag' , true , actions ] ,
143+ [ 'not allow' , 'flag' , 'canFlag' , false , actions ] ,
144+ [ 'allow' , 'markUnread' , 'canMarkUnread' , true , actions ] ,
145+ [ 'not allow' , 'markUnread' , 'canMarkUnread' , false , actions ] ,
146+ [ 'allow' , 'mute' , 'canMute' , true , actions ] ,
147+ [ 'not allow' , 'mute' , 'canMute' , false , actions ] ,
148+ [ 'allow' , 'pin' , 'canPin' , true , actions ] ,
149+ [ 'not allow' , 'pin' , 'canPin' , false , actions ] ,
150+ [ 'allow' , 'quote' , 'canQuote' , true , actions ] ,
151+ [ 'not allow' , 'quote' , 'canQuote' , false , actions ] ,
152+ ] ) (
153+ 'it should %s %s when %s is %s' ,
154+ ( _ , action , capabilityKey , capabilityValue , actionsToUse ) => {
155+ const capabilities = {
156+ [ capabilityKey ] : capabilityValue ,
157+ } ;
158+ const result = getMessageActions ( actionsToUse , capabilities ) ;
159+ if ( capabilityValue ) {
160+ expect ( result ) . toStrictEqual ( [ action ] ) ;
161+ } else {
162+ expect ( result ) . not . toStrictEqual ( [ action ] ) ;
163+ }
164+ } ,
165+ ) ;
159166 } ) ;
160167
161168 describe ( 'shouldMessageComponentUpdate' , ( ) => {
0 commit comments