aboutsummaryrefslogtreecommitdiff
path: root/test/content/operators/impls/BackgroundOperationOperator.test.ts
blob: 77efeb2ecfede0c47ffc03e3cdcab66dab23c560 (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
import * as operations from "../../../../src/shared/operations";
import BackgroundOperationOperator from "../../../../src/content/operators/impls/BackgroundOperationOperator";
import OperationClient from "../../../../src/content/client/OperationClient";

class MockOperationClient implements OperationClient {
  public readonly executedOps: {
    op: operations.Operation;
    repeat: number;
  }[] = [];
  async execBackgroundOp(
    repeat: number,
    op: operations.Operation
  ): Promise<void> {
    this.executedOps.push({ repeat, op });
  }

  internalOpenUrl(): Promise<void> {
    throw new Error("not implemented");
  }
}

describe("BackgroundOperationOperator", () => {
  describe("#run", () => {
    it("returns an operator", async () => {
      const client = new MockOperationClient();
      const sut = new BackgroundOperationOperator(client, 2, {
        type: operations.TAB_CLOSE,
      });

      await sut.run();

      expect(client.executedOps).toEqual([
        { op: { type: operations.TAB_CLOSE }, repeat: 2 },
      ]);
    });
  });
});