5180 fichiers 38.5 Mo 0 téléchargements 246 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / components / ads / GoogleAdsView.test.tsx
GoogleAdsView.test.tsx 1.3 Ko Télécharger le fichier
import { cleanup, render } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

const settings = vi.hoisted(() => ({ enabled: false }));

vi.mock('../../api', () => ({ GetConfigurationValue: (key: string, fallback: unknown) => (key === 'show.google.ads' ? settings.enabled : fallback) }));
vi.mock('../../common', () => ({ OctaneCardContentView: () => null, OctaneCardHeaderView: () => null, OctaneCardView: () => null }));
vi.mock('../../secure-assets', () => ({ configFileUrl: (name: string) => `/configuration/${name}` }));

const { GoogleAdsView } = await import('./GoogleAdsView');

describe('GoogleAdsView', () => {
    const fetchSpy = vi.fn(() => Promise.resolve({ ok: false, status: 404 } as Response));

    beforeEach(() => {
        fetchSpy.mockClear();
        vi.stubGlobal('fetch', fetchSpy);
    });

    afterEach(() => {
        cleanup();
        vi.unstubAllGlobals();
    });

    it('requests nothing while ads are turned off', () => {
        settings.enabled = false;

        render(<GoogleAdsView />);

        expect(fetchSpy).not.toHaveBeenCalled();
    });

    it('loads ads.txt and the sense config when ads are turned on', () => {
        settings.enabled = true;

        render(<GoogleAdsView />);

        expect(fetchSpy).toHaveBeenCalledTimes(2);
    });
});
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser