Skip to content

Commit

Permalink
fix failing test ci
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Nov 19, 2024
1 parent 85ece5b commit c441792
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@
"no-async-promise-executor": "off",
"no-bitwise": "off",
"unicorn/filename-case": "off",
"max-depth": "off"
"max-depth": "off",
"unicorn/no-typeof-undefined": "off"
},
"overrides": [
{
Expand Down
19 changes: 1 addition & 18 deletions src/react/Keybinding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import triangle from './ps_icons/playstation_triangle_console_controller_gamepad
import square from './ps_icons/playstation_square_console_controller_gamepad_icon.svg'
import circle from './ps_icons/circle_playstation_console_controller_gamepad_icon.svg'
import cross from './ps_icons/cross_playstation_console_controller_gamepad_icon.svg'
import { parseBindingName } from './parseKeybindingName'


type Props = {
Expand All @@ -30,24 +31,6 @@ export default ({ type, val, isPS }: Props) => {
</>
}

export async function parseBindingName (binding: string) {
if (!binding) return ''

const { keyboard } = navigator
const layoutMap = await keyboard?.getLayoutMap?.() ?? new Map<string, string>()

const mapKey = (key: string) => layoutMap.get(key) || key

const cut = binding.replaceAll(/(Digit|Key)/g, '')
const parts = cut.includes('+') ? cut.split('+') : [cut]

for (let i = 0; i < parts.length; i++) {
parts[i] = mapKey(parts[i]).split(/(?<=[a-z])(?=\d)/).join(' ').split(/(?=[A-Z])/).reverse().join(' ')
}

return parts.join(' + ')
}

const buttonsMap = {
'A': cross,
'B': circle,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from 'vitest'
import { parseBindingName } from './Keybinding'
import { parseBindingName } from './parseKeybindingName'

test('display keybinding correctly', async () => {
expect(await parseBindingName('unknown')).toMatchInlineSnapshot('"unknown"')
Expand Down
17 changes: 17 additions & 0 deletions src/react/parseKeybindingName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export async function parseBindingName (binding: string) {
if (!binding) return ''

const { keyboard } = navigator
const layoutMap = (typeof keyboard === 'undefined' ? undefined : await keyboard?.getLayoutMap?.()) ?? new Map<string, string>()

const mapKey = (key: string) => layoutMap.get(key) || key

const cut = binding.replaceAll(/(Digit|Key)/g, '')
const parts = cut.includes('+') ? cut.split('+') : [cut]

for (let i = 0; i < parts.length; i++) {
parts[i] = mapKey(parts[i]).split(/(?<=[a-z])(?=\d)/).join(' ').split(/(?=[A-Z])/).reverse().join(' ')
}

return parts.join(' + ')
}
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
include: [
'../../src/botUtils.test.ts',
'../../src/markdownToFormattedText.test.ts',
'../../src/react/keybinding.test.ts',
'../../src/react/parseKeybindingName.test.ts',
'lib/mesher/test/tests.test.ts',
'sign-renderer/tests.test.ts'
],
Expand Down

0 comments on commit c441792

Please sign in to comment.