|
| 1 | +import { render } from '@testing-library/vue' |
| 2 | +import KeyboardShortcut from '../KeyboardShortcut.vue' |
| 3 | + |
| 4 | +vi.mock('@archilogic/toolbox', async importOriginal => { |
| 5 | + const toolbox = await importOriginal<typeof import('@archilogic/toolbox')>() |
| 6 | + return { |
| 7 | + ...toolbox, |
| 8 | + isMac: false |
| 9 | + } |
| 10 | +}) |
| 11 | +describe('KeyboardShortcut', () => { |
| 12 | + describe('when given a single shortcut', () => { |
| 13 | + it('renders the shortcut', () => { |
| 14 | + const { getByText } = render(KeyboardShortcut, { |
| 15 | + props: { shortcut: { keySequence: 'a' } } |
| 16 | + }) |
| 17 | + expect(getByText('A')).toBeTruthy() |
| 18 | + }) |
| 19 | + }) |
| 20 | + |
| 21 | + describe('when given several shortcuts', () => { |
| 22 | + it('renders the shortcuts, separated by "or"s', () => { |
| 23 | + const { getByText, queryAllByText } = render(KeyboardShortcut, { |
| 24 | + props: { shortcut: [{ keySequence: 'a' }, { keySequence: 'b' }, { keySequence: 'c' }] } |
| 25 | + }) |
| 26 | + expect(getByText('A')).toBeTruthy() |
| 27 | + expect(getByText('B')).toBeTruthy() |
| 28 | + expect(getByText('C')).toBeTruthy() |
| 29 | + expect(queryAllByText('or').length).toEqual(2) |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + it('renders a "ctrl" modifier key', () => { |
| 34 | + const { getByText } = render(KeyboardShortcut, { |
| 35 | + props: { shortcut: { modifiers: ['ctrl'] } } |
| 36 | + }) |
| 37 | + |
| 38 | + expect(getByText('Ctrl')).toBeTruthy() |
| 39 | + }) |
| 40 | + |
| 41 | + it('renders a "shift" modifier key', () => { |
| 42 | + const { getByText } = render(KeyboardShortcut, { |
| 43 | + props: { shortcut: { modifiers: ['shift'] } } |
| 44 | + }) |
| 45 | + expect(getByText('⇧')).toBeTruthy() |
| 46 | + }) |
| 47 | + |
| 48 | + it('renders a "backspace" key', () => { |
| 49 | + const { getByText } = render(KeyboardShortcut, { |
| 50 | + props: { shortcut: { keySequence: 'backspace' } } |
| 51 | + }) |
| 52 | + expect(getByText('⌫')).toBeTruthy() |
| 53 | + }) |
| 54 | + |
| 55 | + it('renders a "delete" key', () => { |
| 56 | + const { getByText } = render(KeyboardShortcut, { |
| 57 | + props: { shortcut: { keySequence: 'delete' } } |
| 58 | + }) |
| 59 | + expect(getByText('Delete')).toBeTruthy() |
| 60 | + }) |
| 61 | + |
| 62 | + it('renders a "space" key', () => { |
| 63 | + const { getByText } = render(KeyboardShortcut, { |
| 64 | + props: { shortcut: { keySequence: ' ' } } |
| 65 | + }) |
| 66 | + expect(getByText('Space')).toBeTruthy() |
| 67 | + }) |
| 68 | + |
| 69 | + it('renders an "escape" key', () => { |
| 70 | + const { getByText } = render(KeyboardShortcut, { |
| 71 | + props: { shortcut: { keySequence: 'escape' } } |
| 72 | + }) |
| 73 | + expect(getByText('Esc')).toBeTruthy() |
| 74 | + }) |
| 75 | + |
| 76 | + it('renders an "enter" key', () => { |
| 77 | + const { getByText } = render(KeyboardShortcut, { |
| 78 | + props: { shortcut: { keySequence: 'enter' } } |
| 79 | + }) |
| 80 | + expect(getByText('↵')).toBeTruthy() |
| 81 | + }) |
| 82 | + |
| 83 | + it('renders a key or key sequence in upper case', () => { |
| 84 | + const { getByText } = render(KeyboardShortcut, { |
| 85 | + props: { shortcut: { keySequence: 'wa' } } |
| 86 | + }) |
| 87 | + expect(getByText('WA')).toBeTruthy() |
| 88 | + }) |
| 89 | + |
| 90 | + it('renders a mouse event', () => { |
| 91 | + const { getByText } = render(KeyboardShortcut, { |
| 92 | + props: { shortcut: { mouseEvent: 'click' } } |
| 93 | + }) |
| 94 | + expect(getByText('click')).toBeTruthy() |
| 95 | + }) |
| 96 | + |
| 97 | + describe('when not on Mac', () => { |
| 98 | + it('renders an "alt" modifier key', () => { |
| 99 | + const { getByText } = render(KeyboardShortcut, { |
| 100 | + props: { shortcut: { modifiers: ['alt'] } } |
| 101 | + }) |
| 102 | + expect(getByText('Alt')).toBeTruthy() |
| 103 | + }) |
| 104 | + |
| 105 | + it('renders a "meta" modifier key', () => { |
| 106 | + const { getByText } = render(KeyboardShortcut, { |
| 107 | + props: { shortcut: { modifiers: ['meta'] } } |
| 108 | + }) |
| 109 | + expect(getByText('⊞')).toBeTruthy() |
| 110 | + }) |
| 111 | + }) |
| 112 | +}) |
0 commit comments