Files
ComfyUI-Lora-Manager/tests/frontend/state/index.test.js
Will Miao ceeab0c998 feat: add configurable mature blur threshold setting
Add new setting 'mature_blur_level' with options PG13/R/X/XXX to control
which NSFW rating level triggers blur filtering when NSFW blur is enabled.

- Backend: update preview selection logic to respect threshold
- Frontend: update UI components to use configurable threshold
- Settings: add validation and normalization for mature_blur_level
- Tests: add coverage for new threshold behavior
- Translations: add keys for all supported languages

Fixes #867
2026-03-26 18:24:47 +08:00

55 lines
2.0 KiB
JavaScript

import { describe, it, expect, beforeEach } from 'vitest';
import { createDefaultSettings, getCurrentPageState, initPageState, setCurrentPageType, state } from '../../../static/js/state/index.js';
import { MODEL_TYPES } from '../../../static/js/api/apiConfig.js';
import { DEFAULT_PATH_TEMPLATES } from '../../../static/js/utils/constants.js';
describe('state module', () => {
beforeEach(() => {
// Reset to default page before each assertion
state.currentPageType = MODEL_TYPES.LORA;
});
it('creates default settings with immutable template copies', () => {
const defaultSettings = createDefaultSettings();
expect(defaultSettings).toMatchObject({
civitai_api_key: '',
language: 'en',
blur_mature_content: true,
mature_blur_level: 'R'
});
expect(defaultSettings.download_path_templates).toEqual(DEFAULT_PATH_TEMPLATES);
// ensure nested objects are new references so tests can safely mutate
expect(defaultSettings.download_path_templates).not.toBe(DEFAULT_PATH_TEMPLATES);
expect(defaultSettings.base_model_path_mappings).toEqual({});
expect(Object.isFrozen(defaultSettings)).toBe(false);
});
it('switches current page type when valid', () => {
const didSwitch = setCurrentPageType(MODEL_TYPES.CHECKPOINT);
expect(didSwitch).toBe(true);
expect(state.currentPageType).toBe(MODEL_TYPES.CHECKPOINT);
expect(getCurrentPageState()).toBe(state.pages[MODEL_TYPES.CHECKPOINT]);
});
it('rejects switching to an unknown page type', () => {
state.currentPageType = MODEL_TYPES.LORA;
const didSwitch = setCurrentPageType('invalid-page');
expect(didSwitch).toBe(false);
expect(state.currentPageType).toBe(MODEL_TYPES.LORA);
});
it('initializes and returns state for a known page', () => {
const pageState = initPageState(MODEL_TYPES.EMBEDDING);
expect(pageState).toBeDefined();
expect(pageState).toBe(state.pages[MODEL_TYPES.EMBEDDING]);
expect(state.currentPageType).toBe(MODEL_TYPES.EMBEDDING);
});
});