microsoft / microsoft/BotFramework-WebChat

Add test for `useLocalizeDate`

Open
#2,588 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog feature-request technical-debt
Dominant language
HTML
Stars
1.8k
Forks
1.6k
Avg merge
22h 58m
Merged PRs (30d)
2

Description

Feature Request

Description

While we are adding the useLocalizeDate hook, we found out we didn't test getLocaleString function at all.

But when we try to add the test, we are hitting timezone problem. Timezone of the CI box and local box could be different.

To mitigate the problem, we need to add some code in production codebase to allow the user to select timezone. For example, the options passed to Intl.DateTimeFormat should have { timeZone: 'utc' }.

Instead of doing it in the PR, we are adding a new issue and address it later.

Actual code
import { timeouts } from '../constants.json';

// selenium-webdriver API doc:
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html

jest.setTimeout(timeouts.test);

test('calling localizeDate should return a localized date time string', async () => {
  const { pageObjects } = await setupWebDriver();

  await expect(
    pageObjects.runHook('useLocalizeDate', [new Date(2000, 0, 2, 12, 34, 56)])
  ).resolves.toMatchInlineSnapshot(`"January 02, 20:34"`);
});

[Enhancement]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the useLocalizeDate hook and its getLocaleString function, then inspect the Jest test using setupWebDriver and the inline snapshot. Make the date formatting and test independent of the machine timezone while allowing the intended timezone option, and verify the localized output with the test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.