blob: fc3761575e70b67eaba331c552658bbc56ab8986 (
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
|
import RepeatLastOperator from "../../../../src/background/operators/impls/RepeatLastOperator";
import MockRepeatRepository from "../../mock/MockRepeatRepository";
import OperatorFactory from "../../../../src/background/operators/OperatorFactory";
import * as operations from "../../../../src/shared/operations";
import Operator from "../../../../src/background/operators/Operator";
class MockOperatorFactory implements OperatorFactory {
create(_op: operations.Operation): Operator {
throw new Error("not implemented");
}
}
class MockOperator implements Operator {
run(): Promise<void> {
throw new Error("not implemented");
}
}
describe("RepeatLastOperator", () => {
describe("#run", () => {
it("repeat last operation", async () => {
const operator = new MockOperator();
const runSpy = jest
.spyOn(operator, "run")
.mockReturnValue(Promise.resolve());
const repeatRepository = new MockRepeatRepository();
repeatRepository.setLastOperation({ type: operations.CANCEL });
const operatorFactory = new MockOperatorFactory();
const createSpy = jest
.spyOn(operatorFactory, "create")
.mockReturnValue(operator);
const sut = new RepeatLastOperator(repeatRepository, operatorFactory);
await sut.run();
expect(runSpy).toBeCalledTimes(1);
expect(createSpy).toBeCalledWith({ type: operations.CANCEL });
});
it("does nothing if no last operations", async () => {
const repeatRepository = new MockRepeatRepository();
const operatorFactory = new MockOperatorFactory();
const createSpy = jest.spyOn(operatorFactory, "create");
const sut = new RepeatLastOperator(repeatRepository, operatorFactory);
await sut.run();
expect(createSpy).not.toBeCalled();
});
});
});
|