forked from learningequality/kolibri-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting-playground.vue
91 lines (81 loc) · 2.28 KB
/
testing-playground.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
<!--
Testing Playground: A dedicated page for component visual testing
*****************************************************
Please do not modify the contents of this file.
-->
<div
id="testing-playground"
style="padding: 24px"
>
<component
:is="component"
v-bind="componentProps"
>
<!-- Render slots if provided -->
<template v-for="(slot, name) in slots">
<!-- eslint-disable vue/no-v-text-v-html-on-component -->
<!-- eslint-disable vue/no-v-html -->
<component
:is="slot.element"
v-if="slot.element"
v-bind="slot.elementProps"
:key="name"
v-html="slot.innerHTML"
/>
</template>
</component>
</div>
</template>
<script>
/**
* Renders the components for visual testing
* to ensure expected visual behavior under
* various conditions.
*/
export default {
name: 'VisualTestingPlayground',
data() {
return {
/**
* @type {string|null} The name of the component to be dynamically rendered.
*/
component: null,
/**
* @type {Object} The props to be passed to the dynamically rendered component.
*/
componentProps: {},
/**
* @type {Object} The slots to be passed to the dynamically rendered component.
*/
slots: {},
};
},
/**
* Adds an event listener for messages from the test runner.
* This listener will trigger the `handleMessage` method.
*/
mounted() {
window.addEventListener('message', this.handleMessage);
},
/**
* Removes the event listener for messages from the test runner.
*/
beforeDestroy() {
window.removeEventListener('message', this.handleMessage);
},
methods: {
/**
* Handles messages received from the test runner to render a specified component.
* @param {MessageEvent} event - The message event containing the component and its props.
*/
handleMessage(event) {
if (event.data.type === 'RENDER_COMPONENT') {
this.component = event.data.component;
this.componentProps = event.data.props;
this.slots = event.data.slots || {};
}
},
},
};
</script>