@@ -20,15 +20,18 @@ class DashboardComponentPage extends PageObject<DashboardComponent> {
20
20
get dbVersion ( ) : HTMLTableCellElement {
21
21
return this . query < HTMLTableCellElement > ( '#db-version' ) ;
22
22
}
23
- get dbWorldVersion ( ) : HTMLTableCellElement {
24
- return this . query < HTMLTableCellElement > ( '#db-world-version' ) ;
25
- }
26
- get dbWarning ( ) : HTMLDivElement {
27
- return this . query < HTMLDivElement > ( '#database-warning' , false ) ;
23
+ // get dbWorldVersion(): HTMLTableCellElement {
24
+ // return this.query<HTMLTableCellElement>('#db-world-version');
25
+ // }
26
+ dbWarning ( assert = true ) : HTMLDivElement {
27
+ return this . query < HTMLDivElement > ( '#database-warning' , assert ) ;
28
28
}
29
29
get commitHashUrl ( ) : HTMLAnchorElement {
30
30
return this . query < HTMLAnchorElement > ( '#commit-hash-url' ) ;
31
31
}
32
+ get reloadBtn ( ) : HTMLButtonElement {
33
+ return this . query < HTMLButtonElement > ( '#reload-btn' ) ;
34
+ }
32
35
}
33
36
34
37
describe ( 'DashboardComponent' , ( ) => {
@@ -38,6 +41,12 @@ describe('DashboardComponent', () => {
38
41
db_version : 'ACDB 335.3 (dev)' ,
39
42
cache_id : 3 ,
40
43
} ;
44
+ const wrongVersionRow : VersionRow = {
45
+ core_version : 'ShinCore rev. 2bcedc2859e7 2019-02-17 10:04:09 +0100 (master branch) (Unix, Debug)' ,
46
+ core_revision : '2bcedc2859e7' ,
47
+ db_version : 'SHINDB 335.3 (dev)' ,
48
+ cache_id : 3 ,
49
+ } ;
41
50
const worldDbVersion = '2019_02_17_02' ;
42
51
const versionDbRow : VersionDbRow = {
43
52
sql_rev : 123 ,
@@ -66,20 +75,19 @@ describe('DashboardComponent', () => {
66
75
} ;
67
76
68
77
it ( 'should correctly display the versions' , ( ) => {
69
- const { fixture , page, component } = setup ( ) ;
70
- fixture . detectChanges ( ) ;
78
+ const { page } = setup ( ) ;
79
+ page . detectChanges ( ) ;
71
80
72
81
expect ( page . coreVersion . innerHTML ) . toContain ( versionRow . core_version ) ;
73
82
expect ( page . coreRevision . innerHTML ) . toContain ( versionRow . core_revision ) ;
74
83
expect ( page . dbVersion . innerHTML ) . toContain ( versionRow . db_version ) ;
75
84
expect ( page . commitHashUrl . href ) . toEqual ( `https://github.com/azerothcore/azerothcore-wotlk/commit/${ versionRow . core_revision } ` ) ;
76
85
// expect(page.dbWorldVersion.innerHTML).toContain(worldDbVersion);
77
- expect ( page . dbWarning ) . toBe ( null ) ;
78
- expect ( component . error ) . toBe ( false ) ;
86
+ expect ( page . dbWarning ( false ) ) . toBeFalsy ( ) ;
79
87
} ) ;
80
88
81
89
it ( 'if the revision hash ends with a "+", it should be stripped in the url' , ( ) => {
82
- const { fixture , page } = setup ( ) ;
90
+ const { page } = setup ( ) ;
83
91
when ( MockedMysqlQueryService . query ( 'SELECT * FROM version' ) ) . thenReturn (
84
92
of ( [
85
93
{
@@ -89,50 +97,78 @@ describe('DashboardComponent', () => {
89
97
] ) ,
90
98
) ;
91
99
92
- fixture . detectChanges ( ) ;
100
+ page . detectChanges ( ) ;
93
101
94
102
expect ( page . commitHashUrl . href ) . toEqual ( `https://github.com/azerothcore/azerothcore-wotlk/commit/${ versionRow . core_revision } ` ) ;
95
103
} ) ;
96
104
105
+ describe ( 'refresh button' , ( ) => {
106
+ it ( 'when the refresh button is clicked, it should correctly reload the data' , ( ) => {
107
+ const { page } = setup ( ) ;
108
+ page . detectChanges ( ) ;
109
+ expect ( page . coreVersion . innerHTML ) . toContain ( versionRow . core_version ) ;
110
+
111
+ const newVersion = 'A new fantastic AzerothCore version!' ;
112
+ when ( MockedMysqlQueryService . query ( 'SELECT * FROM version' ) ) . thenReturn (
113
+ of ( [
114
+ {
115
+ ...versionRow ,
116
+ core_version : newVersion ,
117
+ } ,
118
+ ] ) ,
119
+ ) ;
120
+ page . reloadBtn . click ( ) ;
121
+ page . detectChanges ( ) ;
122
+
123
+ expect ( page . coreVersion . innerHTML ) . not . toContain ( versionRow . core_version ) ;
124
+ expect ( page . coreVersion . innerHTML ) . toContain ( newVersion ) ;
125
+ } ) ;
126
+
127
+ it ( 'when clicked after an error, it should clear the error out' , ( ) => {
128
+ const { page } = setup ( ) ;
129
+
130
+ when ( MockedMysqlQueryService . query ( anyString ( ) ) ) . thenReturn ( of ( [ wrongVersionRow ] ) ) ;
131
+ page . detectChanges ( ) ;
132
+ expect ( page . dbWarning ( ) ) . toBeDefined ( ) ;
133
+
134
+ when ( MockedMysqlQueryService . query ( anyString ( ) ) ) . thenReturn ( of ( [ versionRow ] ) ) ;
135
+ page . reloadBtn . click ( ) ;
136
+ page . detectChanges ( ) ;
137
+
138
+ expect ( page . dbWarning ( false ) ) . toBeFalsy ( ) ;
139
+ } ) ;
140
+ } ) ;
141
+
97
142
it ( 'should correctly give error if the query does not return the data in the expected format' , ( ) => {
98
- const { fixture , page, component } = setup ( ) ;
143
+ const { page } = setup ( ) ;
99
144
when ( MockedMysqlQueryService . query ( anyString ( ) ) ) . thenReturn ( of ( [ ] ) ) ;
100
145
const errorSpy = spyOn ( console , 'error' ) ;
101
146
102
- fixture . detectChanges ( ) ;
147
+ page . detectChanges ( ) ;
103
148
104
149
expect ( errorSpy ) . toHaveBeenCalledTimes ( 1 ) ;
105
- expect ( page . dbWarning ) . toBe ( null ) ;
106
- expect ( component . error ) . toBe ( false ) ;
150
+ expect ( page . dbWarning ( false ) ) . toBeFalsy ( ) ;
107
151
} ) ;
108
152
109
153
it ( 'should correctly give error if the query returns an error' , ( ) => {
110
- const { fixture , page, component } = setup ( ) ;
154
+ const { page } = setup ( ) ;
111
155
const error = 'some error' ;
112
156
when ( MockedMysqlQueryService . query ( anyString ( ) ) ) . thenReturn ( throwError ( error ) ) ;
113
157
const errorSpy = spyOn ( console , 'error' ) ;
114
158
115
- fixture . detectChanges ( ) ;
159
+ page . detectChanges ( ) ;
116
160
117
161
expect ( errorSpy ) . toHaveBeenCalledTimes ( 1 ) ;
118
162
expect ( errorSpy ) . toHaveBeenCalledWith ( error ) ;
119
- expect ( page . dbWarning ) . toBeDefined ( ) ;
120
- expect ( component . error ) . toBe ( true ) ;
163
+ expect ( page . dbWarning ( ) ) . toBeDefined ( ) ;
121
164
} ) ;
122
165
123
166
it ( 'should correctly give error if the query returns an error' , ( ) => {
124
- const { fixture, page, component } = setup ( ) ;
125
- const wrongVersionRow : VersionRow = {
126
- core_version : 'ShinCore rev. 2bcedc2859e7 2019-02-17 10:04:09 +0100 (master branch) (Unix, Debug)' ,
127
- core_revision : '2bcedc2859e7' ,
128
- db_version : 'SHINDB 335.3 (dev)' ,
129
- cache_id : 3 ,
130
- } ;
167
+ const { page } = setup ( ) ;
131
168
when ( MockedMysqlQueryService . query ( anyString ( ) ) ) . thenReturn ( of ( [ wrongVersionRow ] ) ) ;
132
169
133
- fixture . detectChanges ( ) ;
170
+ page . detectChanges ( ) ;
134
171
135
- expect ( page . dbWarning ) . toBeDefined ( ) ;
136
- expect ( component . error ) . toBe ( true ) ;
172
+ expect ( page . dbWarning ( ) ) . toBeDefined ( ) ;
137
173
} ) ;
138
174
} ) ;
0 commit comments