Skip to content

Commit

Permalink
playwright: migrate glossary version page spec (#16671)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaileshParmar11 committed Jun 18, 2024
1 parent 57e51df commit 282327c
Show file tree
Hide file tree
Showing 9 changed files with 530 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
REVIEWER_DETAILS,
} from '../../constants/Version.constants';

describe(
// migrated to playwright
describe.skip(
'Glossary and glossary term version pages should work properly',
{ tags: 'Glossary' },
() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.
*/
export const GLOSSARY_PATCH_PAYLOAD = [
{
op: 'add',
path: '/tags/0',
value: {
labelType: 'Manual',
state: 'Confirmed',
source: 'Classification',
tagFQN: 'PersonalData.SpecialCategory',
},
},
{
op: 'add',
path: '/tags/1',
value: {
labelType: 'Manual',
state: 'Confirmed',
source: 'Classification',
tagFQN: 'PII.Sensitive',
},
},
{
op: 'replace',
path: '/description',
value: 'Description for newly added glossary',
},
];

export const GLOSSARY_TERM_PATCH_PAYLOAD = [
{
op: 'add',
path: '/synonyms/0',
value: 'test-synonym',
},
{
op: 'add',
path: '/references/0',
value: {
name: 'reference1',
endpoint: 'https://example.com',
},
},
{
op: 'add',
path: '/tags/0',
value: {
labelType: 'Manual',
state: 'Confirmed',
source: 'Classification',
tagFQN: 'PersonalData.SpecialCategory',
},
},
{
op: 'add',
path: '/tags/1',
value: {
labelType: 'Manual',
state: 'Confirmed',
source: 'Classification',
tagFQN: 'PII.Sensitive',
},
},
{
op: 'replace',
path: '/description',
value: 'Description for newly added glossaryTerm',
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { TableClass } from '../../support/entity/TableClass';
import { TopicClass } from '../../support/entity/TopicClass';
import {
createNewPage,
getApiContext,
getAuthContext,
getToken,
redirectToHomePage,
Expand Down Expand Up @@ -133,8 +134,7 @@ entities.forEach((EntityClass) => {
// increase timeout as it using single test for multiple steps
test.slow(true);

const token = await getToken(page);
const apiContext = await getAuthContext(token);
const { apiContext, afterAction } = await getApiContext(page);
await entity.prepareCustomProperty(apiContext);

await test.step(`Set ${titleText} Custom Property`, async () => {
Expand All @@ -158,6 +158,7 @@ entities.forEach((EntityClass) => {
});

await entity.cleanupCustomProperty(apiContext);
await afterAction();
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
/*
* 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 test, { expect } from '@playwright/test';
import { GLOSSARY_PATCH_PAYLOAD } from '../../constant/version';
import { EntityTypeEndpoint } from '../../support/entity/Entity.interface';
import { Glossary } from '../../support/glossary/Glossary';
import { UserClass } from '../../support/user/UserClass';
import {
createNewPage,
getApiContext,
redirectToHomePage,
} from '../../utils/common';
import { addOwner } from '../../utils/entity';
import { addMultiOwner, setupGlossaryAndTerms } from '../../utils/glossary';

// use the admin user to login
test.use({ storageState: 'playwright/.auth/admin.json' });

const user = new UserClass();
const reviewer = new UserClass();

test.beforeAll(async ({ browser }) => {
const { afterAction, apiContext } = await createNewPage(browser);
await user.create(apiContext);
await reviewer.create(apiContext);
await afterAction();
});

test.beforeEach(async ({ page }) => {
await redirectToHomePage(page);
});

test('Glossary', async ({ page }) => {
const glossary = new Glossary();
const { afterAction, apiContext } = await getApiContext(page);
await glossary.create(apiContext);
await glossary.patch(apiContext, GLOSSARY_PATCH_PAYLOAD);

await test.step('Version changes', async () => {
await glossary.visitPage(page);

await page.click('[data-testid="version-button"]');

await expect(
page
.getByTestId('asset-description-container')
.getByTestId('markdown-parser')
.locator('span')
.filter({ hasText: 'Description' })
).toBeVisible();

await expect(
page.locator(
'.diff-added [data-testid="tag-PersonalData.SpecialCategory"]'
)
).toBeVisible();

await expect(
page.locator('.diff-added [data-testid="tag-PII.Sensitive"]')
).toBeVisible();
});

await test.step('Should display the owner & reviewer changes', async () => {
await glossary.visitPage(page);

await expect(page.getByTestId('version-button')).toHaveText(/0.2/);

await addOwner(
page,
user.getUserName(),
'Users',
EntityTypeEndpoint.Glossary,
'glossary-right-panel-owner-link'
);

await page.reload();
const versionPageResponse = page.waitForResponse(
`/api/v1/glossaries/${glossary.responseData.id}/versions/0.2`
);
await page.click('[data-testid="version-button"]');
await versionPageResponse;

await expect(
page.locator(
'[data-testid="glossary-right-panel-owner-link"] [data-testid="diff-added"]'
)
).toBeVisible();

await page.click('[data-testid="version-button"]');
await versionPageResponse;

await addMultiOwner({
page,
ownerNames: [reviewer.getUserName()],
activatorBtnDataTestId: 'Add',
resultTestId: 'glossary-reviewer-name',
endpoint: EntityTypeEndpoint.Glossary,
});

await page.reload();
await page.click('[data-testid="version-button"]');
await versionPageResponse;

await expect(
page.locator(
'[data-testid="glossary-reviewer"] [data-testid="diff-added"]'
)
).toBeVisible();
});

await glossary.delete(apiContext);
await afterAction();
});

test('GlossaryTerm', async ({ page }) => {
const { term1, term2, cleanup } = await setupGlossaryAndTerms(page);

await test.step('Version changes', async () => {
await term2.visitPage(page);

await page.click('[data-testid="version-button"]');

await expect(
page
.getByTestId('asset-description-container')
.getByTestId('markdown-parser')
.locator('span')
.filter({ hasText: 'Description' })
).toBeVisible();

await expect(
page.locator(
'.diff-added [data-testid="tag-PersonalData.SpecialCategory"]'
)
).toBeVisible();

await expect(
page.locator('.diff-added [data-testid="tag-PII.Sensitive"]')
).toBeVisible();

await expect(
page.locator('[data-testid="test-synonym"].diff-added')
).toBeVisible();

await expect(
page.locator(`[data-testid="${term1.data.displayName}"].diff-added`)
).toBeVisible();

await expect(
page.locator('.diff-added [data-testid="reference-link-reference1"]')
).toBeVisible();
});

await test.step('Should display the owner & reviewer changes', async () => {
await term2.visitPage(page);

await expect(page.getByTestId('version-button')).toHaveText(/0.2/);

await addOwner(
page,
user.getUserName(),
'Users',
EntityTypeEndpoint.GlossaryTerm,
'glossary-right-panel-owner-link'
);
await page.reload();
const versionPageResponse = page.waitForResponse(
`/api/v1/glossaryTerms/${term2.responseData.id}/versions/0.2`
);
await page.click('[data-testid="version-button"]');
await versionPageResponse;

await expect(
page.locator(
'[data-testid="glossary-right-panel-owner-link"] [data-testid="diff-added"]'
)
).toBeVisible();

await page.click('[data-testid="version-button"]');
await versionPageResponse;

await addMultiOwner({
page,
ownerNames: [reviewer.getUserName()],
activatorBtnDataTestId: 'Add',
resultTestId: 'glossary-reviewer-name',
endpoint: EntityTypeEndpoint.GlossaryTerm,
});

await page.reload();
await page.click('[data-testid="version-button"]');
await versionPageResponse;

await expect(
page.locator(
'[data-testid="glossary-reviewer"] [data-testid="diff-added"]'
)
).toBeVisible();
});

await cleanup();
});

test.afterAll(async ({ browser }) => {
const { afterAction, apiContext } = await createNewPage(browser);

await user.delete(apiContext);
await reviewer.delete(apiContext);
await afterAction();
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import { APIRequestContext, Page } from '@playwright/test';
import { CustomPropertySupportedEntityList } from '../../constant/customProperty';
import {
CustomProperty,
createCustomPropertyForEntity,
CustomProperty,
setValueForProperty,
validateValueForProperty,
} from '../../utils/customProperty';
Expand All @@ -37,15 +37,15 @@ import {
replyAnnouncement,
softDeleteEntity,
unFollowEntity,
upVote,
updateDescription,
updateDisplayNameForEntity,
updateOwner,
upVote,
validateFollowedEntityToWidget,
} from '../../utils/entity';
import { Domain } from '../domain/Domain';
import { GlossaryTerm } from '../glossary/GlossaryTerm';
import { ENTITY_PATH, EntityTypeEndpoint } from './Entity.interface';
import { EntityTypeEndpoint, ENTITY_PATH } from './Entity.interface';

export class EntityClass {
type: string;
Expand Down Expand Up @@ -123,7 +123,7 @@ export class EntityClass {
) {
await addOwner(page, owner1, type, this.endpoint, 'data-assets-header');
await updateOwner(page, owner2, type, this.endpoint, 'data-assets-header');
await removeOwner(page, this.endpoint, 'data-assets-header');
await removeOwner(page, this.endpoint, owner2, 'data-assets-header');
}

async tier(page: Page, tier1: string, tier2: string) {
Expand Down
Loading

0 comments on commit 282327c

Please sign in to comment.