|
| 1 | +/********************************************************************** |
| 2 | + * Copyright (C) 2024 Red Hat, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + ***********************************************************************/ |
| 18 | + |
| 19 | +import type { NavigationBar } from '@podman-desktop/tests-playwright'; |
| 20 | +import { expect as playExpect, ExtensionCardPage, RunnerOptions, test } from '@podman-desktop/tests-playwright'; |
| 21 | + |
| 22 | +import { OpenShiftLocalExtensionPage } from './model/pages/openshift-local-extension-page'; |
| 23 | + |
| 24 | +let extensionInstalled = false; |
| 25 | +let extensionCard: ExtensionCardPage; |
| 26 | +const imageName = 'ghcr.io/crc-org/crc-extension:latest'; |
| 27 | +const extensionLabelCrc = 'redhat.openshift-local'; |
| 28 | +const extensionLabelNameCrc = 'openshift-local'; |
| 29 | +const extensionLabelAuthentication = 'redhat.redhat-authentication'; |
| 30 | +const extensionLabelNameAuthentication = 'redhat-authentication'; |
| 31 | +const activeExtensionStatus = 'ACTIVE'; |
| 32 | +const disabledExtensionStatus = 'DISABLED'; |
| 33 | +const skipInstallation = process.env.SKIP_INSTALLATION ? process.env.SKIP_INSTALLATION : false; |
| 34 | + |
| 35 | +test.use({ |
| 36 | + runnerOptions: new RunnerOptions({ customFolder: 'crc-tests-pd', autoUpdate: false, autoCheckUpdates: false }), |
| 37 | +}); |
| 38 | +test.beforeAll(async ({ runner, page, welcomePage }) => { |
| 39 | + runner.setVideoAndTraceName('crc-e2e'); |
| 40 | + await welcomePage.handleWelcomePage(true); |
| 41 | + extensionCard = new ExtensionCardPage(page, extensionLabelNameCrc, extensionLabelCrc); |
| 42 | +}); |
| 43 | + |
| 44 | +test.afterAll(async ({ runner }) => { |
| 45 | + await runner.close(); |
| 46 | +}); |
| 47 | + |
| 48 | +test.describe.serial('Red Hat OpenShift Local extension verification', () => { |
| 49 | + test.describe.serial('Red Hat OpenShift Local extension installation', () => { |
| 50 | + // PR check builds extension locally and so it is available already |
| 51 | + test('Go to extensions and check if extension is already installed', async ({ navigationBar }) => { |
| 52 | + const extensions = await navigationBar.openExtensions(); |
| 53 | + if (await extensions.extensionIsInstalled(extensionLabelCrc)) { |
| 54 | + extensionInstalled = true; |
| 55 | + } |
| 56 | + }); |
| 57 | + |
| 58 | + // we want to skip removing of the extension when we are running tests from PR check |
| 59 | + test('Uninstall previous version of crc extension', async ({ navigationBar }) => { |
| 60 | + test.skip(!extensionInstalled || !!skipInstallation); |
| 61 | + test.setTimeout(60000); |
| 62 | + await removeExtension(navigationBar); |
| 63 | + }); |
| 64 | + |
| 65 | + // we want to install extension from OCI image (usually using latest tag) after new code was added to the codebase |
| 66 | + // and extension was published already |
| 67 | + test('Extension can be installed using OCI image', async ({ navigationBar }) => { |
| 68 | + test.skip(extensionInstalled && !skipInstallation); |
| 69 | + test.setTimeout(200000); |
| 70 | + const extensions = await navigationBar.openExtensions(); |
| 71 | + await extensions.installExtensionFromOCIImage(imageName); |
| 72 | + await playExpect(extensionCard.card).toBeVisible(); |
| 73 | + }); |
| 74 | + |
| 75 | + test('Extension (card) is installed, present and active', async ({ navigationBar }) => { |
| 76 | + const extensions = await navigationBar.openExtensions(); |
| 77 | + await playExpect.poll(async () => |
| 78 | + await extensions.extensionIsInstalled(extensionLabelCrc), { timeout: 30000 }, |
| 79 | + ).toBeTruthy(); |
| 80 | + const extensionCard = await extensions.getInstalledExtension(extensionLabelNameCrc, extensionLabelCrc); |
| 81 | + await playExpect(extensionCard.status).toHaveText(activeExtensionStatus); |
| 82 | + }); |
| 83 | + |
| 84 | + test('Extension\'s dependency, Red Hat Authentication, (card) is installed, present and active', async ({ navigationBar }) => { |
| 85 | + const extensions = await navigationBar.openExtensions(); |
| 86 | + await playExpect.poll(async () => |
| 87 | + await extensions.extensionIsInstalled(extensionLabelAuthentication), { timeout: 30000 }, |
| 88 | + ).toBeTruthy(); |
| 89 | + const extensionCard = await extensions.getInstalledExtension(extensionLabelNameAuthentication, extensionLabelAuthentication); |
| 90 | + await playExpect(extensionCard.status).toHaveText(activeExtensionStatus); |
| 91 | + }); |
| 92 | + |
| 93 | + test('Extension\'s details show correct status, no error', async ({ page,navigationBar }) => { |
| 94 | + const extensions = await navigationBar.openExtensions(); |
| 95 | + const extensionCard = await extensions.getInstalledExtension(extensionLabelNameCrc, extensionLabelCrc); |
| 96 | + await extensionCard.openExtensionDetails('Red Hat Authentication'); |
| 97 | + const details = new OpenShiftLocalExtensionPage(page); |
| 98 | + await playExpect(details.heading).toBeVisible(); |
| 99 | + await playExpect(details.status).toHaveText(activeExtensionStatus); |
| 100 | + const errorTab = details.tabs.getByRole('button', { name: 'Error' }); |
| 101 | + // we would like to propagate the error's stack trace into test failure message |
| 102 | + let stackTrace = ''; |
| 103 | + if ((await errorTab.count()) > 0) { |
| 104 | + await details.activateTab('Error'); |
| 105 | + stackTrace = await details.errorStackTrace.innerText(); |
| 106 | + } |
| 107 | + await playExpect(errorTab, `Error Tab was present with stackTrace: ${stackTrace}`).not.toBeVisible(); |
| 108 | + }); |
| 109 | + }); |
| 110 | + |
| 111 | + test.describe.serial('Red Hat OpenShift Local extension handling', () => { |
| 112 | + test('Extension can be disabled', async ({ navigationBar }) => { |
| 113 | + const extensions = await navigationBar.openExtensions(); |
| 114 | + playExpect(await extensions.extensionIsInstalled(extensionLabelCrc)).toBeTruthy(); |
| 115 | + const extensionCard = await extensions.getInstalledExtension(extensionLabelNameCrc, extensionLabelCrc); |
| 116 | + await playExpect(extensionCard.status).toHaveText(activeExtensionStatus); |
| 117 | + await extensionCard.disableExtension(); |
| 118 | + await playExpect(extensionCard.status).toHaveText(disabledExtensionStatus); |
| 119 | + }); |
| 120 | + |
| 121 | + test('Extension can be re-enabled correctly', async ({ navigationBar }) => { |
| 122 | + const extensions = await navigationBar.openExtensions(); |
| 123 | + playExpect(await extensions.extensionIsInstalled(extensionLabelCrc)).toBeTruthy(); |
| 124 | + const extensionCard = await extensions.getInstalledExtension(extensionLabelNameCrc, extensionLabelCrc); |
| 125 | + await playExpect(extensionCard.status).toHaveText(disabledExtensionStatus); |
| 126 | + await extensionCard.enableExtension(); |
| 127 | + await playExpect(extensionCard.status).toHaveText(activeExtensionStatus); |
| 128 | + }); |
| 129 | + }); |
| 130 | + |
| 131 | + test('OpenShift Local extension can be removed', async ({ navigationBar }) => { |
| 132 | + await removeExtension(navigationBar); |
| 133 | + }); |
| 134 | +}); |
| 135 | + |
| 136 | +async function removeExtension(navBar: NavigationBar): Promise<void> { |
| 137 | + const extensions = await navBar.openExtensions(); |
| 138 | + const extensionCard = await extensions.getInstalledExtension(extensionLabelNameCrc, extensionLabelCrc); |
| 139 | + await extensionCard.disableExtension(); |
| 140 | + await extensionCard.removeExtension(); |
| 141 | + await playExpect.poll(async () => await extensions.extensionIsInstalled(extensionLabelCrc), { timeout: 15000 }).toBeFalsy(); |
| 142 | +} |
0 commit comments