Skip to content

Commit

Permalink
Language of timestamp should update on-the-fly (#2414)
Browse files Browse the repository at this point in the history
* Fix timestamp not updating on language

* Add tests

* Update PR number

* Remove console log
  • Loading branch information
compulim authored Sep 25, 2019
1 parent 850890f commit 7de0a84
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fix [Emulator:#1823](https://github.com/microsoft/BotFramework-Emulator/issues/1823). Fix Sendbox "Type your message" being read twice by AT, by [@corinagum](https://github.com/corinagum) in PR [#2423](https://github.com/microsoft/BotFramework-WebChat/pull/2423)
- Fix [#2415](https://github.com/microsoft/BotFramework-WebChat/issues/2415) and [#2416](https://github.com/microsoft/BotFramework-WebChat/issues/2416). Fix receipt card rendering, by [@compulim](https://github.com/compulim) in PR [#2417](https://github.com/microsoft/BotFramework-WebChat/issues/2417)
- Fix [#2415](https://github.com/microsoft/BotFramework-WebChat/issues/2415) and [#2416](https://github.com/microsoft/BotFramework-WebChat/issues/2416). Fix Adaptive Cards cannot be disabled on-the-fly, by [@compulim](https://github.com/compulim) in PR [#2417](https://github.com/microsoft/BotFramework-WebChat/issues/2417)
- Fix [#2360](https://github.com/microsoft/BotFramework-WebChat/issues/2360). Timestamp should update on language change, by [@compulim](https://github.com/compulim) in PR [#2414](https://github.com/microsoft/BotFramework-WebChat/pull/2414)

### Added

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 1 addition & 6 deletions __tests__/setup/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,7 @@
...props
};

renderWebChat = props => {
console.log(props);

window.WebChat.renderWebChat(props, document.getElementById('webchat'));
};

renderWebChat = props => window.WebChat.renderWebChat(props, document.getElementById('webchat'));
renderWebChat(props);

document.querySelector('#webchat > *').focus();
Expand Down
28 changes: 28 additions & 0 deletions __tests__/timestamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { imageSnapshotOptions, timeouts } from './constants.json';

import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown';
import uiConnected from './setup/conditions/uiConnected';

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

jest.setTimeout(timeouts.test);

test('update timestamp on-the-fly', async () => {
const { driver, pageObjects } = await setupWebDriver();

await driver.wait(uiConnected(), timeouts.directLine);
await pageObjects.sendMessageViaSendBox('echo Hello, World!', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);

await pageObjects.updateProps({ locale: 'zh-HK' });

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);

await pageObjects.updateProps({ locale: 'zh-YUE' });

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);
});
8 changes: 3 additions & 5 deletions packages/component/src/Utils/RelativeTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ function getText(language, value) {
}

const RelativeTime = ({ language, value }) => {
const [text, setText] = useState(getText(language, value));
const [timer, setTimer] = useState(nextTimer(value));

const localizedAbsoluteTime = localize('SentAt', language) + getLocaleString(value, language);

const handleInterval = useCallback(() => {
setText(getText(language, value));
setTimer(nextTimer(value));
}, [language, value]);

const localizedAbsoluteTime = localize('SentAt', language) + getLocaleString(value, language);
const text = getText(language, value);

return (
<React.Fragment>
<ScreenReaderText text={localizedAbsoluteTime} />
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const App = ({ store }) => {

const handleLanguageChange = useCallback(
({ target: { value } }) => {
setLanguage(!!value);
setLanguage(value);
document.querySelector('html').setAttribute('lang', value || window.navigator.language);
window.sessionStorage.setItem('PLAYGROUND_LANGUAGE', value);
},
Expand Down

0 comments on commit 7de0a84

Please sign in to comment.