-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #917 from openSUSE/installer-keymap
Configure installer keymap
- Loading branch information
Showing
14 changed files
with
319 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) [2023] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
import React from "react"; | ||
import { FormSelect, FormSelectOption } from "@patternfly/react-core"; | ||
|
||
import cockpit from "../../lib/cockpit"; | ||
|
||
import { Icon } from "~/components/layout"; | ||
import { _ } from "~/i18n"; | ||
import { useInstallerL10n } from "~/context/installerL10n"; | ||
import { useL10n } from "~/context/l10n"; | ||
import { localConnection } from "~/utils"; | ||
import { If } from "~/components/core"; | ||
|
||
const sort = (keymaps) => { | ||
// sort the keymap names using the current locale | ||
const lang = cockpit.language || "en"; | ||
return keymaps.sort((k1, k2) => k1.name.localeCompare(k2.name, lang)); | ||
}; | ||
|
||
export default function InstallerKeymapSwitcher() { | ||
const { keymap, changeKeymap } = useInstallerL10n(); | ||
const { keymaps } = useL10n(); | ||
|
||
const onChange = (_, id) => changeKeymap(id); | ||
|
||
const options = sort(keymaps) | ||
.map((keymap, index) => <FormSelectOption key={index} value={keymap.id} label={keymap.name} />); | ||
|
||
return ( | ||
<> | ||
<h3> | ||
{/* TRANSLATORS: label for keyboard layout selection */} | ||
<Icon name="keyboard" size="24" />{_("Keyboard")} | ||
</h3> | ||
<If | ||
condition={localConnection()} | ||
then={ | ||
<FormSelect | ||
id="keyboard" | ||
// TRANSLATORS: label for keyboard layout selection | ||
aria-label={_("keyboard")} | ||
value={keymap} | ||
onChange={onChange} | ||
> | ||
{options} | ||
</FormSelect> | ||
} | ||
else={ | ||
// TRANSLATORS: | ||
_("Keyboard layout cannot be changed in remote installation") | ||
} | ||
/> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) [2023] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
import React from "react"; | ||
import { screen } from "@testing-library/react"; | ||
import { plainRender } from "~/test-utils"; | ||
|
||
import InstallerKeymapSwitcher from "./InstallerKeymapSwitcher"; | ||
|
||
let mockChangeKeyboardFn; | ||
|
||
jest.mock("~/lib/cockpit", () => ({ | ||
gettext: term => term, | ||
})); | ||
|
||
jest.mock("~/context/installerL10n", () => ({ | ||
...jest.requireActual("~/context/installerL10n"), | ||
useInstallerL10n: () => ({ | ||
changeKeymap: mockChangeKeyboardFn, | ||
keymap: "us" | ||
}) | ||
})); | ||
|
||
jest.mock("~/context/l10n", () => ({ | ||
...jest.requireActual("~/context/l10n"), | ||
useL10n: () => ({ | ||
keymaps: [ | ||
{ id: "cz", name: "Czech" }, | ||
{ id: "cz(qwerty)", name: "Czech (QWERTY)" }, | ||
{ id: "de", name: "German" }, | ||
{ id: "us", name: "English (US)" }, | ||
{ id: "us(dvorak)", name: "English (Dvorak)" } | ||
] | ||
}) | ||
})); | ||
|
||
beforeEach(() => { | ||
mockChangeKeyboardFn = jest.fn(); | ||
}); | ||
|
||
it("InstallerKeymapSwitcher", async () => { | ||
const { user } = plainRender(<InstallerKeymapSwitcher />); | ||
|
||
// the current keyboard is correctly selected | ||
expect(screen.getByRole("option", { name: "English (US)" }).selected).toBe(true); | ||
|
||
// change the keyboard | ||
await user.selectOptions( | ||
screen.getByRole("combobox", { label: "Keyboard" }), | ||
screen.getByRole("option", { name: "Czech" }) | ||
); | ||
expect(mockChangeKeyboardFn).toHaveBeenCalledWith("cz"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.