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

const config = vi.hoisted(() => ({ values: {} as Record<string, string> }));

vi.mock('@octane/renderer', async (importOriginal) => ({
    ...(await importOriginal<typeof import('@octane/renderer')>()),
    GetConfiguration: () => ({
        definitions: { has: (key: string) => key in config.values },
        getValue: (key: string) => config.values[key],
        interpolate: (value: string) => value
    })
}));

import { LoadingView } from './LoadingView';

describe('LoadingView (AIR HabboLoadingScreen)', () => {
    afterEach(() => {
        cleanup();
        config.values = {};
        vi.useRealTimers();
    });

    it('shows the logo, the photo splash, a revolving message, the bar and the percentage', () => {
        config.values['client.starting.revolving'] = 'One/Two';
        const { container } = render(<LoadingView progress={45} currentTask="Loading rooms..." />);

        expect(screen.getByAltText('Octane')).toHaveClass('octane-loading__logo');
        expect(container.querySelectorAll('.octane-loading__splash img')).toHaveLength(3);
        expect(['One', 'Two']).toContain(screen.getByRole('status').textContent);
        expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '45');
        expect(screen.getByText('45%')).toBeInTheDocument();
        expect(screen.getByText('Loading rooms...')).toBeInTheDocument();
    });

    it('turns to the next message while loading', () => {
        vi.useFakeTimers();
        config.values['client.starting.revolving'] = 'One/Two';
        render(<LoadingView progress={10} />);

        const first = screen.getByRole('status').textContent;

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

        expect(screen.getByRole('status').textContent).not.toBe(first);
    });

    it('says the load failed, with the error and the way home', () => {
        render(<LoadingView isError message="The server is offline." homeUrl="/home" />);

        expect(screen.getByRole('status')).toHaveTextContent('Loading failed');
        expect(screen.getByText('The server is offline.')).toBeInTheDocument();
        expect(screen.getByRole('link', { name: 'Back to Hotel' })).toHaveAttribute('href', '/home');
        expect(screen.queryByRole('progressbar')).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