/
reference-loot-template.integration.spec.ts
286 lines (251 loc) · 12.6 KB
/
reference-loot-template.integration.spec.ts
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import { async, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { of } from 'rxjs';
import { ReferenceLootTemplateComponent } from './reference-loot-template.component';
import { ReferenceLootTemplateModule } from './reference-loot-template.module';
import { MysqlQueryService } from '@keira-shared/services/mysql-query.service';
import { ReferenceLootTemplate } from '@keira-types/reference-loot-template.type';
import { MultiRowEditorPageObject } from '@keira-testing/multi-row-editor-page-object';
import { ReferenceLootHandlerService } from './reference-loot-handler.service';
class ReferenceLootTemplatePage extends MultiRowEditorPageObject<ReferenceLootTemplateComponent> {}
describe('ReferenceLootTemplate integration tests', () => {
const id = 1234;
const originalRow0 = new ReferenceLootTemplate();
const originalRow1 = new ReferenceLootTemplate();
const originalRow2 = new ReferenceLootTemplate();
originalRow0.Entry = originalRow1.Entry = originalRow2.Entry = id;
originalRow0.Item = 0;
originalRow1.Item = 1;
originalRow2.Item = 2;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ReferenceLootTemplateModule,
RouterTestingModule,
],
providers: [
ReferenceLootHandlerService,
]
})
.compileComponents();
}));
function setup(creatingNew: boolean) {
const handlerService = TestBed.inject(ReferenceLootHandlerService);
handlerService['_selected'] = `${id}`;
handlerService.isNew = creatingNew;
const queryService = TestBed.inject(MysqlQueryService);
const querySpy = spyOn(queryService, 'query').and.returnValue(of());
spyOn(queryService, 'queryValue').and.returnValue(of());
spyOn(queryService, 'selectAll').and.returnValue(of(
creatingNew ? [] : [originalRow0, originalRow1, originalRow2]
));
const fixture = TestBed.createComponent(ReferenceLootTemplateComponent);
const page = new ReferenceLootTemplatePage(fixture);
fixture.autoDetectChanges(true);
fixture.detectChanges();
return { page, querySpy, handlerService };
}
describe('Creating new', () => {
it('should correctly initialise', () => {
const { page } = setup(true);
page.expectDiffQueryToBeEmpty();
page.expectFullQueryToBeEmpty();
expect(page.formError.hidden).toBe(true);
expect(page.addNewRowBtn.disabled).toBe(false);
expect(page.deleteSelectedRowBtn.disabled).toBe(true);
expect(page.getInputById('Item').disabled).toBe(true);
expect(page.getInputById('Reference').disabled).toBe(true);
expect(page.getInputById('Chance').disabled).toBe(true);
expect(page.getInputById('QuestRequired').disabled).toBe(true);
expect(page.getInputById('LootMode').disabled).toBe(true);
expect(page.getInputById('GroupId').disabled).toBe(true);
expect(page.getInputById('MinCount').disabled).toBe(true);
expect(page.getInputById('MaxCount').disabled).toBe(true);
expect(page.getInputById('Comment').disabled).toBe(true);
expect(page.getEditorTableRowsCount()).toBe(0);
});
it('should correctly update the unsaved status', () => {
const { page, handlerService } = setup(true);
expect(handlerService.isUnsaved).toBe(false);
page.addNewRow();
expect(handlerService.isUnsaved).toBe(true);
page.deleteRow();
expect(handlerService.isUnsaved).toBe(false);
});
it('adding new rows and executing the query should correctly work', () => {
const { page, querySpy } = setup(true);
const expectedQuery = 'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234) AND (`Item` IN (0, 1, 2));\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, `GroupId`, ' +
'`MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 0, 0, 100, 0, 1, 0, 1, 1, \'\'),\n' +
'(1234, 1, 0, 100, 0, 1, 0, 1, 1, \'\'),\n' +
'(1234, 2, 0, 100, 0, 1, 0, 1, 1, \'\');';
querySpy.calls.reset();
page.addNewRow();
expect(page.getEditorTableRowsCount()).toBe(1);
page.addNewRow();
expect(page.getEditorTableRowsCount()).toBe(2);
page.addNewRow();
expect(page.getEditorTableRowsCount()).toBe(3);
page.clickExecuteQuery();
page.expectDiffQueryToContain(expectedQuery);
expect(querySpy).toHaveBeenCalledTimes(1);
expect(querySpy.calls.mostRecent().args[0]).toContain(expectedQuery);
});
it('adding a row and changing its values should correctly update the queries', () => {
const { page } = setup(true);
page.addNewRow();
page.expectDiffQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234) AND (`Item` IN (0));\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, ' +
'`GroupId`, `MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 0, 0, 100, 0, 1, 0, 1, 1, \'\');'
);
page.expectFullQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234);\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, ' +
'`GroupId`, `MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 0, 0, 100, 0, 1, 0, 1, 1, \'\');'
);
page.setInputValueById('Chance', '1');
page.expectDiffQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234) AND (`Item` IN (0));\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, ' +
'`GroupId`, `MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 0, 0, 1, 0, 1, 0, 1, 1, \'\');'
);
page.expectFullQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234);\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, ' +
'`GroupId`, `MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 0, 0, 1, 0, 1, 0, 1, 1, \'\');'
);
page.setInputValueById('QuestRequired', '2');
page.expectDiffQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234) AND (`Item` IN (0));\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, ' +
'`GroupId`, `MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 0, 0, 1, 2, 1, 0, 1, 1, \'\');'
);
page.expectFullQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234);\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, ' +
'`GroupId`, `MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 0, 0, 1, 2, 1, 0, 1, 1, \'\');'
);
page.setInputValueById('Item', '123');
page.expectDiffQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234) AND (`Item` IN (123));\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, ' +
'`GroupId`, `MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 123, 0, 1, 2, 1, 0, 1, 1, \'\');'
);
page.expectFullQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234);\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, ' +
'`GroupId`, `MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 123, 0, 1, 2, 1, 0, 1, 1, \'\');'
);
});
});
describe('Editing existing', () => {
it('should correctly initialise', () => {
const { page } = setup(false);
expect(page.formError.hidden).toBe(true);
page.expectDiffQueryToBeShown();
page.expectDiffQueryToBeEmpty();
page.expectFullQueryToContain('' +
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234);\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, ' +
'`GroupId`, `MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 0, 0, 100, 0, 1, 0, 1, 1, \'\'),\n' +
'(1234, 1, 0, 100, 0, 1, 0, 1, 1, \'\'),\n' +
'(1234, 2, 0, 100, 0, 1, 0, 1, 1, \'\');');
expect(page.getEditorTableRowsCount()).toBe(3);
});
it('deleting rows should correctly work', () => {
const { page } = setup(false);
page.deleteRow(1);
expect(page.getEditorTableRowsCount()).toBe(2);
page.expectDiffQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234) AND (`Item` IN (1));'
);
page.expectFullQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234);\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, `GroupId`, ' +
'`MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 0, 0, 100, 0, 1, 0, 1, 1, \'\'),\n' +
'(1234, 2, 0, 100, 0, 1, 0, 1, 1, \'\');'
);
page.deleteRow(1);
expect(page.getEditorTableRowsCount()).toBe(1);
page.expectDiffQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234) AND (`Item` IN (1, 2));'
);
page.expectFullQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234);\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, `GroupId`, ' +
'`MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 0, 0, 100, 0, 1, 0, 1, 1, \'\');'
);
page.deleteRow(0);
expect(page.getEditorTableRowsCount()).toBe(0);
page.expectDiffQueryToContain(
'DELETE FROM `reference_loot_template` WHERE `Entry` = 1234;'
);
page.expectFullQueryToBeEmpty();
});
it('editing existing rows should correctly work', () => {
const { page } = setup(false);
page.clickRowOfDatatable(1);
page.setInputValueById('LootMode', 1);
page.clickRowOfDatatable(2);
page.setInputValueById('GroupId', 2);
page.expectDiffQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234) AND (`Item` IN (2));\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, `GroupId`, ' +
'`MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 2, 0, 100, 0, 1, 2, 1, 1, \'\');'
);
page.expectFullQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234);\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, `GroupId`, ' +
'`MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 0, 0, 100, 0, 1, 0, 1, 1, \'\'),\n' +
'(1234, 1, 0, 100, 0, 1, 0, 1, 1, \'\'),\n' +
'(1234, 2, 0, 100, 0, 1, 2, 1, 1, \'\');'
);
});
it('combining add, edit and delete should correctly work', () => {
const { page } = setup(false);
page.addNewRow();
expect(page.getEditorTableRowsCount()).toBe(4);
page.clickRowOfDatatable(1);
page.setInputValueById('Chance', 10);
expect(page.getEditorTableRowsCount()).toBe(4);
page.deleteRow(2);
expect(page.getEditorTableRowsCount()).toBe(3);
page.expectDiffQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234) AND (`Item` IN (1, 2, 3));\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, `GroupId`, ' +
'`MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 1, 0, 10, 0, 1, 0, 1, 1, \'\'),\n' +
'(1234, 3, 0, 100, 0, 1, 0, 1, 1, \'\');'
);
page.expectFullQueryToContain(
'DELETE FROM `reference_loot_template` WHERE (`Entry` = 1234);\n' +
'INSERT INTO `reference_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, `GroupId`, ' +
'`MinCount`, `MaxCount`, `Comment`) VALUES\n' +
'(1234, 0, 0, 100, 0, 1, 0, 1, 1, \'\'),\n' +
'(1234, 1, 0, 10, 0, 1, 0, 1, 1, \'\'),\n' +
'(1234, 3, 0, 100, 0, 1, 0, 1, 1, \'\');'
);
});
it('using the same row id for multiple rows should correctly show an error', () => {
const { page } = setup(false);
page.clickRowOfDatatable(2);
page.setInputValueById('Item', 0);
page.expectUniqueError();
});
});
});