|
| 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 { |
| 35 | + BotActionType, |
| 36 | + load, |
| 37 | + setActive, |
| 38 | + setDirectory, |
| 39 | + close, |
| 40 | + mockAndSetActive, |
| 41 | + botHashGenerated, |
| 42 | + browse, |
| 43 | + closeBot, |
| 44 | + openBotViaFilePathAction, |
| 45 | + openBotViaUrlAction, |
| 46 | + restartConversation, |
| 47 | +} from './botActions'; |
| 48 | + |
| 49 | +describe('bot actions', () => { |
| 50 | + it('should create a load action', () => { |
| 51 | + const bots = [{}, null, undefined, {}]; |
| 52 | + const action = load(bots); |
| 53 | + |
| 54 | + expect(action.type).toBe(BotActionType.load); |
| 55 | + expect(action.payload).toEqual({ bots: [{}, {}] }); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should create a setActive action', () => { |
| 59 | + const bot: any = {}; |
| 60 | + const action = setActive(bot); |
| 61 | + |
| 62 | + expect(action.type).toBe(BotActionType.setActive); |
| 63 | + expect(action.payload).toEqual({ bot: {} }); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should create a setDirectory action', () => { |
| 67 | + const directory = '/some/directory'; |
| 68 | + const action = setDirectory(directory); |
| 69 | + |
| 70 | + expect(action.type).toBe(BotActionType.setDirectory); |
| 71 | + expect(action.payload).toEqual({ directory }); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should create a close action', () => { |
| 75 | + const action = close(); |
| 76 | + |
| 77 | + expect(action.type).toBe(BotActionType.close); |
| 78 | + expect(action.payload).toEqual({}); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should create a mockAndSetActive action', () => { |
| 82 | + const mock: any = { name: 'mockBot', someMockProperty: true }; |
| 83 | + const action = mockAndSetActive(mock); |
| 84 | + |
| 85 | + expect(action.type).toBe(BotActionType.setActive); |
| 86 | + expect(action.payload).toEqual({ |
| 87 | + bot: { |
| 88 | + version: '', |
| 89 | + name: 'mockBot', |
| 90 | + description: '', |
| 91 | + services: [], |
| 92 | + padlock: '', |
| 93 | + someMockProperty: true, |
| 94 | + }, |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + it('should create a botHashGenerated action', () => { |
| 99 | + const hash = 'someHash'; |
| 100 | + const action = botHashGenerated(hash); |
| 101 | + |
| 102 | + expect(action.type).toBe(BotActionType.hashGenerated); |
| 103 | + expect(action.payload).toEqual({ hash }); |
| 104 | + }); |
| 105 | + |
| 106 | + it('should create a browse action', () => { |
| 107 | + const action = browse(); |
| 108 | + |
| 109 | + expect(action.type).toBe(BotActionType.browse); |
| 110 | + expect(action.payload).toEqual({}); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should create a closeBot action', () => { |
| 114 | + const action = closeBot(); |
| 115 | + |
| 116 | + expect(action.type).toBe(BotActionType.close); |
| 117 | + expect(action.payload).toEqual({}); |
| 118 | + }); |
| 119 | + |
| 120 | + it('should create an openBotViaFilePathAction', () => { |
| 121 | + const action = openBotViaFilePathAction('some/path'); |
| 122 | + |
| 123 | + expect(action.type).toBe(BotActionType.openViaFilePath); |
| 124 | + expect(action.payload).toBe('some/path'); |
| 125 | + }); |
| 126 | + |
| 127 | + it('should create an openBotViaUrlAction action', () => { |
| 128 | + const action = openBotViaUrlAction({}); |
| 129 | + |
| 130 | + expect(action.type).toBe(BotActionType.openViaUrl); |
| 131 | + expect(action.payload).toEqual({}); |
| 132 | + }); |
| 133 | + |
| 134 | + it('should create a restartConversation action', () => { |
| 135 | + const conversationId = 'someConvoId'; |
| 136 | + const documentId = 'someDocId'; |
| 137 | + const action = restartConversation(conversationId, documentId); |
| 138 | + |
| 139 | + expect(action.type).toBe(BotActionType.restartConversation); |
| 140 | + expect(action.payload).toEqual({ conversationId, documentId }); |
| 141 | + }); |
| 142 | +}); |
0 commit comments