diff options
author | marco <marcoambrosini@pm.me> | 2022-03-17 16:44:39 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-03-21 14:08:28 +0300 |
commit | cb3d53aa11f4cd57c7ac9f2432fa04ada31ed644 (patch) | |
tree | f5029ad3ba29f09a9c79b0177adbe5e001ac7c6a /src/components/MessagesList/MessagesGroup/Message/Message.spec.js | |
parent | e62766fa7083b2ed88231b8cfa4b46dc063c2973 (diff) |
Fix delete message tests
Signed-off-by: marco <marcoambrosini@pm.me>
Diffstat (limited to 'src/components/MessagesList/MessagesGroup/Message/Message.spec.js')
-rw-r--r-- | src/components/MessagesList/MessagesGroup/Message/Message.spec.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/components/MessagesList/MessagesGroup/Message/Message.spec.js b/src/components/MessagesList/MessagesGroup/Message/Message.spec.js index ce90c6422..7cf34ab03 100644 --- a/src/components/MessagesList/MessagesGroup/Message/Message.spec.js +++ b/src/components/MessagesList/MessagesGroup/Message/Message.spec.js @@ -15,6 +15,7 @@ import DefaultParameter from './MessagePart/DefaultParameter' import MessageButtonsBar from './MessageButtonsBar/MessageButtonsBar.vue' import Message from './Message' +import ActionButton from '@nextcloud/vue/dist/Components/ActionButton' // needed because of https://github.com/vuejs/vue-test-utils/issues/1507 const RichTextStub = { @@ -591,6 +592,52 @@ describe('Message.vue', () => { }) }) + describe('delete action', () => { + test('deletes message', async () => { + let resolveDeleteMessage + const deleteMessage = jest.fn().mockReturnValue(new Promise((resolve, reject) => { resolveDeleteMessage = resolve })) + testStoreConfig.modules.messagesStore.actions.deleteMessage = deleteMessage + store = new Vuex.Store(testStoreConfig) + + // need to mock the date to be within 6h + const mockDate = new Date('2020-05-07 10:00:00') + jest.spyOn(global.Date, 'now') + .mockImplementation(() => mockDate) + + const wrapper = mount(Message, { + localVue, + store, + stubs: { + ActionButton, + MessageButtonsBar, + }, + propsData: messageProps, + }) + + wrapper.find(MessageButtonsBar).vm.$emit('delete') + + expect(deleteMessage).toHaveBeenCalledWith(expect.anything(), { + message: { + token: TOKEN, + id: 123, + }, + placeholder: expect.anything(), + }) + + await wrapper.vm.$nextTick() + expect(wrapper.vm.isDeleting).toBe(true) + expect(wrapper.find('.icon-loading-small').exists()).toBe(true) + + resolveDeleteMessage(200) + // needs two updates... + await wrapper.vm.$nextTick() + await wrapper.vm.$nextTick() + + expect(wrapper.vm.isDeleting).toBe(false) + expect(wrapper.find('.icon-loading-small').exists()).toBe(false) + }) + }) + describe('status', () => { beforeEach(() => { store = new Vuex.Store(testStoreConfig) |