Skip to content

Commit 272559d

Browse files
committed
Move reaction tests to its corresponsing components tests suite
Signed-off-by: DorraJaouad <[email protected]>
1 parent 3fbc0b8 commit 272559d

File tree

2 files changed

+244
-162
lines changed

2 files changed

+244
-162
lines changed

Diff for: src/components/MessagesList/MessagesGroup/Message/Message.spec.js

-162
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import CheckAll from 'vue-material-design-icons/CheckAll.vue'
1010

1111
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
1212
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
13-
import NcEmojiPicker from '@nextcloud/vue/dist/Components/NcEmojiPicker.js'
1413

1514
import Message from './Message.vue'
1615
import MessageButtonsBar from './MessageButtonsBar/MessageButtonsBar.vue'
@@ -39,10 +38,6 @@ const RichTextStub = {
3938
template: '<div/>',
4039
}
4140

42-
const NcPopoverStub = {
43-
template: '<slot name="trigger" /><slot/>',
44-
}
45-
4641
describe('Message.vue', () => {
4742
const TOKEN = 'XXTOKENXX'
4843
let localVue
@@ -756,161 +751,4 @@ describe('Message.vue', () => {
756751
expect(wrapper.findComponent(CheckAll).exists()).toBe(false)
757752
})
758753
})
759-
760-
describe('reactions', () => {
761-
beforeEach(() => {
762-
messageProps.reactions = { '❤️': 1, '👍': 7 }
763-
messageProps.reactionsSelf = ['👍']
764-
store = new Store(testStoreConfig)
765-
})
766-
767-
test('shows reaction buttons with count and emoji picker', () => {
768-
// Arrange
769-
const wrapper = shallowMount(Message, {
770-
localVue,
771-
store,
772-
propsData: messageProps,
773-
provide: injected,
774-
stubs: {
775-
NcPopover: NcPopoverStub,
776-
},
777-
})
778-
779-
// Assert
780-
const reactionButtons = wrapper.findAllComponents({ name: 'NcButton' })
781-
expect(reactionButtons).toHaveLength(3) // 2 for reactions and 1 for emoji picker
782-
expect(reactionButtons.at(0).text()).toBe('❤️ 1')
783-
expect(reactionButtons.at(1).text()).toBe('👍 7')
784-
})
785-
786-
test('shows reaction buttons with count but without emoji picker when no chat permission', () => {
787-
// Arrange
788-
const conversationProps = {
789-
token: TOKEN,
790-
lastCommonReadMessage: 0,
791-
type: CONVERSATION.TYPE.GROUP,
792-
readOnly: CONVERSATION.STATE.READ_WRITE,
793-
permissions: PARTICIPANT.PERMISSIONS.MAX_DEFAULT - PARTICIPANT.PERMISSIONS.CHAT,
794-
}
795-
testStoreConfig.modules.conversationsStore.getters.conversation
796-
= jest.fn().mockReturnValue((token) => conversationProps)
797-
store = new Store(testStoreConfig)
798-
799-
const wrapper = shallowMount(Message, {
800-
localVue,
801-
store,
802-
propsData: messageProps,
803-
provide: injected,
804-
stubs: {
805-
NcPopover: NcPopoverStub,
806-
},
807-
})
808-
809-
// Assert
810-
const reactionButtons = wrapper.findAllComponents({ name: 'NcButton' })
811-
expect(reactionButtons).toHaveLength(2) // 2 for reactions
812-
expect(reactionButtons.at(0).text()).toBe('❤️ 1')
813-
expect(reactionButtons.at(1).text()).toBe('👍 7')
814-
})
815-
816-
test('doesn\'t mount emoji picker when there are no reactions', () => {
817-
// Arrange
818-
messageProps.reactions = { }
819-
const wrapper = shallowMount(Message, {
820-
localVue,
821-
store,
822-
propsData: messageProps,
823-
provide: injected,
824-
stubs: {
825-
NcEmojiPicker,
826-
},
827-
})
828-
829-
// Assert
830-
const reactionButtons = wrapper.findAllComponents({ name: 'NcButton' })
831-
expect(reactionButtons).toHaveLength(0)
832-
const emojiPicker = wrapper.findComponent(NcEmojiPicker)
833-
expect(emojiPicker.exists()).toBeFalsy()
834-
expect(emojiPicker.vm).toBeUndefined()
835-
})
836-
837-
test('dispatches store actions upon picking an emoji from the emojipicker', () => {
838-
// Arrange
839-
const addReactionToMessageAction = jest.fn()
840-
const removeReactionFromMessageAction = jest.fn()
841-
testStoreConfig.modules.messagesStore.actions.addReactionToMessage = addReactionToMessageAction
842-
testStoreConfig.modules.messagesStore.actions.removeReactionFromMessage = removeReactionFromMessageAction
843-
store = new Store(testStoreConfig)
844-
845-
const wrapper = shallowMount(Message, {
846-
localVue,
847-
store,
848-
propsData: messageProps,
849-
provide: injected,
850-
stubs: {
851-
NcEmojiPicker,
852-
},
853-
computed: {
854-
showMessageButtonsBar: () => {
855-
return true
856-
},
857-
},
858-
})
859-
860-
// Act
861-
const emojiPicker = wrapper.findComponent(NcEmojiPicker)
862-
emojiPicker.vm.$emit('select', '❤️')
863-
emojiPicker.vm.$emit('select', '👍')
864-
865-
// Assert
866-
expect(addReactionToMessageAction).toHaveBeenCalledWith(expect.anything(), {
867-
token: messageProps.token,
868-
messageId: messageProps.id,
869-
selectedEmoji: '❤️',
870-
})
871-
expect(removeReactionFromMessageAction).toHaveBeenCalledWith(expect.anything(), {
872-
token: messageProps.token,
873-
messageId: messageProps.id,
874-
selectedEmoji: '👍',
875-
actorId: messageProps.actorId,
876-
})
877-
})
878-
879-
test('dispatches store actions upon clicking a reaction buttons', () => {
880-
// Arrange
881-
const addReactionToMessageAction = jest.fn()
882-
const removeReactionFromMessageAction = jest.fn()
883-
testStoreConfig.modules.messagesStore.actions.addReactionToMessage = addReactionToMessageAction
884-
testStoreConfig.modules.messagesStore.actions.removeReactionFromMessage = removeReactionFromMessageAction
885-
store = new Store(testStoreConfig)
886-
887-
const wrapper = shallowMount(Message, {
888-
localVue,
889-
store,
890-
propsData: messageProps,
891-
provide: injected,
892-
stubs: {
893-
NcPopover: NcPopoverStub,
894-
},
895-
})
896-
897-
// Act
898-
const reactionButtons = wrapper.findAllComponents({ name: 'NcButton' })
899-
reactionButtons.at(0).vm.$emit('click') // ❤️
900-
reactionButtons.at(1).vm.$emit('click') // 👍
901-
902-
// Assert
903-
expect(addReactionToMessageAction).toHaveBeenCalledWith(expect.anything(), {
904-
token: messageProps.token,
905-
messageId: messageProps.id,
906-
selectedEmoji: '❤️',
907-
})
908-
expect(removeReactionFromMessageAction).toHaveBeenCalledWith(expect.anything(), {
909-
token: messageProps.token,
910-
messageId: messageProps.id,
911-
selectedEmoji: '👍',
912-
actorId: messageProps.actorId,
913-
})
914-
})
915-
})
916754
})

0 commit comments

Comments
 (0)