|
| 1 | +// |
| 2 | +// Copyright (c) Microsoft. All rights reserved. |
| 3 | +// Licensed under the MIT license. |
| 4 | +// |
| 5 | +// Microsoft Bot Framework: http://botframework.com |
| 6 | +// |
| 7 | +// Bot Framework Emulator Github: |
| 8 | +// https://github.com/Microsoft/BotFramwork-Emulator |
| 9 | +// |
| 10 | +// Copyright (c) Microsoft Corporation |
| 11 | +// All rights reserved. |
| 12 | +// |
| 13 | +// MIT License: |
| 14 | +// Permission is hereby granted, free of charge, to any person obtaining |
| 15 | +// a copy of this software and associated documentation files (the |
| 16 | +// "Software"), to deal in the Software without restriction, including |
| 17 | +// without limitation the rights to use, copy, modify, merge, publish, |
| 18 | +// distribute, sublicense, and/or sell copies of the Software, and to |
| 19 | +// permit persons to whom the Software is furnished to do so, subject to |
| 20 | +// the following conditions: |
| 21 | +// |
| 22 | +// The above copyright notice and this permission notice shall be |
| 23 | +// included in all copies or substantial portions of the Software. |
| 24 | +// |
| 25 | +// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, |
| 26 | +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 28 | +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 29 | +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 30 | +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 31 | +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 32 | +// |
| 33 | + |
| 34 | +import { CommandServiceImpl, CommandRegistry, CommandServiceInstance } from '@bfemulator/sdk-shared'; |
| 35 | +import { SharedConstants } from '@bfemulator/app-shared'; |
| 36 | + |
| 37 | +import { addFile, removeFile, clear } from '../state/actions/fileActions'; |
| 38 | +import { addDocPendingChange } from '../state/actions/editorActions'; |
| 39 | + |
| 40 | +import { FileCommands } from './fileCommands'; |
| 41 | + |
| 42 | +const mockDispatch = jest.fn(); |
| 43 | +jest.mock('../state/store', () => ({ |
| 44 | + store: { |
| 45 | + dispatch: action => mockDispatch(action), |
| 46 | + }, |
| 47 | +})); |
| 48 | + |
| 49 | +describe('The file commands', () => { |
| 50 | + let commandService: CommandServiceImpl; |
| 51 | + let registry: CommandRegistry; |
| 52 | + const { File } = SharedConstants.Commands; |
| 53 | + |
| 54 | + beforeAll(() => { |
| 55 | + new FileCommands(); |
| 56 | + const decorator = CommandServiceInstance(); |
| 57 | + const descriptor = decorator({ descriptor: {} }, 'none') as any; |
| 58 | + commandService = descriptor.descriptor.get(); |
| 59 | + registry = commandService.registry; |
| 60 | + }); |
| 61 | + |
| 62 | + beforeEach(mockDispatch.mockClear); |
| 63 | + |
| 64 | + it('should add a file to the store', () => { |
| 65 | + const payload: any = { |
| 66 | + type: 'leaf', |
| 67 | + name: 'somefile.txt', |
| 68 | + path: 'dir/somefile.txt', |
| 69 | + }; |
| 70 | + const command = registry.getCommand(File.Add); |
| 71 | + command(payload); |
| 72 | + |
| 73 | + expect(mockDispatch).toHaveBeenCalledWith(addFile(payload)); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should remove a file from the store', () => { |
| 77 | + const payload: any = { |
| 78 | + type: 'leaf', |
| 79 | + name: 'somefile.txt', |
| 80 | + path: 'dir/somefile.txt', |
| 81 | + }; |
| 82 | + const command = registry.getCommand(File.Remove); |
| 83 | + command(payload); |
| 84 | + |
| 85 | + expect(mockDispatch).toHaveBeenCalledWith(removeFile(payload)); |
| 86 | + }); |
| 87 | + |
| 88 | + it('should clear the file store', () => { |
| 89 | + const command = registry.getCommand(File.Clear); |
| 90 | + command(); |
| 91 | + |
| 92 | + expect(mockDispatch).toHaveBeenCalledWith(clear()); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should mark a file as changed (.chat file)', () => { |
| 96 | + const filename = 'my-file.chat'; |
| 97 | + const command = registry.getCommand(File.Changed); |
| 98 | + command(filename); |
| 99 | + |
| 100 | + expect(mockDispatch).toHaveBeenCalledWith(addDocPendingChange(filename)); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should mark a file as changed (.transcript file)', () => { |
| 104 | + const filename = 'my-file.transcript'; |
| 105 | + const command = registry.getCommand(File.Changed); |
| 106 | + command(filename); |
| 107 | + |
| 108 | + expect(mockDispatch).toHaveBeenCalledWith(addDocPendingChange(filename)); |
| 109 | + }); |
| 110 | +}); |
0 commit comments