-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathAdvancedSearch.spec.ts
More file actions
632 lines (563 loc) · 19.8 KB
/
AdvancedSearch.spec.ts
File metadata and controls
632 lines (563 loc) · 19.8 KB
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/*
* Copyright 2024 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { expect } from '@playwright/test';
import { EntityStatus } from '../../../src/generated/entity/data/searchIndex';
import { COMMON_TIER_TAG } from '../../constant/common';
import { SidebarItem } from '../../constant/sidebar';
import { DataProduct } from '../../support/domain/DataProduct';
import { EntityDataClass } from '../../support/entity/EntityDataClass';
import { MlModelClass } from '../../support/entity/MlModelClass';
import { TableClass } from '../../support/entity/TableClass';
import { TopicClass } from '../../support/entity/TopicClass';
import { Glossary } from '../../support/glossary/Glossary';
import { GlossaryTerm } from '../../support/glossary/GlossaryTerm';
import { UserClass } from '../../support/user/UserClass';
import { performAdminLogin } from '../../utils/admin';
import {
FIELDS,
fillRule,
fillStaticListRule,
OPERATOR,
runRuleGroupTests,
runRuleGroupTestsWithNonExistingValue,
selectOption,
showAdvancedSearchDialog,
verifyAllConditions,
} from '../../utils/advancedSearch';
import { redirectToHomePage } from '../../utils/common';
import { waitForAllLoadersToDisappear } from '../../utils/entity';
import { sidebarClick } from '../../utils/sidebar';
import { test } from '../fixtures/pages';
let user: UserClass;
let table: TableClass;
let glossaryEntity: Glossary;
let table1: TableClass;
let table2: TableClass;
let topic1: TopicClass;
let topic2: TopicClass;
test.describe('Advanced Search', { tag: ['@advanced-search'] }, () => {
let searchCriteria: Record<string, Array<string>> = {};
test.beforeAll('Setup pre-requests', async ({ browser }) => {
test.slow(true);
user = new UserClass();
table = new TableClass(undefined, 'Regular');
table1 = new TableClass();
table2 = new TableClass();
topic1 = new TopicClass();
topic2 = new TopicClass();
const { apiContext, afterAction } = await performAdminLogin(browser);
await user.create(apiContext);
await Promise.allSettled([
table1.create(apiContext),
table2.create(apiContext),
topic1.create(apiContext),
topic2.create(apiContext),
]);
glossaryEntity = new Glossary(undefined, [
{
id: user.responseData.id,
type: 'user',
name: user.responseData.name,
displayName: user.responseData.displayName,
},
]);
const glossaryTermEntity = new GlossaryTerm(glossaryEntity);
await glossaryEntity.create(apiContext);
await glossaryTermEntity.create(apiContext);
await table.create(apiContext);
// Add Owner & Tag and domain to the table
await table1.patch({
apiContext,
patchData: [
{
op: 'add',
value: {
type: 'user',
id: EntityDataClass.user1.responseData.id,
},
path: '/owners/0',
},
{
op: 'add',
value: {
tagFQN: 'PersonalData.Personal',
},
path: '/tags/0',
},
{
op: 'add',
path: '/domains/0',
value: {
id: EntityDataClass.domain1.responseData.id,
type: 'domain',
name: EntityDataClass.domain1.responseData.name,
displayName: EntityDataClass.domain1.responseData.displayName,
},
},
],
});
// Add data product to the table 1
await table1.patch({
apiContext,
patchData: [
{
op: 'add',
path: '/dataProducts/0',
value: {
id: EntityDataClass.dataProduct1.responseData.id,
type: 'dataProduct',
name: EntityDataClass.dataProduct1.responseData.name,
displayName: EntityDataClass.dataProduct1.responseData.displayName,
},
},
],
});
await table2.patch({
apiContext,
patchData: [
{
op: 'add',
value: {
type: 'user',
id: EntityDataClass.user2.responseData.id,
},
path: '/owners/0',
},
{
op: 'add',
value: {
tagFQN: 'PII.None',
},
path: '/tags/0',
},
{
op: 'add',
path: '/domains/0',
value: {
id: EntityDataClass.domain2.responseData.id,
type: 'domain',
name: EntityDataClass.domain2.responseData.name,
displayName: EntityDataClass.domain2.responseData.displayName,
},
},
],
});
// Add data product to the table 2
await table2.patch({
apiContext,
patchData: [
{
op: 'add',
path: '/dataProducts/0',
value: {
id: EntityDataClass.dataProduct3.responseData.id,
type: 'dataProduct',
name: EntityDataClass.dataProduct3.responseData.name,
displayName: EntityDataClass.dataProduct3.responseData.displayName,
},
},
],
});
// Add Tier To the topic 1
await topic1.patch({
apiContext,
patchData: [
{
op: 'add',
path: '/tags/0',
value: {
name: COMMON_TIER_TAG[0].name,
tagFQN: COMMON_TIER_TAG[0].fullyQualifiedName,
labelType: 'Manual',
state: 'Confirmed',
},
},
],
});
// Add Tier To the topic 2
await topic2.patch({
apiContext,
patchData: [
{
op: 'add',
path: '/tags/0',
value: {
name: COMMON_TIER_TAG[1].name,
tagFQN: COMMON_TIER_TAG[1].fullyQualifiedName,
labelType: 'Manual',
state: 'Confirmed',
},
},
],
});
// Update Search Criteria here
searchCriteria = {
ownerDisplayName: [
EntityDataClass.user1.getUserDisplayName(),
EntityDataClass.user2.getUserDisplayName(),
],
'tags.tagFQN': ['PersonalData.Personal', 'PII.None'],
'tier.tagFQN': [
COMMON_TIER_TAG[0].fullyQualifiedName,
COMMON_TIER_TAG[1].fullyQualifiedName,
],
'service.displayName.keyword': [
table1.serviceResponseData.name,
table2.serviceResponseData.name,
],
'database.displayName.keyword': [
table1.databaseResponseData.name,
table2.databaseResponseData.name,
],
'databaseSchema.displayName.keyword': [
table1.schemaResponseData.name,
table2.schemaResponseData.name,
],
'columns.name.keyword': [
table1.entityResponseData.columns[2].name,
table2.entityResponseData.columns[3].name,
],
'displayName.keyword': [
table1.entityResponseData.displayName ?? '',
table2.entityResponseData.displayName ?? '',
],
serviceType: [
table1.serviceResponseData.serviceType ?? '',
topic1.serviceResponseData.serviceType ?? '',
],
'messageSchema.schemaFields.name.keyword': [
topic1.entityResponseData?.messageSchema?.schemaFields?.[0].name ?? '',
topic2.entityResponseData?.messageSchema?.schemaFields?.[1].name ?? '',
],
'dataModel.columns.name.keyword': [
EntityDataClass.container1.entityResponseData?.dataModel?.columns?.[0]
.name ?? '',
EntityDataClass.container2.entityResponseData?.dataModel?.columns?.[1]
.name ?? '',
],
dataModelType: [
EntityDataClass.dashboard1.dataModelResponseData.dataModelType ?? '',
EntityDataClass.dashboard2.dataModelResponseData.dataModelType ?? '',
],
'fields.name.keyword': [
EntityDataClass.searchIndex1.entityResponseData?.fields?.[1].name ?? '',
EntityDataClass.searchIndex2.entityResponseData?.fields?.[3].name ?? '',
],
'tasks.displayName.keyword': [
EntityDataClass.pipeline1.entityResponseData?.tasks?.[0]?.displayName ??
'',
EntityDataClass.pipeline2.entityResponseData?.tasks?.[1]?.displayName ??
'',
],
'domains.displayName.keyword': [
EntityDataClass.domain1.responseData.displayName,
EntityDataClass.domain2.responseData.displayName,
],
'responseSchema.schemaFields.name.keyword': [
EntityDataClass.apiCollection1.apiEndpointResponseData.responseSchema
?.schemaFields[0].name ?? '',
EntityDataClass.apiCollection2.apiEndpointResponseData.responseSchema
?.schemaFields[1].name ?? '',
],
'requestSchema.schemaFields.name.keyword': [
EntityDataClass.apiCollection1.apiEndpointResponseData.requestSchema
?.schemaFields[0].name ?? '',
EntityDataClass.apiCollection2.apiEndpointResponseData.requestSchema
?.schemaFields[1].name ?? '',
],
'name.keyword': [
table1.entityResponseData.name,
table2.entityResponseData.name,
],
'project.keyword': [
EntityDataClass.dashboardDataModel1.entityResponseData.project || '',
EntityDataClass.dashboardDataModel2.entityResponseData.project || '',
],
'charts.displayName.keyword': [
EntityDataClass.dashboard1.chartsResponseData.displayName,
EntityDataClass.dashboard2.chartsResponseData.displayName,
],
'dataProducts.displayName.keyword': [
EntityDataClass.dataProduct1.responseData.displayName,
EntityDataClass.dataProduct3.responseData.displayName,
],
};
await afterAction();
});
test.beforeEach(async ({ page }) => {
await redirectToHomePage(page);
await sidebarClick(page, SidebarItem.EXPLORE);
});
FIELDS.forEach((field) => {
test(`Verify All conditions for ${field.id} field`, async ({ page }) => {
test.slow(true);
await verifyAllConditions(page, field, searchCriteria[field.name][0]);
});
});
Object.values(OPERATOR).forEach(({ name: operator }) => {
FIELDS.forEach((field) => {
// Rule based search
test(`Verify Rule functionality for field ${field.id} with ${operator} operator`, async ({
page,
}) => {
test.slow(true);
await runRuleGroupTests(page, field, operator, false, searchCriteria);
});
// Group based search
test(`Verify Group functionality for field ${field.id} with ${operator} operator`, async ({
page,
}) => {
test.slow(true);
await runRuleGroupTests(page, field, operator, true, searchCriteria);
});
});
});
test('Verify search with non existing value do not result in infinite search', async ({
page,
}) => {
test.slow(true);
await runRuleGroupTestsWithNonExistingValue(page);
});
});
const ENTITY_STATUSES = Object.values(EntityStatus);
test.describe(
'Advanced Search - Entity Status Filter',
{ tag: ['@advanced-search', '@Discovery'] },
() => {
// One distinct entity type per status to prove the filter works across entity types
const glossaryForStatus = new Glossary();
const glossaryTermApproved = new GlossaryTerm(glossaryForStatus);
const mlModelDraft = new MlModelClass();
const dataProductInReview = new DataProduct();
type StatusEntry = {
status: EntityStatus;
endpoint: string;
id: () => string;
displayName: () => string;
fqn: () => string;
};
let statusEntries: StatusEntry[];
test.beforeAll(
'Create mixed entity types with distinct entity statuses',
async ({ browser }) => {
const { apiContext, afterAction } = await performAdminLogin(browser);
await glossaryForStatus.create(apiContext);
await Promise.all([
glossaryTermApproved.create(apiContext),
mlModelDraft.create(apiContext),
dataProductInReview.create(apiContext),
]);
statusEntries = [
{
status: EntityStatus.Approved,
endpoint: 'glossaryTerms',
id: () => glossaryTermApproved.responseData.id,
displayName: () => glossaryTermApproved.data.displayName,
fqn: () => glossaryTermApproved.responseData.fullyQualifiedName,
},
{
status: EntityStatus.Draft,
endpoint: 'mlmodels',
id: () => mlModelDraft.entityResponseData.id,
displayName: () => mlModelDraft.entity.displayName,
fqn: () => mlModelDraft.entityResponseData.fullyQualifiedName,
},
{
status: EntityStatus.InReview,
endpoint: 'dataProducts',
id: () => dataProductInReview.responseData.id ?? '',
displayName: () => dataProductInReview.data.displayName,
fqn: () =>
dataProductInReview.responseData.fullyQualifiedName ?? '',
},
];
// Patch entityStatus on each entity
await Promise.all(
statusEntries.map(({ id, status, endpoint }) =>
apiContext.patch(`/api/v1/${endpoint}/${id()}`, {
data: [{ op: 'add', path: '/entityStatus', value: status }],
headers: { 'Content-Type': 'application/json-patch+json' },
})
)
);
await afterAction();
}
);
test.beforeEach(async ({ page }) => {
await redirectToHomePage(page);
await sidebarClick(page, SidebarItem.EXPLORE);
});
test('All entity status options are visible in the Status dropdown', async ({
page,
}) => {
test.slow();
await test.step('Open advanced search dialog', async () => {
await showAdvancedSearchDialog(page);
});
await test.step('Select Status field and == operator', async () => {
const ruleLocator = page.locator('.rule').nth(0);
await selectOption(
page,
ruleLocator.locator('.rule--field .ant-select'),
'Status',
true
);
await selectOption(
page,
ruleLocator.locator('.rule--operator .ant-select'),
'=='
);
});
await test.step('Open Status value dropdown and verify all hard-coded options appear', async () => {
const ruleLocator = page.locator('.rule').nth(0);
await ruleLocator.locator('.widget--widget > .ant-select').click();
const dropdown = page
.locator('.ant-select-dropdown')
.filter({ hasText: EntityStatus.Approved })
.last();
await expect(dropdown).toBeVisible();
for (const status of ENTITY_STATUSES) {
await expect(
dropdown
.locator('.ant-select-item-option')
.filter({ hasText: new RegExp(`^${status}$`, 'i') })
.first()
).toBeVisible();
}
});
});
test('Filtering by status "==" shows matching entity and hides others across entity types', async ({
page,
}) => {
test.slow();
for (const entry of statusEntries) {
const { status } = entry;
const matchedName = entry.displayName();
await test.step(`Apply Status == "${status}" AND Name == "${matchedName}"`, async () => {
await showAdvancedSearchDialog(page);
await fillStaticListRule(page, {
fieldLabel: 'Status',
condition: '==',
value: status,
ruleIndex: 1,
});
await page.getByTestId('advanced-search-add-rule').nth(1).click();
await fillRule(page, {
condition: '==',
field: { id: 'Display Name', name: 'displayName.keyword' },
searchCriteria: matchedName,
index: 2,
});
const searchRes = page.waitForResponse(
'/api/v1/search/query?*index=dataAsset*'
);
await page.getByTestId('apply-btn').click();
await searchRes;
await waitForAllLoadersToDisappear(page);
});
await test.step('Filter chip shows the applied status', async () => {
await expect(
page.getByTestId('advance-search-filter-container')
).toContainText(`'${status}'`);
});
await test.step(`"${matchedName}" (${entry.endpoint}) is visible`, async () => {
await expect(
page.getByTestId(`table-data-card_${entry.fqn()}`)
).toBeVisible();
});
await test.step('Entities with other statuses are not in results', async () => {
const otherEntries = statusEntries.filter((e) => e.status !== status);
for (const other of otherEntries) {
await expect(
page.getByTestId(`table-data-card_${other.fqn()}`)
).not.toBeVisible();
}
});
await page.getByTestId('clear-filters').click();
}
});
test('Filtering by status "!=" excludes matched entity but shows all other entity types', async ({
page,
}) => {
test.slow();
const targetEntry = statusEntries.find(
(e) => e.status === EntityStatus.Approved
)!;
const approvedName = targetEntry.displayName();
const otherEntries = statusEntries.filter(
(e) => e.status !== EntityStatus.Approved
);
await test.step('Apply Status != "Approved" AND Name == approved entity name', async () => {
await showAdvancedSearchDialog(page);
await fillStaticListRule(page, {
fieldLabel: 'Status',
condition: '!=',
value: EntityStatus.Approved,
ruleIndex: 1,
});
await page.getByTestId('advanced-search-add-rule').nth(1).click();
await fillRule(page, {
condition: '==',
field: { id: 'Display Name', name: 'displayName.keyword' },
searchCriteria: approvedName,
index: 2,
});
const searchRes = page.waitForResponse(
'/api/v1/search/query?*index=dataAsset*'
);
await page.getByTestId('apply-btn').click();
await searchRes;
await waitForAllLoadersToDisappear(page);
});
await test.step('Filter chip reflects the != condition', async () => {
await expect(
page.getByTestId('advance-search-filter-container')
).toContainText(`'${EntityStatus.Approved}'`);
});
await test.step('GlossaryTerm with Approved status is not visible', async () => {
await expect(
page.getByTestId(`table-data-card_${targetEntry.fqn()}`)
).not.toBeVisible();
});
await test.step('Draft and In Review entities appear when searched by their name and non-Approved status', async () => {
for (const entry of otherEntries) {
await page.getByTestId('clear-filters').click();
await showAdvancedSearchDialog(page);
await fillStaticListRule(page, {
fieldLabel: 'Status',
condition: '!=',
value: EntityStatus.Approved,
ruleIndex: 1,
});
await page.getByTestId('advanced-search-add-rule').nth(1).click();
await fillRule(page, {
condition: '==',
field: { id: 'Display Name', name: 'displayName.keyword' },
searchCriteria: entry.displayName(),
index: 2,
});
const searchRes = page.waitForResponse(
'/api/v1/search/query?*index=dataAsset*'
);
await page.getByTestId('apply-btn').click();
await searchRes;
await waitForAllLoadersToDisappear(page);
await expect(
page.getByTestId(`table-data-card_${entry.fqn()}`)
).toBeVisible();
}
});
await page.getByTestId('clear-filters').click();
});
}
);