From bd0d5b3a508ea21ce1153830e0ee41fcd18bfa17 Mon Sep 17 00:00:00 2001 From: 4eb0da <4eb0da@yandex-team.com> Date: Mon, 19 Sep 2022 12:58:02 +0300 Subject: [PATCH] BooleanInt props now accepts bools too --- client/web/divkit/src/dev.ts | 22 +++++++++---------- .../web/divkit/src/utils/correctBooleanInt.ts | 4 ++-- .../tests/utils/correctBooleanInt.test.ts | 4 ++++ client/web/divkit/typings/common.d.ts | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/client/web/divkit/src/dev.ts b/client/web/divkit/src/dev.ts index 847127025..612234bc9 100644 --- a/client/web/divkit/src/dev.ts +++ b/client/web/divkit/src/dev.ts @@ -3,18 +3,18 @@ import Root from './components/Root.svelte'; const json = { "templates": {}, "card": { - "type": "div2", - "log_id": "snapshot_test_card", - "states": [ - { - "state_id": 0, - "div": { - "type": "text", - "text": "Hello world" - } + "type": "div2", + "log_id": "snapshot_test_card", + "states": [ + { + "state_id": 0, + "div": { + "type": "text", + "text": "Hello world" } - ] - } + } + ] + } }; window.root = new Root({ diff --git a/client/web/divkit/src/utils/correctBooleanInt.ts b/client/web/divkit/src/utils/correctBooleanInt.ts index 612a633bb..228e7257a 100644 --- a/client/web/divkit/src/utils/correctBooleanInt.ts +++ b/client/web/divkit/src/utils/correctBooleanInt.ts @@ -1,5 +1,5 @@ -export function correctBooleanInt(val: number | undefined, defaultVal: boolean): boolean { - if (val === 1 || val === 0) { +export function correctBooleanInt(val: number | boolean | undefined, defaultVal: boolean): boolean { + if (val === 1 || val === 0 || val === false || val === true) { return Boolean(val); } return defaultVal; diff --git a/client/web/divkit/tests/utils/correctBooleanInt.test.ts b/client/web/divkit/tests/utils/correctBooleanInt.test.ts index b83adc7d6..2b2553c8c 100644 --- a/client/web/divkit/tests/utils/correctBooleanInt.test.ts +++ b/client/web/divkit/tests/utils/correctBooleanInt.test.ts @@ -8,6 +8,10 @@ describe('correctBooleanInt', () => { expect(correctBooleanInt(1, true)).toBe(true); expect(correctBooleanInt(0, false)).toBe(false); expect(correctBooleanInt(0, true)).toBe(false); + expect(correctBooleanInt(true, false)).toBe(true); + expect(correctBooleanInt(true, true)).toBe(true); + expect(correctBooleanInt(false, false)).toBe(false); + expect(correctBooleanInt(false, true)).toBe(false); expect(correctBooleanInt(undefined, false)).toBe(false); expect(correctBooleanInt(undefined, true)).toBe(true); }); diff --git a/client/web/divkit/typings/common.d.ts b/client/web/divkit/typings/common.d.ts index 502d5bed8..c33f7d27b 100644 --- a/client/web/divkit/typings/common.d.ts +++ b/client/web/divkit/typings/common.d.ts @@ -1,4 +1,4 @@ -export type BooleanInt = 0 | 1; +export type BooleanInt = 0 | 1 | false | true; export type TemplateContext = Record;