5180 fichiers 38.5 Mo 0 téléchargements 195 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / api / octane / GetConfigurationRecord.test.ts
GetConfigurationRecord.test.ts 1.9 Ko Télécharger le fichier
import { readFileSync } from 'node:fs';
import { GetConfiguration } from '@octane/renderer';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { GetConfigurationRecord } from './GetConfigurationValue';

const config: Record<string, unknown> = {};

describe('GetConfigurationRecord', () => {
    beforeEach(() => {
        for (const key of Object.keys(config)) delete config[key];
        vi.mocked(GetConfiguration).mockReturnValue({
            getValue: (key: string, fallback: unknown) => (key in config ? config[key] : fallback)
        } as never);
    });

    it('reads a field of a settings object', () => {
        config['hc.center'] = { 'payday.info': true };

        expect(GetConfigurationRecord('hc.center')['payday.info']).toBe(true);
    });

    it('answers an empty object for a missing key, a null or something that is not an object', () => {
        config['catalog.links'] = null;
        config['respect.options'] = 'yes';
        config.hotelview = [1, 2];

        expect(GetConfigurationRecord('hc.center')['payday.info']).toBeUndefined();
        expect(GetConfigurationRecord('catalog.links')['pets.buy_food']).toBeUndefined();
        expect(GetConfigurationRecord('respect.options').enabled).toBeUndefined();
        expect(GetConfigurationRecord('hotelview')['room.pool']).toBeUndefined();
    });

    it('is what the views read settings objects through', () => {
        const files = [
            'src/components/hc-center/HcCenterView.tsx',
            'src/components/hotel-view/RoomWidgetView.tsx',
            'src/hooks/rooms/widgets/useChatWidget.ts',
            'src/components/room/widgets/avatar-info/infostand/InfoStandWidgetPetView.tsx',
            'src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetOwnPetView.tsx'
        ];

        for (const file of files) expect(readFileSync(file, 'utf8'), file).not.toMatch(/GetConfigurationValue(<[^>]*>)?\('[^']+'\)\[/);
    });
});
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