1 import { useMailSettings } from '@proton/mail/mailSettings/hooks';
2 import type { Folder } from '@proton/shared/lib/interfaces/Folder';
3 import { FOLDER_COLOR, INHERIT_PARENT_FOLDER_COLOR } from '@proton/shared/lib/mail/mailSettings';
5 import useFolderColor from './useFolderColor';
7 const mockFolderSetting = FOLDER_COLOR.ENABLED;
8 const mockinheritSetting = INHERIT_PARENT_FOLDER_COLOR.ENABLED;
9 jest.mock('@proton/mail/mailSettings/hooks', () => ({
10 useMailSettings: jest.fn(() => [
11 { EnableFolderColor: mockFolderSetting, InheritParentFolderColor: mockinheritSetting },
16 jest.mock('@proton/mail/labels/hooks', () => ({
19 { ID: 'A', Color: 'red' },
20 { ID: 'B', Color: 'blue', ParentID: 'A' },
21 { ID: 'C', Color: 'green', ParentID: 'B' },
27 describe('useFolderColor hook', () => {
28 it('should not return color if EnableFolderColor is disabled', () => {
29 (useMailSettings as jest.Mock).mockReturnValueOnce([
30 { EnableFolderColor: FOLDER_COLOR.DISABLED, InheritParentFolderColor: INHERIT_PARENT_FOLDER_COLOR.ENABLED },
33 const folder = { ID: 'C', Color: 'green' } as Folder;
34 const color = useFolderColor(folder);
35 expect(color).toBe(undefined);
38 it('should return current color if InheritParentFolderColor is disabled', () => {
39 (useMailSettings as jest.Mock).mockReturnValueOnce([
40 { EnableFolderColor: FOLDER_COLOR.ENABLED, InheritParentFolderColor: INHERIT_PARENT_FOLDER_COLOR.DISABLED },
43 const folder = { ID: 'C', Color: 'green', ParentID: 'B' } as Folder;
44 const color = useFolderColor(folder);
45 expect(color).toBe('green');
48 it('should return current folder color since it is a root', () => {
49 const folder = { ID: 'C', Color: 'green' } as Folder;
50 const color = useFolderColor(folder);
51 expect(color).toBe('green');
54 it('should search for root folder color', () => {
55 const folder = { ID: 'C', Color: 'green', ParentID: 'B' } as Folder;
56 const color = useFolderColor(folder);
57 expect(color).toBe('red');