1 import type { Message } from '@proton/shared/lib/interfaces/mail/Message';
2 import { MESSAGE_FLAGS } from '@proton/shared/lib/mail/constants';
3 import { clearFlag, hasFlag, setFlag, toggleFlag } from '@proton/shared/lib/mail/messages';
5 describe('hasFlag', () => {
6 it('should detect correctly that the message has a flag', () => {
8 Flags: MESSAGE_FLAGS.FLAG_SENT,
11 expect(hasFlag(MESSAGE_FLAGS.FLAG_SENT)(message)).toBeTrue();
14 it('should detect correctly that the message has not a flag', () => {
16 Flags: MESSAGE_FLAGS.FLAG_RECEIVED,
17 } as Partial<Message>;
19 expect(hasFlag(MESSAGE_FLAGS.FLAG_SENT)(message)).toBeFalsy();
23 describe('setFlag', () => {
24 it('should set the message Flag', () => {
26 Flags: MESSAGE_FLAGS.FLAG_SENT,
27 } as Partial<Message>;
29 const newFlags = setFlag(MESSAGE_FLAGS.FLAG_RECEIPT_SENT)(message);
30 expect(newFlags).toEqual(MESSAGE_FLAGS.FLAG_SENT + MESSAGE_FLAGS.FLAG_RECEIPT_SENT);
34 describe('clearFlag', () => {
35 it('should clear the message flag', () => {
37 Flags: MESSAGE_FLAGS.FLAG_SENT + MESSAGE_FLAGS.FLAG_RECEIPT_SENT,
38 } as Partial<Message>;
40 const newFlags = clearFlag(MESSAGE_FLAGS.FLAG_RECEIPT_SENT)(message);
41 expect(newFlags).toEqual(MESSAGE_FLAGS.FLAG_SENT);
45 describe('toggleFlag', () => {
46 it('should clear the message flag', () => {
48 Flags: MESSAGE_FLAGS.FLAG_SENT + MESSAGE_FLAGS.FLAG_RECEIPT_SENT,
49 } as Partial<Message>;
51 const newFlags = toggleFlag(MESSAGE_FLAGS.FLAG_RECEIPT_SENT)(message);
52 expect(newFlags).toEqual(MESSAGE_FLAGS.FLAG_SENT);