From d75ca368fd505ac27c2a69b7be138afce97f43b8 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Thu, 4 Jan 2024 16:54:06 +0900 Subject: [PATCH] Fix a bug on monthly report feature --- functions/internals/views.ts | 8 ++++---- functions/internals/views_test.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 functions/internals/views_test.ts diff --git a/functions/internals/views.ts b/functions/internals/views.ts index 2f9b670..e5e4cca 100644 --- a/functions/internals/views.ts +++ b/functions/internals/views.ts @@ -997,7 +997,7 @@ interface reportStartBlocksArgs { blocks: AnyModalBlock[]; isLifelogEnabled: boolean; } -function reportStartBlocks( +export function reportStartBlocks( { language, offset, blocks, isLifelogEnabled }: reportStartBlocksArgs, ) { const yyyymmdd = todayYYYYMMDD(offset); @@ -1032,7 +1032,7 @@ function reportStartBlocks( value: i.toString(), }); } - const month = yyyymmdd.substring(4, 6); + const month = Number.parseInt(yyyymmdd.substring(4, 6)); blocks.push({ "type": "input", "block_id": BlockId.Month, @@ -1042,8 +1042,8 @@ function reportStartBlocks( "action_id": ActionId.Input, "options": months, "initial_option": { - text: { type: "plain_text", text: month }, - value: month, + text: { type: "plain_text", text: month.toString() }, + value: month.toString(), }, }, }); diff --git a/functions/internals/views_test.ts b/functions/internals/views_test.ts new file mode 100644 index 0000000..4f49c46 --- /dev/null +++ b/functions/internals/views_test.ts @@ -0,0 +1,26 @@ +import { assertEquals } from "std/assert/assert_equals.ts"; +import { reportStartBlocks } from "./views.ts"; +import { LanguageCode } from "./constants.ts"; +import { AnyModalBlock } from "slack-web-api-client/index.ts"; +import { StaticSelect, ViewInputBlock } from "slack-web-api-client/mod.ts"; + +Deno.test("reportStartBlocks", () => { + const blocks: AnyModalBlock[] = []; + reportStartBlocks({ + language: LanguageCode.English, + offset: 0, + blocks, + isLifelogEnabled: true, + }); + assertEquals(blocks.length, 3); + const year = (blocks[0] as ViewInputBlock).element as StaticSelect; + assertEquals( + year.options?.map((o) => o.value).includes(year.initial_option?.value), + true, + ); + const month = (blocks[1] as ViewInputBlock).element as StaticSelect; + assertEquals( + month.options?.map((o) => o.value).includes(month.initial_option?.value), + true, + ); +});