Adrià Vilanova MartÃnez | 12c84c3 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 1 | import { beforeEach, describe, expect, it, jest } from '@jest/globals'; |
| 2 | import NodeWatcherScriptAdapter from './NodeWatcherScript.adapter'; |
| 3 | import { NodeWatcherPort } from '../../../presentation/nodeWatcher/NodeWatcher.port'; |
| 4 | import { NodeWatcherHandler } from '../../../presentation/nodeWatcher/NodeWatcherHandler'; |
| 5 | |
| 6 | describe('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 | }); |