From 6beab79eb4fe852080122f6018c85a9cd8078c56 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Fri, 1 Mar 2024 11:39:31 +0100 Subject: [PATCH] add tests for falsy formatting attributes - #619 --- tests/y-text.tests.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/y-text.tests.js b/tests/y-text.tests.js index 87ac21a4..34ae7e9e 100644 --- a/tests/y-text.tests.js +++ b/tests/y-text.tests.js @@ -1746,6 +1746,27 @@ export const testBasicFormat = tc => { compare(users) } +/** + * @param {t.TestCase} tc + */ +export const testFalsyFormats = tc => { + const { users, text0 } = init(tc, { users: 2 }) + let delta + text0.observe(event => { + delta = event.delta + }) + text0.insert(0, 'abcde', { falsy: false }) + t.compare(text0.toDelta(), [{ insert: 'abcde', attributes: { falsy: false } }]) + t.compare(delta, [{ insert: 'abcde', attributes: { falsy: false } }]) + text0.format(1, 3, { falsy: true }) + t.compare(text0.toDelta(), [{ insert: 'a', attributes: { falsy: false } }, { insert: 'bcd', attributes: { falsy: true } }, { insert: 'e', attributes: { falsy: false } }]) + t.compare(delta, [{ retain: 1 }, { retain: 3, attributes: { falsy: true } }]) + text0.format(2, 1, { falsy: false }) + t.compare(text0.toDelta(), [{ insert: 'a', attributes: { falsy: false } }, { insert: 'b', attributes: { falsy: true } }, { insert: 'c', attributes: { falsy: false } }, { insert: 'd', attributes: { falsy: true } }, { insert: 'e', attributes: { falsy: false } }]) + t.compare(delta, [{ retain: 2 }, { retain: 1, attributes: { falsy: false } }]) + compare(users) +} + /** * @param {t.TestCase} _tc */