Welcome to mirror list, hosted at ThFree Co, Russian Federation.

shortcut_spec.js « shortcuts « behaviors « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 44bb74ce1795e6ba87812e23fd85f99f40443341 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { shallowMount } from '@vue/test-utils';
import Shortcut from '~/behaviors/shortcuts/shortcut.vue';

describe('Shortcut Vue Component', () => {
  const render = (shortcuts) => shallowMount(Shortcut, { propsData: { shortcuts } }).html();

  afterEach(() => {
    delete window.gl.client;
  });

  describe.each([true, false])('With browser env isMac: %p', (isMac) => {
    beforeEach(() => {
      window.gl = { client: { isMac } };
    });

    it.each([
      ['up', '<kbd>↑</kbd>'],
      ['down', '<kbd>↓</kbd>'],
      ['left', '<kbd>←</kbd>'],
      ['right', '<kbd>→</kbd>'],
      ['ctrl', '<kbd>Ctrl</kbd>'],
      ['shift', '<kbd>Shift</kbd>'],
      ['enter', '<kbd>Enter</kbd>'],
      ['esc', '<kbd>Esc</kbd>'],
      // Some normal ascii letter
      ['a', '<kbd>a</kbd>'],
      // An umlaut letter
      ['ø', '<kbd>ø</kbd>'],
      // A number
      ['5', '<kbd>5</kbd>'],
    ])('renders platform agnostic key %p as: %p', (key, rendered) => {
      expect(render([key])).toEqual(`<div>${rendered}</div>`);
    });

    it('renders keys combined with plus ("+") correctly', () => {
      expect(render(['shift+a+b+c'])).toEqual(
        `<div><kbd>Shift</kbd> + <kbd>a</kbd> + <kbd>b</kbd> + <kbd>c</kbd></div>`,
      );
    });

    it('renders keys combined with space (" ") correctly', () => {
      expect(render(['shift a b c'])).toEqual(
        `<div><kbd>Shift</kbd> then <kbd>a</kbd> then <kbd>b</kbd> then <kbd>c</kbd></div>`,
      );
    });

    it('renders multiple shortcuts correctly', () => {
      expect(render(['shift+[', 'shift+k'])).toEqual(
        `<div><kbd>Shift</kbd> + <kbd>[</kbd> or <br><kbd>Shift</kbd> + <kbd>k</kbd></div>`,
      );
      expect(render(['[', 'k'])).toEqual(`<div><kbd>[</kbd> or <kbd>k</kbd></div>`);
    });
  });

  describe('With browser env isMac: true', () => {
    beforeEach(() => {
      window.gl = { client: { isMac: true } };
    });

    it.each([
      ['mod', '<kbd>⌘</kbd>'],
      ['command', '<kbd>⌘</kbd>'],
      ['meta', '<kbd>⌘</kbd>'],
      ['option', '<kbd>⌥</kbd>'],
      ['alt', '<kbd>⌥</kbd>'],
    ])('renders platform specific key %p as: %p', (key, rendered) => {
      expect(render([key])).toEqual(`<div>${rendered}</div>`);
    });

    it('does render Mac specific shortcuts', () => {
      expect(render(['command+[', 'ctrl+k'])).toEqual(
        `<div><kbd>⌘</kbd> + <kbd>[</kbd> or <br><kbd>Ctrl</kbd> + <kbd>k</kbd></div>`,
      );
    });
  });

  describe('With browser env isMac: false', () => {
    beforeEach(() => {
      window.gl = { client: { isMac: false } };
    });

    it.each([
      ['mod', '<kbd>Ctrl</kbd>'],
      ['command', ''],
      ['meta', ''],
      ['option', '<kbd>Alt</kbd>'],
      ['alt', '<kbd>Alt</kbd>'],
    ])('renders platform specific key %p as: %p', (key, rendered) => {
      expect(render([key])).toEqual(`<div>${rendered}</div>`);
    });

    it('does not render Mac specific shortcuts', () => {
      expect(render(['command+[', 'ctrl+k'])).toEqual(`<div><kbd>Ctrl</kbd> + <kbd>k</kbd></div>`);
    });
  });
});