blob: 8647e3b6c65232d5119ca31f7402dcd4f7a47861 [file] [log] [blame]
Adrià Vilanova Martínez12c84c32024-10-19 15:55:15 +02001import { beforeEach, describe, expect, it, jest } from '@jest/globals';
2import NodeWatcherScriptAdapter from './NodeWatcherScript.adapter';
3import { NodeWatcherPort } from '../../../presentation/nodeWatcher/NodeWatcher.port';
4import { NodeWatcherHandler } from '../../../presentation/nodeWatcher/NodeWatcherHandler';
5
6describe('NodeWatcherScriptAdapter', () => {
7 const fakeNodeWatcher: NodeWatcherPort = {
8 start: jest.fn<NodeWatcherPort['start']>(),
9 pause: jest.fn<NodeWatcherPort['pause']>(),
10 setHandler: jest.fn<NodeWatcherPort['setHandler']>(),
11 removeHandler: jest.fn<NodeWatcherPort['removeHandler']>(),
12 };
13
14 beforeEach(() => {
15 jest.resetAllMocks();
16 });
17
18 describe('When the script is executed', () => {
19 it('should start the NodeWatcher', () => {
20 const sut = new NodeWatcherScriptAdapter(fakeNodeWatcher, new Map([]));
21 sut.execute();
22
23 expect(fakeNodeWatcher.start).toBeCalledTimes(1);
24 });
25
26 it('should add the handlers to NodeWatcher', () => {
27 const key = 'test-handler';
28 const handler: NodeWatcherHandler = {
29 nodeFilter: () => false,
30 onMutatedNode: () => undefined,
31 };
32 const handlers = new Map([[key, handler]]);
33 const sut = new NodeWatcherScriptAdapter(fakeNodeWatcher, handlers);
34 sut.execute();
35
36 expect(fakeNodeWatcher.setHandler).toHaveBeenCalledTimes(1);
37 expect(fakeNodeWatcher.setHandler).toHaveBeenCalledWith(key, handler);
38 });
39 });
40});