Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use documentLocaleSettings #156

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
"access": "public"
},
"dependencies": {
"@rollup/plugin-node-resolve": "^15",
"@brightspace-ui/intl": "^3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we can't use @brightspace-ui/testing in intl, or would that still work? 🤔 Looks like we use mocha directly anyways so maybe doesn't matter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that's what it implies. I'm OK with that, since yeah keeping intl bare bones seems like a good call anyway given how low-level it is.

"@open-wc/testing": "^3",
"@rollup/plugin-node-resolve": "^15",
"@web/config-loader": "^0.2",
"@web/dev-server": "^0.2",
"@web/rollup-plugin-html": "^2",
Expand Down
11 changes: 7 additions & 4 deletions src/browser/reset.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { sendMouse, setViewport } from '@web/test-runner-commands';
import { getDocumentLocaleSettings } from '@brightspace-ui/intl/lib/common.js';
import { nextFrame } from '@open-wc/testing';

const DEFAULT_LANG = 'en',
DEFAULT_MATHJAX_RENDER_LATEX = false,
DEFAULT_VIEWPORT_HEIGHT = 800,
DEFAULT_VIEWPORT_WIDTH = 800;

let currentLang = undefined,
const documentLocaleSettings = getDocumentLocaleSettings();

let
currentMathjaxRenderLatex = DEFAULT_MATHJAX_RENDER_LATEX,
currentRtl = false,
currentViewportHeight = 0,
Expand Down Expand Up @@ -57,9 +60,9 @@ export async function reset(opts = {}) {
currentRtl = opts.rtl;
}

if (opts.lang !== currentLang) {
document.documentElement.setAttribute('lang', opts.lang);
currentLang = opts.lang;
opts.lang ??= '';
if (documentLocaleSettings.lamguage !== opts.lang) {
Copy link
Contributor

@svanherk svanherk Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this should be "language" and this is working right now because this is always true?

document.documentElement.lang = opts.lang;
Comment on lines +63 to +65
Copy link
Contributor Author

@bearfriend bearfriend Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Avoids coercion of nullish values to strings (i.e. <html lang="null" ...>)
  2. Compares against documentLocaleSettings for guaranteed latest change
  3. Sets document.documentElement.lang to guarantee all values are in sync (documentLocaleSettings is observing this value)

awaitNextFrame = true;
}

Expand Down