2018-10-22 12:02:13 +02:00
|
|
|
//@flow
|
2019-09-13 13:49:11 +02:00
|
|
|
import o from "ospec"
|
2018-10-22 12:02:13 +02:00
|
|
|
import {Notifications} from "../../../src/gui/Notifications"
|
2021-11-04 14:05:23 +01:00
|
|
|
import type {Spy} from "@tutao/tutanota-test-utils"
|
|
|
|
import {spy} from "@tutao/tutanota-test-utils"
|
2021-02-03 17:13:38 +01:00
|
|
|
import type {MailboxDetail} from "../../../src/mail/model/MailModel"
|
|
|
|
import {MailModel} from "../../../src/mail/model/MailModel"
|
2018-10-22 12:02:13 +02:00
|
|
|
import type {OperationTypeEnum} from "../../../src/api/common/TutanotaConstants"
|
|
|
|
import {MailFolderType, OperationType} from "../../../src/api/common/TutanotaConstants"
|
|
|
|
import {MailTypeRef} from "../../../src/api/entities/tutanota/Mail"
|
|
|
|
import {createMailFolder} from "../../../src/api/entities/tutanota/MailFolder"
|
2019-01-21 10:48:07 +01:00
|
|
|
import type {EntityUpdateData} from "../../../src/api/main/EventController"
|
2019-09-13 13:49:11 +02:00
|
|
|
import {EntityClient} from "../../../src/api/common/EntityClient"
|
2021-09-24 13:26:42 +02:00
|
|
|
import {EntityRestClientMock} from "../../api/worker/EntityRestClientMock"
|
|
|
|
import nodemocker from "../nodemocker"
|
2021-11-04 14:05:23 +01:00
|
|
|
import {downcast} from "@tutao/tutanota-utils"
|
2018-10-22 12:02:13 +02:00
|
|
|
|
|
|
|
o.spec("MailModelTest", function () {
|
2021-12-23 14:03:23 +01:00
|
|
|
let notifications: Partial<Notifications>
|
2018-10-22 12:02:13 +02:00
|
|
|
let showSpy: Spy
|
|
|
|
let model: MailModel
|
|
|
|
|
|
|
|
const inboxFolder = createMailFolder()
|
|
|
|
inboxFolder.mails = "instanceListId"
|
|
|
|
inboxFolder.folderType = MailFolderType.INBOX
|
|
|
|
|
|
|
|
const anotherFolder = createMailFolder()
|
|
|
|
anotherFolder.mails = "anotherListId"
|
|
|
|
anotherFolder.folderType = MailFolderType.ARCHIVE
|
|
|
|
|
2021-12-23 14:03:23 +01:00
|
|
|
const mailboxDetails: Partial<MailboxDetail>[] = [
|
2018-10-22 12:02:13 +02:00
|
|
|
{
|
|
|
|
folders: [inboxFolder]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
o.beforeEach(function () {
|
|
|
|
notifications = {}
|
|
|
|
showSpy = notifications.showNotification = spy()
|
2021-09-24 13:26:42 +02:00
|
|
|
const restClient = new EntityRestClientMock()
|
|
|
|
const workerClient = nodemocker.mock("worker", {}).set()
|
|
|
|
const mailFacade = nodemocker.mock("mailFacade", {}).set()
|
|
|
|
model = new MailModel(downcast(notifications), downcast({}), workerClient, mailFacade, new EntityClient(restClient))
|
2018-10-22 12:02:13 +02:00
|
|
|
// not pretty, but works
|
|
|
|
model.mailboxDetails(mailboxDetails)
|
|
|
|
})
|
|
|
|
|
2019-04-24 11:47:18 +02:00
|
|
|
// FIXME No way to inject entityRestClient for now
|
|
|
|
// o("sends notification on new email in inbox", function () {
|
|
|
|
// model.entityEventsReceived([
|
|
|
|
// makeUpdate({
|
|
|
|
// instanceListId: inboxFolder.mails,
|
|
|
|
// operation: OperationType.CREATE
|
|
|
|
// })
|
|
|
|
// ])
|
|
|
|
// o(showSpy.invocations.length).equals(1)
|
|
|
|
// })
|
2018-10-22 12:02:13 +02:00
|
|
|
|
2020-09-16 14:36:28 +02:00
|
|
|
o("doesn't send notification for another folder", async function () {
|
|
|
|
await model.entityEventsReceived([
|
2018-10-22 12:02:13 +02:00
|
|
|
makeUpdate({
|
|
|
|
instanceListId: anotherFolder.mails,
|
|
|
|
operation: OperationType.CREATE
|
|
|
|
})
|
|
|
|
])
|
|
|
|
o(showSpy.invocations.length).equals(0)
|
|
|
|
})
|
|
|
|
|
2020-09-16 14:36:28 +02:00
|
|
|
o("doesn't send notification for move operation", async function () {
|
|
|
|
await model.entityEventsReceived([
|
2018-10-22 12:02:13 +02:00
|
|
|
makeUpdate({
|
|
|
|
instanceListId: anotherFolder.mails,
|
|
|
|
operation: OperationType.DELETE
|
|
|
|
}),
|
|
|
|
makeUpdate({
|
|
|
|
instanceListId: inboxFolder.mails,
|
|
|
|
operation: OperationType.CREATE
|
|
|
|
})
|
|
|
|
])
|
|
|
|
o(showSpy.invocations.length).equals(0)
|
|
|
|
})
|
|
|
|
|
|
|
|
function makeUpdate(arg: {instanceListId: string, operation: OperationTypeEnum}): EntityUpdateData {
|
|
|
|
return Object.assign({}, {
|
|
|
|
type: MailTypeRef.type,
|
|
|
|
application: MailTypeRef.app,
|
|
|
|
instanceId: "instanceId",
|
|
|
|
}, arg)
|
|
|
|
}
|
2019-03-11 14:40:11 +01:00
|
|
|
})
|