2019-09-13 13:49:11 +02:00
|
|
|
import o from "ospec"
|
2022-05-12 16:51:15 +02:00
|
|
|
import {Notifications} from "../../../src/gui/Notifications.js"
|
2021-11-04 14:05:23 +01:00
|
|
|
import type {Spy} from "@tutao/tutanota-test-utils"
|
|
|
|
import {spy} from "@tutao/tutanota-test-utils"
|
2022-05-12 16:51:15 +02:00
|
|
|
import type {MailboxDetail} from "../../../src/mail/model/MailModel.js"
|
|
|
|
import {MailModel} from "../../../src/mail/model/MailModel.js"
|
|
|
|
import {MailFolderType, OperationType} from "../../../src/api/common/TutanotaConstants.js"
|
2022-04-14 17:31:36 +02:00
|
|
|
import {MailTypeRef} from "../../../src/api/entities/tutanota/TypeRefs.js"
|
|
|
|
import {createMailFolder} from "../../../src/api/entities/tutanota/TypeRefs.js"
|
2022-05-12 16:51:15 +02:00
|
|
|
import type {EntityUpdateData} from "../../../src/api/main/EventController.js"
|
|
|
|
import {EntityClient} from "../../../src/api/common/EntityClient.js"
|
|
|
|
import {EntityRestClientMock} from "../api/worker/rest/EntityRestClientMock.js"
|
|
|
|
import nodemocker from "../nodemocker.js"
|
2021-11-04 14:05:23 +01:00
|
|
|
import {downcast} from "@tutao/tutanota-utils"
|
2022-05-12 16:51:15 +02:00
|
|
|
import {WorkerClient} from "../../../src/api/main/WorkerClient.js"
|
|
|
|
import {MailFacade} from "../../../src/api/worker/facades/MailFacade.js"
|
2022-11-08 17:06:42 +01:00
|
|
|
import {LoginController} from "../../../src/api/main/LoginController.js"
|
|
|
|
import {object} from "testdouble"
|
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
|
|
|
{
|
2022-01-07 15:58:30 +01:00
|
|
|
folders: [inboxFolder],
|
|
|
|
},
|
2018-10-22 12:02:13 +02:00
|
|
|
]
|
2022-11-08 17:06:42 +01:00
|
|
|
let logins: LoginController
|
2018-10-22 12:02:13 +02:00
|
|
|
o.beforeEach(function () {
|
|
|
|
notifications = {}
|
|
|
|
showSpy = notifications.showNotification = spy()
|
2021-09-24 13:26:42 +02:00
|
|
|
const restClient = new EntityRestClientMock()
|
2022-01-07 15:58:30 +01:00
|
|
|
const workerClient = nodemocker.mock<WorkerClient>("worker", {}).set()
|
|
|
|
const mailFacade = nodemocker.mock<MailFacade>("mailFacade", {}).set()
|
2022-11-08 17:06:42 +01:00
|
|
|
logins = object()
|
2022-01-07 15:58:30 +01:00
|
|
|
model = new MailModel(
|
|
|
|
downcast(notifications),
|
|
|
|
downcast({}),
|
|
|
|
workerClient,
|
|
|
|
mailFacade,
|
|
|
|
new EntityClient(restClient),
|
2022-11-08 17:06:42 +01:00
|
|
|
logins,
|
2022-01-07 15:58:30 +01:00
|
|
|
)
|
2018-10-22 12:02:13 +02:00
|
|
|
// not pretty, but works
|
2022-01-07 15:58:30 +01:00
|
|
|
model.mailboxDetails(mailboxDetails as MailboxDetail[])
|
2018-10-22 12:02:13 +02:00
|
|
|
})
|
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)
|
|
|
|
// })
|
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,
|
2022-01-07 15:58:30 +01:00
|
|
|
operation: OperationType.CREATE,
|
|
|
|
}),
|
2018-10-22 12:02:13 +02:00
|
|
|
])
|
|
|
|
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,
|
2022-01-07 15:58:30 +01:00
|
|
|
operation: OperationType.DELETE,
|
2018-10-22 12:02:13 +02:00
|
|
|
}),
|
|
|
|
makeUpdate({
|
|
|
|
instanceListId: inboxFolder.mails,
|
2022-01-07 15:58:30 +01:00
|
|
|
operation: OperationType.CREATE,
|
|
|
|
}),
|
2018-10-22 12:02:13 +02:00
|
|
|
])
|
|
|
|
o(showSpy.invocations.length).equals(0)
|
|
|
|
})
|
|
|
|
|
2022-01-07 15:58:30 +01:00
|
|
|
function makeUpdate(arg: { instanceListId: string; operation: OperationType }): EntityUpdateData {
|
|
|
|
return Object.assign(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
type: MailTypeRef.type,
|
|
|
|
application: MailTypeRef.app,
|
|
|
|
instanceId: "instanceId",
|
|
|
|
},
|
|
|
|
arg,
|
|
|
|
)
|
2018-10-22 12:02:13 +02:00
|
|
|
}
|
2022-01-07 15:58:30 +01:00
|
|
|
})
|