summaryrefslogtreecommitdiffstatshomepage
path: root/tests/fixtures/workspace-cycle.js
blob: 13e1bc71e0e300ccf9bc2ffc86b7837119d405a6 (plain) (blame)
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
import assert from "node:assert/strict";

const bindings = new Map();
const Extension = class {
  getSettings() {
    return {};
  }
};
const Meta = { KeyBindingFlags: { NONE: 0 } };
const Shell = { ActionMode: { NORMAL: 1, OVERVIEW: 2 } };
const Main = {
  wm: {
    addKeybinding(name, settings, flags, mode, callback) {
      assert.equal(mode, 3);
      bindings.set(name, callback);
    },
    removeKeybinding(name) {
      bindings.delete(name);
    },
  },
};
let active = 0;
let activations = 0;
global.workspace_manager = {
  n_workspaces: 3,
  get_active_workspace_index: () => active,
  get_workspace_by_index: (index) => ({
    activate(time) {
      assert.equal(time, 123);
      active = index;
      activations++;
    },
  }),
};
global.get_current_time = () => 123;

// EXTENSION

const extension = new WorkspaceCycle();
extension.enable();
bindings.get("previous-workspace")();
assert.equal(active, 2);
bindings.get("next-workspace")();
assert.equal(active, 0);
bindings.get("next-workspace")();
assert.equal(active, 1);
global.workspace_manager.n_workspaces = 1;
extension.cycle(1);
assert.equal(activations, 3);
extension.disable();
assert.equal(bindings.size, 0);
extension.enable();
assert.equal(bindings.size, 2);
extension.disable();