<commit_before>import { SHOW_IMAGES } from '@proton/shared/lib/constants';
import { MailSettings } from '@proton/shared/lib/interfaces';
import { Message } from '@proton/shared/lib/interfaces/mail/Message';
import { MessageExtended } from '../../../models/message';
import { messageCache } from '../../test/cache';
import { api } from '../../test/api';
import { transformRemote } from '../transformRemote';
import { createDocument } from '../../test/message';

const mailSettings = {
    ShowImages: SHOW_IMAGES.REMOTE,
    // ImageProxy: IMAGE_PROXY_FLAGS.PROXY
} as MailSettings;

describe('transformEmbedded', () => {
    const setup = (message: MessageExtended) => {
        return transformRemote(message, mailSettings, api, messageCache);
    };

    it('should detect remote images', async () => {
        const imageURL = 'imageURL';
        const content = `<div>
                            <img proton-src='${imageURL}'/>
                        </div>`;

        const message: MessageExtended = {
            localID: 'messageWithEmbedded',
            data: {
                ID: 'messageID',
            } as Message,
            document: createDocument(content),
        };

        const { showRemoteImages, remoteImages, hasRemoteImages } = await setup(message);

        expect(showRemoteImages).toBeTruthy();
        expect(hasRemoteImages).toBeTruthy();
        expect(remoteImages[0].type).toEqual('remote');
        expect(remoteImages[0].url).toEqual(imageURL);
    });
});<commit_msg>Added loading remote images through proxy test<commit_after>import { IMAGE_PROXY_FLAGS, SHOW_IMAGES } from '@proton/shared/lib/constants';
import { MailSettings } from '@proton/shared/lib/interfaces';
import { Message } from '@proton/shared/lib/interfaces/mail/Message';
import { wait } from '@proton/shared/lib/helpers/promise';
import { MessageExtended } from '../../../models/message';
import { messageCache } from '../../test/cache';
import { addApiMock, api } from '../../test/api';
import { transformRemote } from '../transformRemote';
import { createDocument } from '../../test/message';

describe('transformEmbedded', () => {
    const setup = (message: MessageExtended, mailSettings: MailSettings) => {
        return transformRemote(message, mailSettings, api, messageCache);
    };

    it('should detect remote images', async () => {
        const imageURL = 'imageURL';
        const content = `<div>
                            <img proton-src='${imageURL}'/>
                        </div>`;

        const message: MessageExtended = {
            localID: 'messageWithEmbedded',
            data: {
                ID: 'messageID',
            } as Message,
            document: createDocument(content),
        };

        const mailSettings = {
            ShowImages: SHOW_IMAGES.REMOTE,
        } as MailSettings;

        const { showRemoteImages, remoteImages, hasRemoteImages } = await setup(message, mailSettings);

        expect(showRemoteImages).toBeTruthy();
        expect(hasRemoteImages).toBeTruthy();
        expect(remoteImages[0].type).toEqual('remote');
        expect(remoteImages[0].url).toEqual(imageURL);
    });

    it('should load remote images through proxy', async () => {
        const proxyCall = jest.fn();

        addApiMock('images', proxyCall, 'get');

        const imageURL = 'imageURL';
        const content = `<div>
                            <img proton-src='${imageURL}'/>
                        </div>`;

        const message: MessageExtended = {
            localID: 'messageWithEmbedded',
            data: {
                ID: 'messageID',
            } as Message,
            document: createDocument(content),
        };

        const mailSettings = {
            ShowImages: SHOW_IMAGES.REMOTE,
            ImageProxy: IMAGE_PROXY_FLAGS.PROXY,
        } as MailSettings;

        const { showRemoteImages, remoteImages, hasRemoteImages } = await setup(message, mailSettings);

        await wait(2000);

        expect(showRemoteImages).toBeTruthy();
        expect(hasRemoteImages).toBeTruthy();
        expect(remoteImages[0].type).toEqual('remote');
        expect(remoteImages[0].url).toEqual(imageURL);
        expect(proxyCall).toHaveBeenCalled();
    });
});
{'fraction_non_alphanumeric': 0.13915705203673182, 'fraction_numerical': 0.0023546032493524842, 'mean_word_length': 2.479115479115479, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7152687', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1125, 'n_words': 241}