|
| 1 | +'use strict'; |
| 2 | +import ScriptView from '@/main-app/components/scripts/script-view'; |
| 3 | +import {createLocalVue, mount} from '@vue/test-utils'; |
| 4 | +import Vuex from 'vuex'; |
| 5 | + |
| 6 | +const localVue = createLocalVue(); |
| 7 | +localVue.use(Vuex); |
| 8 | + |
| 9 | + |
| 10 | +describe('Test ScriptView', function () { |
| 11 | + let scriptView; |
| 12 | + let store; |
| 13 | + |
| 14 | + beforeEach(async function () { |
| 15 | + store = new Vuex.Store({ |
| 16 | + modules: { |
| 17 | + scripts: { |
| 18 | + namespaced: true, |
| 19 | + state: { |
| 20 | + selectedScript: 'abc' |
| 21 | + } |
| 22 | + }, |
| 23 | + scriptConfig: { |
| 24 | + namespaced: true, |
| 25 | + state: { |
| 26 | + scriptConfig: { |
| 27 | + description: '' |
| 28 | + }, |
| 29 | + loading: false |
| 30 | + } |
| 31 | + }, |
| 32 | + executions: { |
| 33 | + namespaced: true, |
| 34 | + state: { |
| 35 | + currentExecutor: null, |
| 36 | + executors: {} |
| 37 | + }, |
| 38 | + actions: { |
| 39 | + selectExecutor({state}, executor) { |
| 40 | + state.currentExecutor = executor; |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + }); |
| 46 | + |
| 47 | + scriptView = mount(ScriptView, { |
| 48 | + attachToDocument: true, |
| 49 | + store, |
| 50 | + localVue |
| 51 | + }); |
| 52 | + |
| 53 | + scriptView.vm.$parent.$forceUpdate(); |
| 54 | + await scriptView.vm.$nextTick(); |
| 55 | + }); |
| 56 | + |
| 57 | + afterEach(function () { |
| 58 | + scriptView.destroy(); |
| 59 | + }); |
| 60 | + |
| 61 | + describe('Test log content', function () { |
| 62 | + it('test init with logs', async function () { |
| 63 | + store.state.executions.currentExecutor = { |
| 64 | + state: { |
| 65 | + id: 1, |
| 66 | + scriptName: 'my script', |
| 67 | + logChunks: ['a', 'b', 'c'], |
| 68 | + inputPromptText: '', |
| 69 | + inlineImages: {} |
| 70 | + } |
| 71 | + }; |
| 72 | + |
| 73 | + const newScriptView = mount(ScriptView, { |
| 74 | + attachToDocument: true, |
| 75 | + store, |
| 76 | + localVue |
| 77 | + }); |
| 78 | + |
| 79 | + newScriptView.vm.$parent.$forceUpdate(); |
| 80 | + await newScriptView.vm.$nextTick(); |
| 81 | + |
| 82 | + try { |
| 83 | + const logText = newScriptView.get('.log-content').text(); |
| 84 | + expect(logText).toEqual('abc'); |
| 85 | + |
| 86 | + } finally { |
| 87 | + newScriptView.destroy(); |
| 88 | + } |
| 89 | + }); |
| 90 | + }); |
| 91 | +}); |
0 commit comments