File size: 2,405 Bytes
8a37e0a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import { getViewModeChunks } from 'features/stylePresets/util/getViewModeChunks';
import { describe, expect, it } from 'vitest';
describe('getViewModeChunks', () => {
it('should return empty strings when presetPrompt is not provided', () => {
const currentPrompt = 'current prompt';
const presetPrompt = undefined;
const result = getViewModeChunks(currentPrompt, presetPrompt);
expect(result).toEqual(['', currentPrompt, '']);
});
it('should return empty strings when presetPrompt is empty', () => {
const currentPrompt = 'current prompt';
const presetPrompt = '';
const result = getViewModeChunks(currentPrompt, presetPrompt);
expect(result).toEqual(['', currentPrompt, '']);
});
it('should append presetPrompt to currentPrompt when presetPrompt does not contain PRESET_PLACEHOLDER', () => {
const currentPrompt = 'current prompt';
const presetPrompt = 'preset prompt';
const result = getViewModeChunks(currentPrompt, presetPrompt);
expect(result).toEqual(['', `${currentPrompt} `, presetPrompt]);
});
it('should split presetPrompt into 3 parts when presetPrompt contains PRESET_PLACEHOLDER', () => {
const currentPrompt = 'current prompt';
const presetPrompt = 'before {prompt} after';
const result = getViewModeChunks(currentPrompt, presetPrompt);
expect(result).toEqual(['before ', currentPrompt, ' after']);
});
it('should split presetPrompt into 3 parts when presetPrompt contains multiple PRESET_PLACEHOLDER', () => {
const currentPrompt = 'current prompt';
const presetPrompt = 'before {prompt} middle {prompt} after';
const result = getViewModeChunks(currentPrompt, presetPrompt);
expect(result).toEqual(['before ', currentPrompt, ' middle {prompt} after']);
});
it('should handle the PRESET_PLACEHOLDER being at the start of the presetPrompt', () => {
const currentPrompt = 'current prompt';
const presetPrompt = '{prompt} after';
const result = getViewModeChunks(currentPrompt, presetPrompt);
expect(result).toEqual(['', currentPrompt, ' after']);
});
it('should handle the PRESET_PLACEHOLDER being at the end of the presetPrompt', () => {
const currentPrompt = 'current prompt';
const presetPrompt = 'before {prompt}';
const result = getViewModeChunks(currentPrompt, presetPrompt);
expect(result).toEqual(['before ', currentPrompt, '']);
});
});
|