Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New(RHOSR/tests): First tests of Service Registry artifacts #118

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions lib/artifact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { expect, Page } from '@playwright/test';

// Navigates to artifacts list of Service Registry instance defined by name
export const navigateToServiceRegistryArtifactsList = async function (page: Page, serviceRegistryName: string) {
// Check that there is one link of defined instance
await expect(await page.locator('a', { hasText: serviceRegistryName })).toHaveCount(1);
// Click link of instance
await page.locator('a', { hasText: serviceRegistryName }).click();
// Check that there is tab button for artifacts
await expect(await page.locator('button', { hasText: /Artifacts/ })).toHaveCount(1);
// Click tab button for artifacts
await page.locator('button', { hasText: /Artifacts/ }).click();
};

// Creates artifact in Service registry instance defined by group, id, type and content
export const createServiceRegistryArtifact = async function (
page: Page,
group: string,
id: string,
type: string,
content: string
) {
// Click button for uploading artifact
await page.getByTestId('btn-header-upload-artifact').click();
// Check that modal title is present
await expect(page.getByRole('heading', { name: /Upload Artifact/ })).toHaveCount(1);
// Fill group of artifact
await page.getByPlaceholder('Group').fill(group);
// Fill ID of artifact
await page.getByPlaceholder('ID of the artifact').fill(id);
// Click type dropdown to open it
await page.locator('button:has-text("Auto-Detect")').click();
// Select defined type of artifact
await page.getByText(type).first().click();
// Fill content of artifact
await page.locator('#artifact-content').fill(content);
// Click upload button
await page.getByTestId('modal-btn-upload').click();
// Wait for load of artifact page
await expect(page.getByText(id, { exact: true })).toHaveCount(3);
};

// Deletes artifact in Service Registry instance defined by group and id
export const deleteServiceRegistryArtifact = async function (page: Page, group: string, id: string) {
// Click first occurrence of group to filter artifacts by this group
await page.getByText(group).first().click();
// Click artifact id to open artifact page
await page.getByText(id, { exact: true }).click();
// Click delete button on artifact page
await page.locator('button', { hasText: 'Delete' }).click();
// Click delete button on deletion modal
await page.getByTestId('modal-btn-delete').click();
// Wait for disappearance of artifact id
await expect(page.getByText(id)).toHaveCount(0);
};
123 changes: 123 additions & 0 deletions tests/rhosr/artifacts.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { test, expect } from '@playwright/test';
import login from '@lib/auth';
import { config } from '@lib/config';
import {
deleteServiceRegistryInstance,
createServiceRegistryInstance,
waitForServiceRegistryReady,
deleteAllServiceRegistries
} from '@lib/service_registry';
import {
navigateToServiceRegistryArtifactsList,
deleteServiceRegistryArtifact,
createServiceRegistryArtifact
} from '@lib/artifact';
import { navigateToServiceRegistryList } from '@lib/navigation';

// Define name of Service Registry instance for this set of tests
const testInstanceName = config.instanceName;
// Define artifact group name for artifacts of Service Registry instance for this set of tests
const testArtifactGroupName = `test-artifact-group-${config.sessionID}`;
// Define artifact ID prefix for artifacts of Service Registry instance for this set of tests
const testArtifactIDPrefix = `test-artifact-id-${config.sessionID}`;

// Actions run before every test
test.beforeEach(async ({ page }) => {
// Login to console
await login(page);
// Go to list of Service Registry instances
await navigateToServiceRegistryList(page);
// Wait for dismiss of loading spinner
await page.waitForSelector('[role=progressbar]', {
state: 'detached',
timeout: config.serviceRegistryInstanceCreationTimeout
});
// Wait for presence of button for Service Registry instance creation
await page.waitForSelector('button:has-text("Create Service Registry instance")');
// Check if test instance already exists and it is only present instance in list
if ((await page.getByText(testInstanceName).count()) > 0 && (await page.locator('tr').count()) === 2) {
// Only test instance is present, nothing to do!
} else {
// Go through list of instances
for (const el of await page.locator(`tr >> a`).elementHandles()) {
// Get instance name
const name = await el.textContent();
// If current instance is not instance for this set of tests
if (name !== testInstanceName) {
// Delete instance
await deleteServiceRegistryInstance(page, name);
}
}
// If test instance does not exist yet
if ((await page.getByText(testInstanceName).count()) === 0) {
// Create test instance
await createServiceRegistryInstance(page, testInstanceName);
// Wait for instance readiness
await waitForServiceRegistryReady(page, testInstanceName);
}
}
});

// Actions run after each test
test.afterEach(async ({ page }) => {
// Go to list of Service Registry instances
await navigateToServiceRegistryList(page);
// Go to artifacts list of Service Registry instance
await navigateToServiceRegistryArtifactsList(page, testInstanceName);
// Wait for dismiss of loading spinner
await page.waitForSelector('[role=progressbar]', {
state: 'detached'
});
// If there is at least one artifact present
if (!(await page.getByText('No artifacts found').isVisible())) {
// If there is at least one artifact in current test group
if (!(await expect(page.getByText(testArtifactGroupName)).toHaveCount(0))) {
// Click first occurrence of group to filter artifacts by this group
await page.getByText(testArtifactGroupName).first().click();
// Go through all artifacts in group
for (const el of await page.getByTestId('artifacts-lnk-view-1').elementHandles()) {
// Save id of artifact
const id = await el.textContent();
// If artifact id starts with current test prefix
if (id.startsWith(testArtifactIDPrefix)) {
// Delete artifact
await deleteServiceRegistryArtifact(page, testArtifactGroupName, id);
}
}
}
}
});

// Actions run after all tests
test.afterAll(async ({ page }) => {
// Delete all Service Registry instances created during tests
await deleteAllServiceRegistries(page);
});

// Checks that artifacts list in Service Registry instance is empty
test('check there are no artifacts in Service Registry instance', async ({ page }) => {
// Go to list of Service Registry instances
await navigateToServiceRegistryList(page);
// Go to artifacts list of Service Registry instance
await navigateToServiceRegistryArtifactsList(page, testInstanceName);
// Check presence of text informing about empty list
await expect(page.getByText('No artifacts found')).toHaveCount(1);
});

// Tests upload and deletion of JSON Schema artifact
test('test upload and deletion of JSON Schema artifact', async ({ page }) => {
// Prepare artifact id for test
const testArtifactID = testArtifactIDPrefix + '-json';
// Go to list of Service Registry instances
await navigateToServiceRegistryList(page);
// Go to artifacts list of Service Registry instance
await navigateToServiceRegistryArtifactsList(page, testInstanceName);
// Create artifact defined by group, id, type and content
await createServiceRegistryArtifact(page, testArtifactGroupName, testArtifactID, 'JSON Schema', '{}');
// Go to list of Service Registry instances
await navigateToServiceRegistryList(page);
// Go to artifacts list of Service Registry instance
await navigateToServiceRegistryArtifactsList(page, testInstanceName);
// Delete artifact defined by group and id
await deleteServiceRegistryArtifact(page, testArtifactGroupName, testArtifactID);
});