@@ -2,16 +2,22 @@ import { expect, fixture, html } from '@open-wc/testing';
2
2
3
3
import '../../../../src/editors/publisher/data-set-editor.js' ;
4
4
import { DataSetEditor } from '../../../../src/editors/publisher/data-set-editor.js' ;
5
+ import { cloneTestDoc } from './foundation.test.js' ;
5
6
6
7
describe ( 'Editor for DataSet element' , ( ) => {
7
8
let doc : XMLDocument ;
9
+ let otherDoc : XMLDocument ;
8
10
let element : DataSetEditor ;
9
11
10
12
beforeEach ( async ( ) => {
11
13
doc = await fetch ( '/test/testfiles/valid2007B4.scd' )
12
14
. then ( response => response . text ( ) )
13
15
. then ( str => new DOMParser ( ) . parseFromString ( str , 'application/xml' ) ) ;
14
16
17
+ otherDoc = await fetch ( '/test/testfiles/history.scd' )
18
+ . then ( response => response . text ( ) )
19
+ . then ( str => new DOMParser ( ) . parseFromString ( str , 'application/xml' ) ) ;
20
+
15
21
element = await fixture (
16
22
html `< data-set-editor .doc =${ doc } > </ data-set-editor > `
17
23
) ;
@@ -21,6 +27,8 @@ describe('Editor for DataSet element', () => {
21
27
await expect ( element ) . shadowDom . to . equalSnapshot ( ) ) ;
22
28
23
29
describe ( 'with a selected DataSet' , ( ) => {
30
+ let newDoc : XMLDocument ;
31
+
24
32
beforeEach ( async ( ) => {
25
33
(
26
34
element . shadowRoot ?. querySelector (
@@ -33,5 +41,56 @@ describe('Editor for DataSet element', () => {
33
41
34
42
it ( 'looks like the latest snapshot' , async ( ) =>
35
43
await expect ( element ) . shadowDom . to . equalSnapshot ( ) ) ;
44
+
45
+ describe ( 'on selected element update' , ( ) => {
46
+ beforeEach ( async ( ) => {
47
+ newDoc = cloneTestDoc ( doc ) ;
48
+ element . doc = newDoc ;
49
+ await element . updateComplete ;
50
+
51
+ await element . selectionList . requestUpdate ( ) ;
52
+ } ) ;
53
+
54
+ it ( 'does not reset selected Element' , async ( ) =>
55
+ expect ( element . selectedDataSet ) . to . equal (
56
+ newDoc . querySelector ( 'DataSet' )
57
+ ) ) ;
58
+
59
+ it ( 'does not reset selection' , async ( ) =>
60
+ expect ( element . selectionList . selected ) . to . not . be . null ) ;
61
+ } ) ;
62
+
63
+ describe ( 'on selected element remove' , ( ) => {
64
+ beforeEach ( async ( ) => {
65
+ element . selectedDataSet ?. parentElement ?. removeChild (
66
+ element . selectedDataSet
67
+ ) ;
68
+ element . doc = cloneTestDoc ( doc ) ;
69
+ await element . updateComplete ;
70
+
71
+ await element . selectionList . requestUpdate ( ) ;
72
+ } ) ;
73
+
74
+ it ( 'resets selected Element' , async ( ) =>
75
+ expect ( element . selectedDataSet ) . to . be . undefined ) ;
76
+
77
+ it ( 'reset selection' , async ( ) =>
78
+ expect ( element . selectionList . selected ) . to . be . null ) ;
79
+ } ) ;
80
+
81
+ describe ( 'on new doc loaded' , ( ) => {
82
+ beforeEach ( async ( ) => {
83
+ element . doc = otherDoc ;
84
+ await element . updateComplete ;
85
+
86
+ await element . selectionList . requestUpdate ( ) ;
87
+ } ) ;
88
+
89
+ it ( 'does not reset selected Element' , async ( ) =>
90
+ expect ( element . selectedDataSet ) . to . be . undefined ) ;
91
+
92
+ it ( 'does not reset selection' , async ( ) =>
93
+ expect ( element . selectionList . selected ) . to . be . null ) ;
94
+ } ) ;
36
95
} ) ;
37
96
} ) ;
0 commit comments