diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-06-03 12:23:22 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-06-03 15:28:19 +0300 |
commit | ba86523110421c544680a2d155a2add94d4cb3c9 (patch) | |
tree | 6b6cc33e7bd99842f0767dda28bb71810877dc6f /src | |
parent | 596ff94612a3c774f014bd117e93c12faab1e3a2 (diff) |
Migrate from Mocha to jest
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/setup.js | 4 | ||||
-rw-r--r-- | src/tests/unit/ReplyBuilder.spec.js | 14 | ||||
-rw-r--r-- | src/tests/unit/components/TextEditor.spec.js | 37 | ||||
-rw-r--r-- | src/tests/unit/crypto/mailvelope.spec.js | 4 | ||||
-rw-r--r-- | src/tests/unit/crypto/pgp.spec.js | 6 | ||||
-rw-r--r-- | src/tests/unit/errors/convert.spec.js | 10 | ||||
-rw-r--r-- | src/tests/unit/errors/match.spec.js | 4 | ||||
-rw-r--r-- | src/tests/unit/i18n/MailboxTranslator.spec.js | 4 | ||||
-rw-r--r-- | src/tests/unit/imap/MailboxSorter.spec.js | 8 | ||||
-rw-r--r-- | src/tests/unit/store/actions.spec.js | 217 | ||||
-rw-r--r-- | src/tests/unit/store/getters.spec.js | 16 | ||||
-rw-r--r-- | src/tests/unit/store/mutations.spec.js | 44 | ||||
-rw-r--r-- | src/tests/unit/util/priorityInbox.spec.js | 8 | ||||
-rw-r--r-- | src/tests/unit/util/text.spec.js | 38 |
14 files changed, 218 insertions, 196 deletions
diff --git a/src/tests/setup.js b/src/tests/setup.js index 2972909ab..d428ebba0 100644 --- a/src/tests/setup.js +++ b/src/tests/setup.js @@ -20,11 +20,7 @@ */ require('jsdom-global')() -const chai = require('chai') -const sinonChai = require('sinon-chai') -chai.use(sinonChai) -global.expect = chai.expect // https://github.com/vuejs/vue-test-utils/issues/936 // better fix for "TypeError: Super expression must either be null or // a function" than pinning an old version of prettier. diff --git a/src/tests/unit/ReplyBuilder.spec.js b/src/tests/unit/ReplyBuilder.spec.js index 4344b8c99..1b533331f 100644 --- a/src/tests/unit/ReplyBuilder.spec.js +++ b/src/tests/unit/ReplyBuilder.spec.js @@ -34,8 +34,8 @@ describe('ReplyBuilder', () => { const replyBodyTop = buildReplyBody(body) const replyBodyBottom = buildReplyBody(body, undefined, undefined, false) - expect(replyBodyTop).to.deep.equal(html('<p></p><p></p><div class="quote"><br>> Newsletter<br>> hello<br>> cheers</div>')) - expect(replyBodyBottom).to.deep.equal(html('<div class="quote"><br>> Newsletter<br>> hello<br>> cheers</div><p></p><p></p>')) + expect(replyBodyTop).toEqual(html('<p></p><p></p><div class="quote"><br>> Newsletter<br>> hello<br>> cheers</div>')) + expect(replyBodyBottom).toEqual(html('<div class="quote"><br>> Newsletter<br>> hello<br>> cheers</div><p></p><p></p>')) }) it('creates a reply body', () => { @@ -59,8 +59,8 @@ describe('ReplyBuilder', () => { false ) - expect(replyBodyTop.value.startsWith(html('<p></p><p></p><div class="quote">"Test User" test@user.ru – November 5, 2018 ').value)).to.be.true - expect(replyBodyBottom.value.endsWith(html('<p></p><p></p>').value)).to.be.true + expect(replyBodyTop.value.startsWith(html('<p></p><p></p><div class="quote">"Test User" test@user.ru – November 5, 2018 ').value)).toEqual(true) + expect(replyBodyBottom.value.endsWith(html('<p></p><p></p>').value)).toEqual(true) }) let envelope @@ -81,7 +81,7 @@ describe('ReplyBuilder', () => { const rawL2 = l2.map((a) => a.email) rawL1.sort() rawL2.sort() - expect(rawL1).to.deep.equal(rawL2) + expect(rawL1).toEqual(rawL2) } // b -> a to a -as b @@ -245,7 +245,7 @@ describe('ReplyBuilder', () => { const replySubject = buildReplySubject(orig) - expect(replySubject).to.equal('Re: Hello') + expect(replySubject).toEqual('Re: Hello') }) it("does not stack subject re:'s", () => { @@ -253,6 +253,6 @@ describe('ReplyBuilder', () => { const replySubject = buildReplySubject(orig) - expect(replySubject).to.equal('Re: Hello') + expect(replySubject).toEqual('Re: Hello') }) }) diff --git a/src/tests/unit/components/TextEditor.spec.js b/src/tests/unit/components/TextEditor.spec.js new file mode 100644 index 000000000..481491f39 --- /dev/null +++ b/src/tests/unit/components/TextEditor.spec.js @@ -0,0 +1,37 @@ +/* + * @copyright 2022 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2022 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import { shallowMount } from '@vue/test-utils' +import TextEditor from '../../../components/TextEditor' +import Vue from 'vue' + +describe('TextEditor', () => { + + it('shallow mounts', async() => { + const wrapper = shallowMount(TextEditor, { + propsData: { + value: 'bonjour', + bus: new Vue() + } + }) + }) + +}) diff --git a/src/tests/unit/crypto/mailvelope.spec.js b/src/tests/unit/crypto/mailvelope.spec.js index 29c6ab803..e37c8550c 100644 --- a/src/tests/unit/crypto/mailvelope.spec.js +++ b/src/tests/unit/crypto/mailvelope.spec.js @@ -33,7 +33,7 @@ describe('mailvelope', () => { const mailvelope = await getMailvelope() - expect(mailvelope).to.deep.equal(window.mailvelope) + expect(mailvelope).toEqual(window.mailvelope) }) it('loads dynamically', async() => { @@ -44,6 +44,6 @@ describe('mailvelope', () => { window.dispatchEvent(new Event('mailvelope')) const mailvelope = await p - expect(mailvelope).to.deep.equal(window.mailvelope) + expect(mailvelope).toEqual(window.mailvelope) }) }) diff --git a/src/tests/unit/crypto/pgp.spec.js b/src/tests/unit/crypto/pgp.spec.js index 338b607b7..2db052f0e 100644 --- a/src/tests/unit/crypto/pgp.spec.js +++ b/src/tests/unit/crypto/pgp.spec.js @@ -28,7 +28,7 @@ describe('pgp', () => { const isPgp = isPgpgMessage(messages) - expect(isPgp).to.equal(false) + expect(isPgp).toEqual(false) }) it('detects non-pgp HTML messages', () => { @@ -36,7 +36,7 @@ describe('pgp', () => { const isPgp = isPgpgMessage(messages) - expect(isPgp).to.equal(false) + expect(isPgp).toEqual(false) }) it('detects a pgp message', () => { @@ -44,6 +44,6 @@ describe('pgp', () => { const isPgp = isPgpgMessage(message) - expect(isPgp).to.equal(true) + expect(isPgp).toEqual(true) }) }) diff --git a/src/tests/unit/errors/convert.spec.js b/src/tests/unit/errors/convert.spec.js index 111b9ec83..54cd132d4 100644 --- a/src/tests/unit/errors/convert.spec.js +++ b/src/tests/unit/errors/convert.spec.js @@ -27,8 +27,8 @@ describe('convert error', () => { const result = convertAxiosError(error) - expect(result).to.not.be.an.instanceof(Error) - expect(result).to.equal(error) + expect(result instanceof Error).toEqual(false) + expect(result).toEqual(error) }) it('ignores errors it does not know', () => { @@ -42,8 +42,8 @@ describe('convert error', () => { const result = convertAxiosError(error) - expect(result).to.not.be.an.instanceof(Error) - expect(result).to.equal(error) + expect(result instanceof Error).toEqual(false) + expect(result).toEqual(error) }) it('converts known exceptions to errors', () => { @@ -64,6 +64,6 @@ describe('convert error', () => { const result = convertAxiosError(error) - expect(result).to.be.an.instanceof(Error) + expect(result instanceof Error).toEqual(true) }) }) diff --git a/src/tests/unit/errors/match.spec.js b/src/tests/unit/errors/match.spec.js index 88f563131..481214313 100644 --- a/src/tests/unit/errors/match.spec.js +++ b/src/tests/unit/errors/match.spec.js @@ -35,7 +35,7 @@ describe('match', () => { const error = new Error('henlo') matchError(error, map).then((result) => { - expect(expect(result).to.equal(3)) + expect(expect(result).toEqual(3)) done() }) }) @@ -49,7 +49,7 @@ describe('match', () => { error.name = 'MyErr' matchError(error, map).then((result) => { - expect(expect(result).to.equal(2)) + expect(expect(result).toEqual(2)) done() }) }) diff --git a/src/tests/unit/i18n/MailboxTranslator.spec.js b/src/tests/unit/i18n/MailboxTranslator.spec.js index b5338adb0..4b47095df 100644 --- a/src/tests/unit/i18n/MailboxTranslator.spec.js +++ b/src/tests/unit/i18n/MailboxTranslator.spec.js @@ -30,7 +30,7 @@ describe('MailboxTranslator', () => { const name = translate(mailbox) - expect(name).to.equal('Inbox') + expect(name).toEqual('Inbox') }) it('does not translate an arbitrary mailbox', () => { @@ -42,6 +42,6 @@ describe('MailboxTranslator', () => { const name = translate(mailbox) - expect(name).to.equal('Newsletters') + expect(name).toEqual('Newsletters') }) }) diff --git a/src/tests/unit/imap/MailboxSorter.spec.js b/src/tests/unit/imap/MailboxSorter.spec.js index db1a58df4..1be9e3cf7 100644 --- a/src/tests/unit/imap/MailboxSorter.spec.js +++ b/src/tests/unit/imap/MailboxSorter.spec.js @@ -35,7 +35,7 @@ describe('mailboxSorter', () => { const sorted = sortMailboxes(mailboxes) - expect(sorted).to.deep.equal([mb1, mb2]) + expect(sorted).toEqual([mb1, mb2]) }) it('lists special mailboxes first', () => { @@ -51,7 +51,7 @@ describe('mailboxSorter', () => { const sorted = sortMailboxes(mailboxes) - expect(sorted).to.deep.equal([mb2, mb1]) + expect(sorted).toEqual([mb2, mb1]) }) it('sorts equally special mailboxes', () => { @@ -67,7 +67,7 @@ describe('mailboxSorter', () => { const sorted = sortMailboxes(mailboxes) - expect(sorted).to.deep.equal([mb1, mb2]) + expect(sorted).toEqual([mb1, mb2]) }) it('sorts real-world mailboxes', () => { @@ -99,6 +99,6 @@ describe('mailboxSorter', () => { const sorted = sortMailboxes(mailboxes) - expect(sorted).to.deep.equal([mb2, mb1, mb5, mb6, mb4, mb3]) + expect(sorted).toEqual([mb2, mb1, mb5, mb6, mb4, mb3]) }) }) diff --git a/src/tests/unit/store/actions.spec.js b/src/tests/unit/store/actions.spec.js index 1351cec27..45ec355fc 100644 --- a/src/tests/unit/store/actions.spec.js +++ b/src/tests/unit/store/actions.spec.js @@ -19,7 +19,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -import sinon from 'sinon' import { curry, prop, range, reverse } from 'ramda' import orderBy from 'lodash/fp/orderBy' @@ -29,6 +28,10 @@ import * as MessageService from '../../../service/MessageService' import * as NotificationService from '../../../service/NotificationService' import { UNIFIED_ACCOUNT_ID, UNIFIED_INBOX_ID, PAGE_SIZE } from '../../../store/constants' +jest.mock('../../../service/MailboxService') +jest.mock('../../../service/MessageService') +jest.mock('../../../service/NotificationService') + const mockEnvelope = curry((mailboxId, uid) => ({ mailboxId, uid, @@ -39,25 +42,19 @@ describe('Vuex store actions', () => { let context beforeEach(() => { - sinon.stub(MailboxService, 'create') - context = { - commit: sinon.stub(), - dispatch: sinon.stub(), + commit: jest.fn(), + dispatch: jest.fn(), getters: { accounts: [], - getMailbox: sinon.stub(), - getMailboxes: sinon.stub(), - getEnvelope: sinon.stub(), - getEnvelopes: sinon.stub(), + getMailbox: jest.fn(), + getMailboxes: jest.fn(), + getEnvelope: jest.fn(), + getEnvelopes: jest.fn(), }, } }) - afterEach(() => { - sinon.restore() - }) - it('creates a mailbox', async () => { const account = { id: 13, @@ -67,13 +64,14 @@ describe('Vuex store actions', () => { const mailbox = { 'name': 'Important', } - MailboxService.create.withArgs(13, 'Important').returns(mailbox) + MailboxService.create.mockResolvedValue(mailbox) const result = await actions.createMailbox(context, {account, name}) - expect(result).to.deep.equal(mailbox) - expect(context.commit).to.have.been.calledThrice - expect(context.commit).to.have.been.calledWith('addMailbox', { account, mailbox}) + expect(result).toEqual(mailbox) + expect(context.commit).toHaveBeenCalledTimes(3) + expect(context.commit).toBeCalledWith('addMailbox', { account, mailbox}) + expect(MailboxService.create).toHaveBeenCalledWith(13, 'Important') }) it('creates a sub-mailbox', async () => { @@ -85,13 +83,14 @@ describe('Vuex store actions', () => { const mailbox = { 'name': 'Archive.2020', } - MailboxService.create.withArgs(13, 'Archive.2020').returns(mailbox) + MailboxService.create.mockResolvedValue(mailbox) const result = await actions.createMailbox(context, {account, name}) - expect(result).to.deep.equal(mailbox) - expect(context.commit).to.have.been.calledThrice - expect(context.commit).to.have.been.calledWith('addMailbox', { account, mailbox}) + expect(result).toEqual(mailbox) + expect(context.commit).toHaveBeenCalledTimes(3) + expect(context.commit).toBeCalledWith('addMailbox', { account, mailbox}) + expect(MailboxService.create).toHaveBeenCalledWith(13, 'Archive.2020') }) it('adds a prefix to new mailboxes if the account has a personal namespace', async () => { @@ -103,13 +102,14 @@ describe('Vuex store actions', () => { const mailbox = { 'name': 'INBOX.Important', } - MailboxService.create.withArgs(13, 'INBOX.Important').returns(mailbox) + MailboxService.create.mockResolvedValue(mailbox) const result = await actions.createMailbox(context, {account, name}) - expect(result).to.deep.equal(mailbox) - expect(context.commit).to.have.been.calledThrice - expect(context.commit).to.have.been.calledWith('addMailbox', { account, mailbox}) + expect(result).toEqual(mailbox) + expect(context.commit).toHaveBeenCalledTimes(3) + expect(context.commit).toBeCalledWith('addMailbox', { account, mailbox}) + expect(MailboxService.create).toHaveBeenCalledWith(13, 'INBOX.Important') }) it('adds no prefix to new sub-mailboxes if the account has a personal namespace', async () => { @@ -121,37 +121,38 @@ describe('Vuex store actions', () => { const mailbox = { 'name': 'INBOX.Archive.2020', } - MailboxService.create.withArgs(13, 'INBOX.Archive.2020').returns(mailbox) + MailboxService.create.mockResolvedValue(mailbox) const result = await actions.createMailbox(context, {account, name}) - expect(result).to.deep.equal(mailbox) - expect(context.commit).to.have.been.calledThrice - expect(context.commit).to.have.been.calledWith('addMailbox', { account, mailbox}) + expect(result).toEqual(mailbox) + expect(context.commit).toHaveBeenCalledTimes(3) + expect(context.commit).toBeCalledWith('addMailbox', { account, mailbox}) + expect(MailboxService.create).toHaveBeenCalledWith(13, 'INBOX.Archive.2020') }) - it('combines unified inbox even if no inboxes are present', () => { - context.getters.getMailbox.returns({ + it('combines unified inbox even if no inboxes are present', async() => { + context.getters.getMailbox.mockReturnValueOnce({ isUnified: true, }) - const envelopes = actions.fetchEnvelopes(context, { + const envelopes = await actions.fetchEnvelopes(context, { mailboxId: UNIFIED_INBOX_ID, }) - expect(envelopes).to.be.empty + expect(envelopes).toEqual([]) }) it('creates a unified page from one mailbox', async() => { context.getters.accounts.push({ id: 13, }) - context.getters.getMailbox.withArgs(UNIFIED_INBOX_ID).returns({ + context.getters.getMailbox.mockReturnValueOnce({ isUnified: true, specialRole: 'inbox', databaseId: UNIFIED_INBOX_ID, }) - context.getters.getMailboxes.withArgs(13).returns([ + context.getters.getMailboxes.mockReturnValueOnce([ { id: 'INBOX', databaseId: 21, @@ -165,13 +166,7 @@ describe('Vuex store actions', () => { specialRole: 'draft', }, ]) - context.dispatch - .withArgs('fetchEnvelopes', { - mailboxId: 21, - query: undefined, - addToUnifiedMailboxes: false, - }) - .returns([ + context.dispatch.mockReturnValueOnce([ { databaseId: 123, mailboxId: 21, @@ -184,7 +179,9 @@ describe('Vuex store actions', () => { mailboxId: UNIFIED_INBOX_ID, }) - expect(envelopes).to.deep.equal([ + expect(context.getters.getMailbox).toHaveBeenCalledWith(UNIFIED_INBOX_ID) + expect(context.getters.getMailboxes).toHaveBeenCalledWith(13) + expect(envelopes).toEqual([ { databaseId: 123, mailboxId: 21, @@ -192,13 +189,12 @@ describe('Vuex store actions', () => { subject: 'msg1', }, ]) - expect(context.dispatch).to.have.been.calledOnce - expect(context.dispatch).to.have.been.calledWith('fetchEnvelopes', { + expect(context.dispatch).toBeCalledWith('fetchEnvelopes', { mailboxId: 21, query: undefined, addToUnifiedMailboxes: false, }) - expect(context.commit).to.have.been.calledWith('addEnvelope', { + expect(context.commit).toBeCalledWith('addEnvelope', { envelope: { databaseId: 123, mailboxId: 21, @@ -213,7 +209,7 @@ describe('Vuex store actions', () => { context.getters.accounts.push({ accountId: 13, }) - context.getters.getMailbox.withArgs(13).returns({ + context.getters.getMailbox.mockReturnValueOnce({ name: 'INBOX', databaseId: 11, accountId: 13, @@ -222,25 +218,22 @@ describe('Vuex store actions', () => { '': reverse(range(21, 40)), }, }) - context.getters.getEnvelope - .withArgs(21) - .returns(mockEnvelope(11, 1)) - sinon.stub(MessageService, 'fetchEnvelopes').returns( - Promise.resolve( - reverse( - range(1, 21).map((n) => ({ - uid: n, - dateInt: n * 10000, - })) - ) + context.getters.getEnvelope.mockReturnValueOnce(mockEnvelope(11, 1)) + MessageService.fetchEnvelopes.mockResolvedValue(Promise.resolve( + reverse( + range(1, 21).map((n) => ({ + uid: n, + dateInt: n * 10000, + })) ) - ) + )) - const page = await actions.fetchNextEnvelopePage(context, { + await actions.fetchNextEnvelopes(context, { mailboxId: 13, + quantity: PAGE_SIZE, }) - expect(context.dispatch).to.have.been.calledOnce + expect(MessageService.fetchEnvelopes).toHaveBeenCalled() }) it('builds the next unified page with local data', async() => { @@ -254,13 +247,13 @@ describe('Vuex store actions', () => { context.getters.accounts.push({ id: 26, }) - context.getters.getMailbox.withArgs(UNIFIED_INBOX_ID).returns({ + context.getters.getMailbox.mockReturnValueOnce({ isUnified: true, specialRole: 'inbox', accountId: UNIFIED_ACCOUNT_ID, databaseId: UNIFIED_INBOX_ID, }) - context.getters.getMailboxes.withArgs(13).returns([ + context.getters.getMailboxes.mockReturnValueOnce([ { name: 'INBOX', databaseId: 11, @@ -272,7 +265,7 @@ describe('Vuex store actions', () => { specialRole: 'draft', }, ]) - context.getters.getMailboxes.withArgs(26).returns([ + context.getters.getMailboxes.mockReturnValueOnce([ { name: 'INBOX', databaseId: 21, @@ -286,28 +279,28 @@ describe('Vuex store actions', () => { specialRole: 'draft', }, ]) - context.getters.getEnvelopes - .withArgs(UNIFIED_INBOX_ID, undefined) - .returns( + context.getters.getEnvelopes.mockReturnValueOnce( orderBy( prop('dateInt'), 'desc', page1.map(mockEnvelope(11)).concat(page2.map(mockEnvelope(21))) ) ) - context.getters.getEnvelopes.withArgs(11, undefined).returns(msgs1.map(mockEnvelope(11))) - context.getters.getEnvelopes.withArgs(21, undefined).returns(msgs2.map(mockEnvelope(21))) + context.getters.getEnvelopes.mockReturnValueOnce(msgs1.map(mockEnvelope(11))) + context.getters.getEnvelopes.mockReturnValueOnce(msgs2.map(mockEnvelope(21))) - const page = await actions.fetchNextEnvelopePage(context, { + await actions.fetchNextEnvelopes(context, { mailboxId: UNIFIED_INBOX_ID, + quantity: PAGE_SIZE, }) - expect(context.dispatch).to.have.been.calledOnce - expect(context.dispatch).have.been.calledWith('fetchNextEnvelopes', { - mailboxId: UNIFIED_INBOX_ID, - query: undefined, - quantity: PAGE_SIZE - }) + expect(context.getters.getMailbox).toHaveBeenCalledWith(UNIFIED_INBOX_ID) + expect(context.getters.getMailboxes).toHaveBeenCalledWith(13) + expect(context.getters.getMailboxes).toHaveBeenCalledWith(26) + expect(context.getters.getEnvelopes).toHaveBeenCalledTimes(3) + expect(context.getters.getEnvelopes).toHaveBeenCalledWith(UNIFIED_INBOX_ID, undefined) + expect(context.getters.getEnvelopes).toHaveBeenCalledWith(11, undefined) + expect(context.getters.getEnvelopes).toHaveBeenCalledWith(21, undefined) }) it('builds the next unified page with partial fetch', async() => { @@ -321,14 +314,14 @@ describe('Vuex store actions', () => { context.getters.accounts.push({ id: 26, }) - context.getters.getMailbox.withArgs(UNIFIED_INBOX_ID).returns({ + context.getters.getMailbox.mockReturnValueOnce({ isUnified: true, databaseId: UNIFIED_INBOX_ID, specialRole: 'inbox', accountId: UNIFIED_ACCOUNT_ID, id: UNIFIED_INBOX_ID, }) - context.getters.getMailboxes.withArgs(13).returns([ + context.getters.getMailboxes.mockReturnValueOnce([ { name: 'INBOX', databaseId: 11, @@ -340,7 +333,7 @@ describe('Vuex store actions', () => { specialRole: 'draft', }, ]) - context.getters.getMailboxes.withArgs(26).returns([ + context.getters.getMailboxes.mockReturnValueOnce([ { name: 'INBOX', databaseId: 21, @@ -354,37 +347,30 @@ describe('Vuex store actions', () => { specialRole: 'draft', }, ]) - context.getters.getEnvelopes - .withArgs(UNIFIED_INBOX_ID, undefined) - .returns( + context.getters.getEnvelopes.mockReturnValueOnce( orderBy( prop('dateInt'), 'desc', page1.map(mockEnvelope(11)).concat(page2.map(mockEnvelope(12))) ) ) - context.getters.getEnvelopes.withArgs(11, undefined).returns(msgs1.map(mockEnvelope(11))) - context.getters.getEnvelopes.withArgs(21, undefined).returns(msgs2.map(mockEnvelope(21))) + context.getters.getEnvelopes.mockReturnValueOnce(msgs1.map(mockEnvelope(11))) + context.getters.getEnvelopes.mockReturnValueOnce(msgs2.map(mockEnvelope(21))) - await actions.fetchNextEnvelopePage(context, { + await actions.fetchNextEnvelopes(context, { mailboxId: UNIFIED_INBOX_ID, + quantity: PAGE_SIZE, }) - expect(context.dispatch).have.been.calledOnce - expect(context.dispatch).have.been.calledWith('fetchNextEnvelopes', { - mailboxId: UNIFIED_INBOX_ID, - query: undefined, - quantity: PAGE_SIZE - }) + expect(context.getters.getMailbox).toHaveBeenCalledWith(UNIFIED_INBOX_ID) + expect(context.getters.getEnvelopes).toHaveBeenCalledWith(UNIFIED_INBOX_ID, undefined) + expect(context.getters.getEnvelopes).toHaveBeenCalledWith(11, undefined) + expect(context.getters.getEnvelopes).toHaveBeenCalledWith(21, undefined) }) describe('inbox sync', () => { beforeEach(() => { - sinon.stub(NotificationService, 'showNewMessagesNotification') - }) - afterEach(() => { - sinon.restore() }) it('fetches the inbox first', async() => { @@ -394,13 +380,13 @@ describe('Vuex store actions', () => { context.getters.accounts.push({ id: 26, }) - context.getters.getMailbox.withArgs(UNIFIED_INBOX_ID).returns({ + context.getters.getMailbox.mockReturnValueOnce({ isUnified: true, specialRole: 'inbox', accountId: UNIFIED_ACCOUNT_ID, id: UNIFIED_INBOX_ID, }) - context.getters.getMailboxes.withArgs(13).returns([ + context.getters.getMailboxes.mockReturnValueOnce([ { name: 'INBOX', databaseId: 11, @@ -414,7 +400,7 @@ describe('Vuex store actions', () => { envelopeLists: {}, }, ]) - context.getters.getMailboxes.withArgs(26).returns([ + context.getters.getMailboxes.mockReturnValueOnce([ { name: 'INBOX', databaseId: 21, @@ -433,21 +419,22 @@ describe('Vuex store actions', () => { await actions.syncInboxes(context) - expect(context.dispatch).have.callCount(4) // 2 fetch + 2 sync - expect(context.dispatch).have.been.calledWith('fetchEnvelopes', { + expect(context.getters.getMailboxes).toHaveBeenCalledTimes(2) + expect(context.dispatch).toHaveBeenCalledTimes(4) // 2 fetch + 2 sync + expect(context.dispatch).toBeCalledWith('fetchEnvelopes', { mailboxId: 11, }) - expect(context.dispatch).have.been.calledWith('syncEnvelopes', { + expect(context.dispatch).toBeCalledWith('syncEnvelopes', { mailboxId: 11, }) - expect(context.dispatch).have.been.calledWith('fetchEnvelopes', { + expect(context.dispatch).toBeCalledWith('fetchEnvelopes', { mailboxId: 21, }) - expect(context.dispatch).have.been.calledWith('syncEnvelopes', { + expect(context.dispatch).toBeCalledWith('syncEnvelopes', { mailboxId: 21, }) // We can't detect new messages here - expect(NotificationService.showNewMessagesNotification).not.have.been.called + expect(NotificationService.showNewMessagesNotification).not.toHaveBeenCalled }) it('syncs each individual mailbox', async() => { @@ -457,7 +444,7 @@ describe('Vuex store actions', () => { context.getters.accounts.push({ id: 26, }) - context.getters.getMailbox.withArgs(UNIFIED_INBOX_ID).returns({ + context.getters.getMailbox.mockReturnValue({ isUnified: true, specialRole: 'inbox', accountId: UNIFIED_ACCOUNT_ID, @@ -466,7 +453,7 @@ describe('Vuex store actions', () => { '': [], }, }) - context.getters.getMailboxes.withArgs(13).returns([ + context.getters.getMailboxes.mockReturnValueOnce([ { name: 'INBOX', databaseId: 11, @@ -484,7 +471,7 @@ describe('Vuex store actions', () => { }, }, ]) - context.getters.getMailboxes.withArgs(26).returns([ + context.getters.getMailboxes.mockReturnValueOnce([ { name: 'INBOX', databaseId: 21, @@ -505,22 +492,24 @@ describe('Vuex store actions', () => { }, ]) context.dispatch - .withArgs('syncEnvelopes', { - mailboxId: 11, - }) - .returns(Promise.resolve([{ id: 123 }, { id: 321 }])) + .mockReturnValueOnce(Promise.resolve([{ id: 123 }, { id: 321 }])) await actions.syncInboxes(context) + expect(context.getters.getMailbox).toHaveBeenCalledWith(UNIFIED_INBOX_ID) + expect(context.getters.getMailboxes).toHaveBeenCalledTimes(2) + expect(context.dispatch).toHaveBeenCalledWith('syncEnvelopes', { + mailboxId: 11, + }) //expect(context.dispatch).have.been - expect(context.dispatch).have.been.calledWith('syncEnvelopes', { + expect(context.dispatch).toBeCalledWith('syncEnvelopes', { mailboxId: 11, }) - expect(context.dispatch).have.been.calledWith('syncEnvelopes', { + expect(context.dispatch).toBeCalledWith('syncEnvelopes', { mailboxId: 21, }) // Here we expect notifications - expect(NotificationService.showNewMessagesNotification).have.been.called + expect(NotificationService.showNewMessagesNotification).toHaveBeenCalled }) }) }) diff --git a/src/tests/unit/store/getters.spec.js b/src/tests/unit/store/getters.spec.js index bc9798c1a..b578834c7 100644 --- a/src/tests/unit/store/getters.spec.js +++ b/src/tests/unit/store/getters.spec.js @@ -51,7 +51,7 @@ describe('Vuex store getters', () => { const accounts = getters.accounts - expect(accounts).to.deep.equal([ + expect(accounts).toEqual([ { accountId: 13, }, @@ -66,7 +66,7 @@ describe('Vuex store getters', () => { const accounts = getters.getAccount(13) - expect(accounts).to.deep.equal({ + expect(accounts).toEqual({ accountId: 13, }) }) @@ -80,7 +80,7 @@ describe('Vuex store getters', () => { const thread = getters.getEnvelopeThread(1) - expect(thread).to.be.empty + expect(thread.length).toEqual(0) }) it('returns an envelope\'s empty thread', () => { state.envelopes[1] = { @@ -107,8 +107,8 @@ describe('Vuex store getters', () => { const thread = getters.getEnvelopeThread(1) - expect(thread).to.not.be.empty - expect(thread).to.deep.equal([ + expect(thread.length).toBeGreaterThanOrEqual(1) + expect(thread).toEqual([ { databaseId: 1, uid: 101, @@ -171,8 +171,8 @@ describe('Vuex store getters', () => { const getters = bindGetters() const envelopesA = getters.getEnvelopesByThreadRootId(1, '123-456-789') - expect(envelopesA).to.be.length(2) - expect(envelopesA).to.deep.equal([ + expect(envelopesA.length).toEqual(2) + expect(envelopesA).toEqual([ { accountId: 1, databaseId: 1, @@ -190,6 +190,6 @@ describe('Vuex store getters', () => { ]) const envelopesB = getters.getEnvelopesByThreadRootId('345-678-901') - expect(envelopesB).to.be.empty + expect(envelopesB.length).toEqual(0) }) }) diff --git a/src/tests/unit/store/mutations.spec.js b/src/tests/unit/store/mutations.spec.js index c6be8b81a..7118251ef 100644 --- a/src/tests/unit/store/mutations.spec.js +++ b/src/tests/unit/store/mutations.spec.js @@ -44,7 +44,7 @@ describe('Vuex store mutations', () => { aliases: [], }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accountList: [13], accounts: { 13: { @@ -85,7 +85,7 @@ describe('Vuex store mutations', () => { aliases: [] }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accountList: [13], accounts: { 13: { @@ -149,7 +149,7 @@ describe('Vuex store mutations', () => { personalNamespace: 'INBOX.', }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accountList: [13], accounts: { 13: { @@ -228,7 +228,7 @@ describe('Vuex store mutations', () => { aliases: [] }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accountList: [13], accounts: { 13: { @@ -314,7 +314,7 @@ describe('Vuex store mutations', () => { aliases: [] }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accountList: [13], accounts: { 13: { @@ -421,7 +421,7 @@ describe('Vuex store mutations', () => { }, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accountList: [13], accounts: { 13: { @@ -512,7 +512,7 @@ describe('Vuex store mutations', () => { }, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accountList: [13], accounts: { 13: { @@ -583,7 +583,7 @@ describe('Vuex store mutations', () => { id: 27, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accounts: { 13: { accountId: 13, @@ -628,7 +628,7 @@ describe('Vuex store mutations', () => { id: 28, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accounts: { 13: { accountId: 13, @@ -681,7 +681,7 @@ describe('Vuex store mutations', () => { }, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accounts: { [UNIFIED_ACCOUNT_ID]: { accountId: UNIFIED_ACCOUNT_ID, @@ -757,7 +757,7 @@ describe('Vuex store mutations', () => { }, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accounts: { [UNIFIED_ACCOUNT_ID]: { accountId: UNIFIED_ACCOUNT_ID, @@ -836,7 +836,7 @@ describe('Vuex store mutations', () => { }, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accounts: { [UNIFIED_ACCOUNT_ID]: { accountId: UNIFIED_ACCOUNT_ID, @@ -930,7 +930,7 @@ describe('Vuex store mutations', () => { id: 12345, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accounts: { [UNIFIED_ACCOUNT_ID]: { accountId: UNIFIED_ACCOUNT_ID, @@ -1017,7 +1017,7 @@ describe('Vuex store mutations', () => { ], }) - expect(state).to.deep.equal({ + expect(state).toEqual({ mailboxes: { 27: { databaseId: 27, @@ -1099,7 +1099,7 @@ describe('Vuex store mutations', () => { }, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ accounts: { [UNIFIED_ACCOUNT_ID]: { accountId: UNIFIED_ACCOUNT_ID, @@ -1193,7 +1193,7 @@ describe('Vuex store mutations', () => { ], }) - expect(state).to.deep.equal({ + expect(state).toEqual({ mailboxes: { 27: { databaseId: 27, @@ -1274,7 +1274,7 @@ describe('Vuex store mutations', () => { }, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ mailboxes: { 27: { databaseId: 27, @@ -1338,7 +1338,7 @@ describe('Vuex store mutations', () => { tagId: tag.id, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ envelopes: { 12345: { mailboxId: 27, @@ -1386,7 +1386,7 @@ describe('Vuex store mutations', () => { tagId: tag.id, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ envelopes: { 12345: { mailboxId: 27, @@ -1420,7 +1420,7 @@ describe('Vuex store mutations', () => { }, }) - expect(state).to.deep.equal({ + expect(state).toEqual({ tagList: [ 1, ], @@ -1470,7 +1470,7 @@ describe('Vuex store mutations', () => { }, }) - expect(state.mailboxes[27].envelopeLists['']).to.be.length(1) + expect(state.mailboxes[27].envelopeLists[''].length).toEqual(1) mutations.addEnvelope(state, { query: undefined, @@ -1484,6 +1484,6 @@ describe('Vuex store mutations', () => { }, }) - expect(state.mailboxes[27].envelopeLists['']).to.be.length(1) + expect(state.mailboxes[27].envelopeLists[''].length).toEqual(1) }) }) diff --git a/src/tests/unit/util/priorityInbox.spec.js b/src/tests/unit/util/priorityInbox.spec.js index 35680fa97..2f50a8aa6 100644 --- a/src/tests/unit/util/priorityInbox.spec.js +++ b/src/tests/unit/util/priorityInbox.spec.js @@ -29,13 +29,13 @@ import { describe('priorityInbox', () => { it('has correct query constants', () => { - expect(priorityImportantQuery).to.equal('is:pi-important') - expect(priorityStarredQuery).to.equal('is:pi-starred') - expect(priorityOtherQuery).to.equal('is:pi-other') + expect(priorityImportantQuery).toEqual('is:pi-important') + expect(priorityStarredQuery).toEqual('is:pi-starred') + expect(priorityOtherQuery).toEqual('is:pi-other') }) it('returns all queries', () => { - expect(getPrioritySearchQueries()).to.deep.equal([ + expect(getPrioritySearchQueries()).toEqual([ 'is:pi-important', 'is:pi-starred', 'is:pi-other', diff --git a/src/tests/unit/util/text.spec.js b/src/tests/unit/util/text.spec.js index 3107011bd..20cf216e0 100644 --- a/src/tests/unit/util/text.spec.js +++ b/src/tests/unit/util/text.spec.js @@ -30,7 +30,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('removes leading line breaks', () => { @@ -39,7 +39,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('removes trailing line breaks', () => { @@ -48,7 +48,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('removes trailing spaces of each line', () => { @@ -57,7 +57,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('breaks on divs', () => { @@ -65,7 +65,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(plain('one\ntwo')) + expect(actual).toEqual(plain('one\ntwo')) }) it('merges spaces at the beginning of a line', () => { @@ -74,7 +74,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('produces a line break for each ending div element', () => { @@ -83,7 +83,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('converts blocks to text', () => { @@ -92,7 +92,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('converts paragraph to text', () => { @@ -101,7 +101,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('produces a single line break between paragraphs', () => { @@ -110,7 +110,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('produces a single line break between a div and a paragraph', () => { @@ -119,7 +119,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('produces a single line break after each block element', () => { @@ -133,7 +133,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('produces exactly one line break for each closing block element', () => { @@ -148,7 +148,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('converts lists to text', () => { @@ -157,7 +157,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('converts deeply nested elements to text', () => { @@ -170,7 +170,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('does not leak internal redirection URLs', () => { @@ -179,7 +179,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) it('preserves quotes', () => { @@ -205,7 +205,7 @@ describe('text', () => { const actual = toPlain(source) - expect(actual).to.deep.equal(expected) + expect(actual).toEqual(expected) }) }) @@ -215,7 +215,7 @@ describe('text', () => { const detected = detect(text) - expect(detected).to.deep.equal(plain(text)) + expect(detected).toEqual(plain(text)) }) it('detects html', () => { @@ -223,7 +223,7 @@ describe('text', () => { const detected = detect(text) - expect(detected).to.deep.equal(html(text)) + expect(detected).toEqual(html(text)) }) }) }) |