aboutsummaryrefslogtreecommitdiff
path: root/test/content/usecases/AddonEnabledUseCase.test.ts
blob: 8a614c5d27ed2474ddcaafdfd3df6205dcd0c8e8 (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
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
97
import AddonEnabledRepository from "../../../src/content/repositories/AddonEnabledRepository";
import AddonEnabledUseCase from "../../../src/content/usecases/AddonEnabledUseCase";
import AddonIndicatorClient from "../../../src/content/client/AddonIndicatorClient";
import { expect } from "chai";
import MockConsoleFramePresenter from "../operators/impls/MockConsoleFramePresenter";

class MockAddonEnabledRepository implements AddonEnabledRepository {
  private enabled: boolean;

  constructor(init: boolean) {
    this.enabled = init;
  }

  set(on: boolean): void {
    this.enabled = on;
  }

  get(): boolean {
    return this.enabled;
  }
}

class MockAddonIndicatorClient implements AddonIndicatorClient {
  public enabled: boolean;

  constructor(init: boolean) {
    this.enabled = init;
  }

  async setEnabled(enabled: boolean): Promise<void> {
    this.enabled = enabled;
    return;
  }
}

describe("AddonEnabledUseCase", () => {
  let repository: MockAddonEnabledRepository;
  let indicator: MockAddonIndicatorClient;
  let presenter: MockConsoleFramePresenter;
  let sut: AddonEnabledUseCase;

  beforeEach(() => {
    repository = new MockAddonEnabledRepository(false);
    indicator = new MockAddonIndicatorClient(false);
    presenter = new MockConsoleFramePresenter(false);
    sut = new AddonEnabledUseCase(indicator, repository, presenter);
  });

  describe("#enable", () => {
    it("store and indicate as enabled", async () => {
      await sut.enable();

      expect(repository.get()).to.be.true;
      expect(indicator.enabled).to.be.true;
      expect(presenter.attached).to.be.true;
    });
  });

  describe("#disable", async () => {
    it("store and indicate as disabled", async () => {
      await sut.disable();

      expect(repository.get()).to.be.false;
      expect(indicator.enabled).to.be.false;
      expect(presenter.attached).to.be.false;
    });
  });

  describe("#toggle", () => {
    it("toggled enabled and disabled", async () => {
      repository.set(true);
      await sut.toggle();

      expect(repository.get()).to.be.false;
      expect(indicator.enabled).to.be.false;
      expect(presenter.attached).to.be.false;

      repository.set(false);

      await sut.toggle();

      expect(repository.get()).to.be.true;
      expect(indicator.enabled).to.be.true;
      expect(presenter.attached).to.be.true;
    });
  });

  describe("#getEnabled", () => {
    it("returns current addon enabled", () => {
      repository.set(true);
      expect(sut.getEnabled()).to.be.true;

      repository.set(false);
      expect(sut.getEnabled()).to.be.false;
    });
  });
});