@@ -6,27 +6,6 @@ import { MockEditorLogger } from '../../mock-editor-logger.js';
6
6
import ValidateSchema from '../../../src/validators/ValidateSchema.js' ;
7
7
import { IssueDetail , LogEntry } from '../../../src/foundation.js' ;
8
8
9
- import { officialPlugins } from '../../../public/js/plugins.js' ;
10
-
11
- const plugins = officialPlugins
12
- . map ( plugin => ( {
13
- ...plugin ,
14
- default : false ,
15
- installed : false ,
16
- official : true ,
17
- } ) )
18
- . concat ( [
19
- {
20
- name : 'Substation' ,
21
- src : '/src/editors/Substation.ts' ,
22
- icon : 'margin' ,
23
- default : true ,
24
- kind : 'editor' ,
25
- installed : true ,
26
- official : false ,
27
- } ,
28
- ] ) ;
29
-
30
9
describe ( 'ValidateSchema plugin' , ( ) => {
31
10
if ( customElements . get ( '' ) === undefined )
32
11
customElements . define ( 'validate-schema' , ValidateSchema ) ;
@@ -37,89 +16,85 @@ describe('ValidateSchema plugin', () => {
37
16
let valid2007B4 : XMLDocument ;
38
17
let invalid2007B : XMLDocument ;
39
18
19
+ before ( async ( ) => {
20
+ parent = await fixture ( html `
21
+ < mock-editor-logger
22
+ > < validate-schema > </ validate-schema
23
+ > </ mock-editor-logger >
24
+ ` ) ;
25
+
26
+ element = < ValidateSchema > parent . querySelector ( 'validate-schema' ) ! ;
27
+ element . pluginId = '/src/validators/ValidateSchema.js' ;
28
+ await element . updateComplete ;
29
+ } ) ;
30
+
40
31
describe ( 'for valid SCL files' , ( ) => {
41
- beforeEach ( async ( ) => {
32
+ before ( async ( ) => {
42
33
valid2007B4 = await fetch ( '/test/testfiles/valid2007B.scd' )
43
34
. then ( response => response . text ( ) )
44
35
. then ( str => new DOMParser ( ) . parseFromString ( str , 'application/xml' ) ) ;
45
36
46
- localStorage . setItem ( 'plugins' , JSON . stringify ( plugins ) ) ;
47
-
48
- parent = await fixture ( html `
49
- < mock-editor-logger
50
- > < validate-schema
51
- .doc =${ valid2007B4 }
52
- .docName =${ 'valid2007B4' }
53
- > </ validate-schema
54
- > </ mock-editor-logger >
55
- ` ) ;
56
- element = < ValidateSchema > parent . querySelector ( 'validate-schema' ) ! ;
57
- element . pluginId = '/src/validators/ValidateSchema.js' ;
58
- await element . requestUpdate ( ) ;
37
+ element . doc = valid2007B4 ;
38
+ element . docName = 'valid2007B' ;
59
39
} ) ;
60
40
61
- it ( 'zeroissues indication looks like the latest snapshot' , async ( ) => {
62
- await parent . requestUpdate ( ) ;
63
- await expect ( parent . diagnosticUI ) . to . equalSnapshot ( ) ;
64
- } ) ;
41
+ beforeEach ( async ( ) => {
42
+ parent . diagnoses . clear ( ) ;
43
+ await parent . updateComplete ;
65
44
66
- it ( 'indicates successful schema validation in the diagnoses pane' , async ( ) => {
67
45
await element . validate ( ) ;
46
+ await parent . updateComplete ;
47
+ } ) ;
68
48
49
+ it ( 'zeroissues indication looks like the latest snapshot' , async ( ) =>
50
+ await expect ( parent . diagnosticUI ) . to . equalSnapshot ( ) ) ;
51
+
52
+ it ( 'indicates successful schema validation in the diagnoses pane' , async ( ) => {
69
53
const lastEntry = < IssueDetail [ ] > (
70
54
parent . diagnoses . get ( '/src/validators/ValidateSchema.js' )
71
55
) ;
72
56
expect ( lastEntry . length ) . to . equal ( 1 ) ;
73
57
expect ( lastEntry [ 0 ] . title ) . to . contain ( '[validator.schema.valid]' ) ;
74
- } ) . timeout ( 15000 ) ;
58
+ } ) ;
75
59
76
60
it ( 'indicates successful schema validation in the log' , async ( ) => {
77
- await element . validate ( ) ;
78
61
const lastEntry = < LogEntry > parent . history . pop ( ) ;
79
62
expect ( lastEntry . kind ) . to . equal ( 'info' ) ;
80
63
expect ( lastEntry . title ) . to . contain ( '[validator.schema.valid]' ) ;
81
- } ) . timeout ( 15000 ) ;
64
+ } ) ;
82
65
} ) ;
83
66
84
67
describe ( 'for invalid SCL files' , ( ) => {
85
- beforeEach ( async ( ) => {
68
+ before ( async ( ) => {
86
69
invalid2007B = await fetch ( '/test/testfiles/invalid2007B.scd' )
87
70
. then ( response => response . text ( ) )
88
71
. then ( str => new DOMParser ( ) . parseFromString ( str , 'application/xml' ) ) ;
89
72
90
- parent = await fixture ( html `
91
- < mock-editor-logger
92
- > < validate-schema
93
- .doc =${ invalid2007B }
94
- .docName =${ 'invalid2007B' }
95
- > </ validate-schema
96
- > </ mock-editor-logger >
97
- ` ) ;
98
-
99
- element = < ValidateSchema > parent . querySelector ( 'validate-schema' ) ! ;
100
- element . pluginId = '/src/validators/ValidateSchema.js' ;
101
- await element . requestUpdate ( ) ;
73
+ element . doc = invalid2007B ;
74
+ element . docName = 'invalid2007B' ;
102
75
103
- try {
104
- await element . validate ( ) ;
105
- } catch ( e ) {
106
- e ;
107
- }
76
+ await element . requestUpdate ( ) ;
108
77
} ) ;
109
- it ( 'create issues in diagnose' , async ( ) => {
110
- const issues = parent . diagnoses . get ( '/src/validators/ValidateSchema.js' ) ;
111
- expect ( issues ) . to . not . be . undefined ;
112
- } ) . timeout ( 15000 ) ;
113
-
114
- it ( 'pushes issues to the diagnostics pane that look like the latest snapshot' , async ( ) => {
115
- await parent . requestUpdate ( ) ;
116
- await expect ( parent . diagnosticUI ) . to . equalSnapshot ( ) ;
78
+
79
+ beforeEach ( async ( ) => {
80
+ parent . diagnoses . clear ( ) ;
81
+ await parent . updateComplete ;
82
+
83
+ await element . validate ( ) ;
84
+ await parent . updateComplete ;
117
85
} ) ;
118
86
87
+ it ( 'pushes issues to the diagnostics pane that look like the latest snapshot' , async ( ) =>
88
+ await expect ( parent . diagnosticUI ) . to . equalSnapshot ( ) ) ;
89
+
90
+ it ( 'create issues in diagnose' , async ( ) =>
91
+ expect ( parent . diagnoses . get ( '/src/validators/ValidateSchema.js' ) ) . to . not
92
+ . be . undefined ) ;
93
+
119
94
it ( 'generates error messages in the log' , async ( ) => {
120
- const lastEntry = < LogEntry > parent . history . pop ( ) ;
121
- expect ( lastEntry . kind ) . to . equal ( 'warning' ) ;
122
- expect ( lastEntry . title ) . to . contain ( '[validator.schema.invalid]' ) ;
123
- } ) . timeout ( 5000 ) ;
95
+ const lastLogEntry = < LogEntry > parent . history . pop ( ) ;
96
+ expect ( lastLogEntry . kind ) . to . equal ( 'warning' ) ;
97
+ expect ( lastLogEntry . title ) . to . contain ( '[validator.schema.invalid]' ) ;
98
+ } ) ;
124
99
} ) ;
125
100
} ) ;
0 commit comments