Skip to content

Commit 7e029c7

Browse files
committed
#339 fixed missing logs when opening a new script-view for existing executor
1 parent 4808e91 commit 7e029c7

2 files changed

Lines changed: 113 additions & 13 deletions

File tree

web-src/src/main-app/components/scripts/script-view.vue

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
'red lighten-1': !killEnabled,
1818
'grey darken-4': killEnabled}"
1919
@click="stopScript">
20-
{{stopButtonLabel}}
20+
{{ stopButtonLabel }}
2121
</button>
2222
<div class="button-gap" v-if="schedulable"></div>
2323
<ScheduleButton :disabled="!enableScheduleButton" @click="openSchedule" v-if="schedulable"/>
@@ -347,23 +347,32 @@
347347
},
348348
349349
logChunks: {
350+
immediate: true,
350351
handler(newValue, oldValue) {
351-
if (isNull(newValue)) {
352-
this.setLog('');
353-
this.nextLogIndex = 0;
352+
const updateLog = () => {
353+
if (isNull(newValue)) {
354+
this.setLog('');
355+
this.nextLogIndex = 0;
354356
355-
return;
356-
}
357+
return;
358+
}
357359
358-
if (newValue !== oldValue) {
359-
this.setLog('');
360-
this.nextLogIndex = 0;
361-
}
360+
if (newValue !== oldValue) {
361+
this.setLog('');
362+
this.nextLogIndex = 0;
363+
}
364+
365+
for (; this.nextLogIndex < newValue.length; this.nextLogIndex++) {
366+
const logChunk = newValue[this.nextLogIndex];
362367
363-
for (; this.nextLogIndex < newValue.length; this.nextLogIndex++) {
364-
const logChunk = newValue[this.nextLogIndex];
368+
this.appendLog(logChunk);
369+
}
370+
}
365371
366-
this.appendLog(logChunk);
372+
if (isNull(this.$refs.logPanel)) {
373+
this.$nextTick(updateLog);
374+
} else {
375+
updateLog();
367376
}
368377
}
369378
},
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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

Comments
 (0)