5180 fichiers 38.5 Mo 0 téléchargements 348 vues mis à jour il y a 7 heures ui
nitro-v36-with-renderer-v36 / src / components / wired / views / extras / WiredExtraTextOutputUsernameView.test.tsx
WiredExtraTextOutputUsernameView.test.tsx 3.4 Ko Télécharger le fichier
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import { PropsWithChildren } from 'react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

const setIntParams = vi.fn();
const setStringParam = vi.fn();
const setSourceTypes = vi.fn();
let trigger: { stringData: string; intData: number[]; userSourceTypes?: number[]; furniSourceTypes?: number[] } | null = null;
let save: (() => void) | null = null;

vi.mock('../../../../api', () => ({
    LocalizeText: (key: string) => key,
    localizeWithFallback: (key: string) => key,
    WiredFurniType: { STUFF_SELECTION_OPTION_NONE: 0, STUFF_SELECTION_OPTION_BY_ID_BY_TYPE_OR_FROM_CONTEXT: 3 }
}));
vi.mock('../../../../common', () => ({
    Text: ({ children }: PropsWithChildren) => <span>{children}</span>
}));
vi.mock('../../../../common/Radio', () => ({
    Radio: (props: { checked: boolean; onCheckedChange: () => void }) => (
        <input type="radio" aria-checked={props.checked} checked={props.checked} onChange={() => props.onCheckedChange()} />
    )
}));
vi.mock('../../../../layout', () => ({
    OctaneInput: (props: Record<string, unknown>) => <input {...props} />
}));
vi.mock('../../../../hooks', () => ({
    useWired: () => ({ trigger, setIntParams, setStringParam, setSourceTypes })
}));
vi.mock('../WiredSourcesSelector', () => ({
    CLICKED_USER_SOURCE_VALUE: 202,
    REACHED_USER_SOURCE_VALUE: 203,
    WiredSourcesSelector: () => null
}));
vi.mock('./WiredPlaceholderPreview', () => ({ WiredPlaceholderPreview: () => null }));
vi.mock('./WiredExtraBaseView', () => ({
    WiredExtraBaseView: (props: PropsWithChildren<{ save: () => void }>) => {
        save = props.save;
        return <div>{props.children}</div>;
    }
}));

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

const views = [
    ['username', WiredExtraTextOutputUsernameView],
    ['furni name', WiredExtraTextOutputFurniNameView]
] as const;

describe.each(views)('the %s placeholder delimiter (AIR)', (_name, View) => {
    afterEach(cleanup);

    beforeEach(() => {
        setStringParam.mockClear();
        setIntParams.mockClear();
    });

    it('starts empty, takes at most 5 characters and is saved with the name', () => {
        trigger = { stringData: 'all', intData: [0] };
        render(<View />);

        fireEvent.click(screen.getAllByRole('radio')[1]);
        const delimiter = screen.getAllByRole('textbox')[1];
        expect(delimiter).toHaveValue('');
        expect(delimiter).toHaveAttribute('maxLength', '5');

        fireEvent.change(delimiter, { target: { value: ' / and more' } });
        save?.();
        expect(setIntParams).toHaveBeenCalledWith([1]);
        expect(setStringParam).toHaveBeenCalledWith('all\t / an');
    });

    it('saves the name alone for one name', () => {
        trigger = { stringData: 'who\t, ', intData: [0] };
        render(<View />);

        save?.();
        expect(setIntParams).toHaveBeenCalledWith([0]);
        expect(setStringParam).toHaveBeenCalledWith('who');
    });

    it('cuts the long delimiter of an old box when it is saved again', () => {
        trigger = { stringData: 'all\t and also ', intData: [1] };
        render(<View />);

        save?.();
        expect(setStringParam).toHaveBeenCalledWith('all\t and ');
    });
});
15Sujets
1Dépôts
20Membres
3En 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