Skip to content

Commit

Permalink
Fix a bug on monthly report feature
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Jan 4, 2024
1 parent 1919140 commit d75ca36
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
8 changes: 4 additions & 4 deletions functions/internals/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ interface reportStartBlocksArgs {
blocks: AnyModalBlock[];
isLifelogEnabled: boolean;
}
function reportStartBlocks(
export function reportStartBlocks(
{ language, offset, blocks, isLifelogEnabled }: reportStartBlocksArgs,
) {
const yyyymmdd = todayYYYYMMDD(offset);
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
},
},
});
Expand Down
26 changes: 26 additions & 0 deletions functions/internals/views_test.ts
Original file line number Diff line number Diff line change
@@ -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,
);
});

0 comments on commit d75ca36

Please sign in to comment.