5180 fichiers 38.5 Mo 0 téléchargements 252 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / common / layout / LayoutBadgeImageView.tooltip.test.tsx
LayoutBadgeImageView.tooltip.test.tsx 2.3 Ko Télécharger le fichier
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { LayoutBadgeImageView } from './LayoutBadgeImageView';

vi.mock('@octane/renderer', () => ({
    BadgeImageReadyEvent: class {
        public static IMAGE_READY = 'badge_image_ready';
    },
    GetEventDispatcher: () => ({ addEventListener: vi.fn(), removeEventListener: vi.fn() }),
    GetSessionDataManager: () => ({
        getBadgeImage: () => null,
        getGroupBadgeImage: () => null
    }),
    OctaneSprite: class {},
    TextureUtils: { generateImage: vi.fn() }
}));

vi.mock('../../api', () => ({
    ensureBadgeLeaderboardLoaded: vi.fn(() => Promise.resolve()),
    GetConfigurationValue: vi.fn((key: string) => (key === 'badge.asset.url' ? 'https://example.com/%badgename%.gif' : true)),
    getCachedBadgeRarityStat: vi.fn(() => null),
    LocalizeBadgeDescription: (code: string) => `Description of ${code}`,
    LocalizeBadgeName: (code: string) => `Name of ${code}`,
    LocalizeText: (key: string) => key
}));

describe('badge tooltip', () => {
    beforeEach(() => vi.useFakeTimers());

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

    it('shows the badge name and description in the skinned bubble on hover', () => {
        const { container } = render(<LayoutBadgeImageView badgeCode="ACH_BasicClub1" showInfo />);

        fireEvent.mouseEnter(container.firstElementChild as HTMLElement);

        act(() => {
            vi.advanceTimersByTime(250);
        });

        const bubble = screen.getByRole('tooltip');
        expect(bubble.classList.contains('octane-badge-details')).toBe(true);
        expect(bubble).toHaveTextContent('Name of ACH_BasicClub1');
        expect(bubble).toHaveTextContent('Description of ACH_BasicClub1');

        fireEvent.mouseLeave(container.firstElementChild as HTMLElement);
        expect(screen.queryByRole('tooltip')).toBeNull();
    });

    it('stays silent without showInfo', () => {
        const { container } = render(<LayoutBadgeImageView badgeCode="ACH_BasicClub1" />);

        fireEvent.mouseEnter(container.firstElementChild as HTMLElement);

        act(() => {
            vi.advanceTimersByTime(250);
        });

        expect(screen.queryByRole('tooltip')).toBeNull();
    });
});
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