fix(fortune): scope s5s fortune markup (#1150)

* fix(markdown): scope fortune markup to fortune boards

* fix(fortune): store fortune output as bbcode

* fix(fortune): keep legacy fortune rendering

* fix(tests): resolve catalog button mock merge

* fix(fortune): validate hidden fortune length
This commit is contained in:
Tommaso Casaburi
2026-06-03 13:49:35 +07:00
committed by GitHub
parent 84f357cba1
commit d09d2d05d1
16 changed files with 439 additions and 93 deletions
@@ -1,10 +1,13 @@
import { describe, expect, it } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import {
getContentWithPostOptionState,
getNonokoPendingAccountCommentIndex,
getNonokoPendingRouteState,
getPostOptionsPublishContentLength,
getPostOptionsValidationError,
getUnsupportedPostOptionsMessage,
hasNonokoOption,
stripGeneratedFortuneMarkup,
} from '../post-options-utils';
describe('post-options-utils', () => {
@@ -42,4 +45,48 @@ describe('post-options-utils', () => {
expect(getNonokoPendingAccountCommentIndex({ nonokoPendingAccountCommentIndex: -1 })).toBeUndefined();
expect(getNonokoPendingAccountCommentIndex({ nonokoPendingAccountCommentIndex: '7' })).toBeUndefined();
});
it('strips generated fortune markers before appending a new fortune on fortune boards', () => {
const randomSpy = vi.spyOn(Math, 'random').mockReturnValue(0.25);
const fortuneEntryRef = { current: null };
const diceRollRef = { current: null };
expect(
getContentWithPostOptionState(
'body[fortune color=#6023f8]Outlook good[/fortune]<span class="fortune" style="color:#7fec11"><br><br><b>Your fortune: Bad Luck</b></span>',
'fortune',
fortuneEntryRef,
diceRollRef,
's5s',
),
).toBe('body[fortune color=#fd4d32]Excellent Luck[/fortune]');
randomSpy.mockRestore();
});
it('strips user-entered generated fortune markers even when fortune is not selected on fortune boards', () => {
const fortuneEntryRef = { current: null };
const diceRollRef = { current: null };
expect(getContentWithPostOptionState('body[fortune color=#6023f8]Outlook good[/fortune]', '', fortuneEntryRef, diceRollRef, 's5s')).toBe('body');
});
it('keeps invalid or non-fortune-board fortune-looking text', () => {
const fortuneEntryRef = { current: null };
const diceRollRef = { current: null };
const userText = '[fortune color=#000000]Excellent Luck[/fortune]';
expect(stripGeneratedFortuneMarkup(userText)).toBe(userText);
expect(getContentWithPostOptionState('body[fortune color=#6023f8]Outlook good[/fortune]', '', fortuneEntryRef, diceRollRef, 'mu')).toBe(
'body[fortune color=#6023f8]Outlook good[/fortune]',
);
});
it('counts hidden fortune output against publish length without rolling a fortune', () => {
const longestFortune = '[fortune color=#0893e1]You will meet a dark handsome stranger[/fortune]';
expect(getPostOptionsPublishContentLength('body', 'fortune', 's5s')).toBe('body'.length + longestFortune.length);
expect(getPostOptionsPublishContentLength('body ', 'fortune', 's5s')).toBe('body '.length + longestFortune.length);
expect(getPostOptionsPublishContentLength('body ', 'fortune', 'mu')).toBe('body'.length);
});
});