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, + ); +});