From cc8d4fe9526f8d8162b45d891b63f76519db2689 Mon Sep 17 00:00:00 2001 From: Dharini Jeeva Date: Wed, 8 Jan 2025 12:25:03 -0800 Subject: [PATCH] test: GCP plugin acceptance tests (#2648) --- .../acceptance/host-catalogs/delete-test.js | 26 +++++++++++++++++++ .../acceptance/host-catalogs/list-test.js | 25 ++++++++++++++++++ .../acceptance/host-catalogs/update-test.js | 25 +++++++++++++++++- 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/ui/admin/tests/acceptance/host-catalogs/delete-test.js b/ui/admin/tests/acceptance/host-catalogs/delete-test.js index c8792fa25..2bab43b5c 100644 --- a/ui/admin/tests/acceptance/host-catalogs/delete-test.js +++ b/ui/admin/tests/acceptance/host-catalogs/delete-test.js @@ -11,6 +11,10 @@ import { Response } from 'miragejs'; import { authenticateSession } from 'ember-simple-auth/test-support'; import { setupIndexedDb } from 'api/test-support/helpers/indexed-db'; import * as commonSelectors from 'admin/tests/helpers/selectors'; +import { + TYPE_HOST_CATALOG_DYNAMIC, + TYPE_HOST_CATALOG_PLUGIN_GCP, +} from 'api/models/host-catalog'; module('Acceptance | host-catalogs | delete', function (hooks) { setupApplicationTest(hooks); @@ -30,6 +34,7 @@ module('Acceptance | host-catalogs | delete', function (hooks) { project: null, }, hostCatalog: null, + gcpDynamicHostCatalog: null, }; const urls = { globalScope: null, @@ -37,6 +42,7 @@ module('Acceptance | host-catalogs | delete', function (hooks) { projectScope: null, hostCatalogs: null, hostCatalog: null, + gcpDynamicHostCatalog: null, }; hooks.beforeEach(async function () { @@ -53,12 +59,20 @@ module('Acceptance | host-catalogs | delete', function (hooks) { instances.hostCatalog = this.server.create('host-catalog', { scope: instances.scopes.project, }); + + instances.gcpDynamicHostCatalog = this.server.create('host-catalog', { + scope: instances.scopes.project, + type: TYPE_HOST_CATALOG_DYNAMIC, + plugin: { name: TYPE_HOST_CATALOG_PLUGIN_GCP }, + }); + // Generate route URLs for resources urls.globalScope = `/scopes/global/scopes`; urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`; urls.projectScope = `/scopes/${instances.scopes.project.id}`; urls.hostCatalogs = `${urls.projectScope}/host-catalogs`; urls.hostCatalog = `${urls.hostCatalogs}/${instances.hostCatalog.id}`; + urls.gcpDynamicHostCatalog = `${urls.hostCatalogs}/${instances.gcpDynamicHostCatalog.id}`; // Generate resource counter getHostCatalogCount = () => this.server.schema.hostCatalogs.all().models.length; @@ -76,6 +90,18 @@ module('Acceptance | host-catalogs | delete', function (hooks) { assert.strictEqual(getHostCatalogCount(), hostCatalogCount - 1); }); + test('can delete GCP host catalog', async function (assert) { + const hostCatalogCount = getHostCatalogCount(); + + await visit(urls.hostCatalogs); + await click(`[href="${urls.gcpDynamicHostCatalog}"]`); + + await click(MANAGE_DROPDOWN_SELECTOR); + await click(DELETE_ACTION_SELECTOR); + + assert.strictEqual(getHostCatalogCount(), hostCatalogCount - 1); + }); + test('cannot delete host catalog without proper authorization', async function (assert) { await visit(urls.hostCatalogs); instances.hostCatalog.authorized_actions = diff --git a/ui/admin/tests/acceptance/host-catalogs/list-test.js b/ui/admin/tests/acceptance/host-catalogs/list-test.js index a1eecb0ba..ff61bcabf 100644 --- a/ui/admin/tests/acceptance/host-catalogs/list-test.js +++ b/ui/admin/tests/acceptance/host-catalogs/list-test.js @@ -14,6 +14,7 @@ import { TYPE_HOST_CATALOG_STATIC, TYPE_HOST_CATALOG_PLUGIN_AWS, TYPE_HOST_CATALOG_PLUGIN_AZURE, + TYPE_HOST_CATALOG_PLUGIN_GCP, } from 'api/models/host-catalog'; import * as commonSelectors from 'admin/tests/helpers/selectors'; @@ -29,6 +30,7 @@ module('Acceptance | host-catalogs | list', function (hooks) { project: null, }, staticHostCatalog: null, + gcpHostCatalog: null, }; const urls = { @@ -39,6 +41,7 @@ module('Acceptance | host-catalogs | list', function (hooks) { awsHostCatalog: null, azureHostCatalog: null, staticHostCatalog: null, + gcpHostCatalog: null, }; const SEARCH_INPUT_SELECTOR = '.search-filtering [type="search"]'; @@ -68,6 +71,12 @@ module('Acceptance | host-catalogs | list', function (hooks) { type: TYPE_HOST_CATALOG_DYNAMIC, plugin: { name: TYPE_HOST_CATALOG_PLUGIN_AZURE }, }); + instances.gcpHostCatalog = this.server.create('host-catalog', { + scope: instances.scopes.project, + type: TYPE_HOST_CATALOG_DYNAMIC, + plugin: { name: TYPE_HOST_CATALOG_PLUGIN_GCP }, + }); + urls.globalScope = `/scopes/global/scopes`; urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`; urls.projectScope = `/scopes/${instances.scopes.project.id}`; @@ -75,6 +84,7 @@ module('Acceptance | host-catalogs | list', function (hooks) { urls.staticHostCatalog = `${urls.hostCatalogs}/${instances.staticHostCatalog.id}`; urls.awsHostCatalog = `${urls.hostCatalogs}/${instances.awsHostCatalog.id}`; urls.azureHostCatalog = `${urls.hostCatalogs}/${instances.azureHostCatalog.id}`; + urls.gcpHostCatalog = `${urls.hostCatalogs}/${instances.gcpHostCatalog.id}`; await authenticateSession({}); }); @@ -215,6 +225,21 @@ module('Acceptance | host-catalogs | list', function (hooks) { assert.dom(`[href="${urls.azureHostCatalog}"]`).exists(); }); + test('user can search for gcp host catalog', async function (assert) { + await visit(urls.projectScope); + + await click(`[href="${urls.hostCatalogs}"]`); + assert.dom(`[href="${urls.staticHostCatalog}"]`).isVisible(); + assert.dom(`[href="${urls.awsHostCatalog}"]`).isVisible(); + assert.dom(`[href="${urls.azureHostCatalog}"]`).isVisible(); + assert.dom(`[href="${urls.gcpHostCatalog}"]`).isVisible(); + + await fillIn(SEARCH_INPUT_SELECTOR, TYPE_HOST_CATALOG_PLUGIN_GCP); + await waitFor(`[href="${urls.staticHostCatalog}"]`, { count: 0 }); + + assert.dom(`[href="${urls.gcpHostCatalog}"]`).isVisible(); + }); + test('user can search for host catalogs and get no results', async function (assert) { await visit(urls.projectScope); diff --git a/ui/admin/tests/acceptance/host-catalogs/update-test.js b/ui/admin/tests/acceptance/host-catalogs/update-test.js index 30e9105ec..4ad893103 100644 --- a/ui/admin/tests/acceptance/host-catalogs/update-test.js +++ b/ui/admin/tests/acceptance/host-catalogs/update-test.js @@ -14,6 +14,7 @@ import * as commonSelectors from 'admin/tests/helpers/selectors'; import { TYPE_HOST_CATALOG_DYNAMIC, TYPE_HOST_CATALOG_PLUGIN_AWS, + TYPE_HOST_CATALOG_PLUGIN_GCP, } from 'api/models/host-catalog'; module('Acceptance | host-catalogs | update', function (hooks) { @@ -28,6 +29,7 @@ module('Acceptance | host-catalogs | update', function (hooks) { project: null, }, hostCatalog: null, + GCPHostCatalog: null, }; const urls = { globalScope: null, @@ -36,10 +38,11 @@ module('Acceptance | host-catalogs | update', function (hooks) { hostCatalogs: null, hostCatalog: null, AWSHostCatalogWithStaticCredential: null, + GCPHostCatalog: null, }; const NAME_INPUT_SELECTOR = '[name="name"]'; - const EDIT_BUTTON_SELECTOR = 'form [type="button"]'; + const EDIT_BUTTON_SELECTOR = '.rose-form-actions [type=button]'; const SAVE_BUTTON_SELECTOR = '.rose-form-actions [type="submit"]'; const CANCEL_BUTTON_SELECTOR = '.rose-form-actions [type="button"]'; const CREDENTIAL_TYPE_SELECTOR = @@ -59,6 +62,12 @@ module('Acceptance | host-catalogs | update', function (hooks) { instances.hostCatalog = this.server.create('host-catalog', { scope: instances.scopes.project, }); + instances.GCPHostCatalog = this.server.create('host-catalog', { + scope: instances.scopes.project, + type: TYPE_HOST_CATALOG_DYNAMIC, + plugin: { name: TYPE_HOST_CATALOG_PLUGIN_GCP }, + }); + instances.AWSHostCatalogWithStaticCredential = this.server.create( 'host-catalog', { @@ -75,6 +84,7 @@ module('Acceptance | host-catalogs | update', function (hooks) { urls.hostCatalogs = `${urls.projectScope}/host-catalogs`; urls.hostCatalog = `${urls.hostCatalogs}/${instances.hostCatalog.id}`; urls.AWSHostCatalogWithStaticCredential = `${urls.hostCatalogs}/${instances.AWSHostCatalogWithStaticCredential.id}`; + urls.GCPHostCatalog = `${urls.hostCatalogs}/${instances.GCPHostCatalog.id}`; await authenticateSession({}); }); @@ -97,6 +107,19 @@ module('Acceptance | host-catalogs | update', function (hooks) { ); }); + test('can update GCP host catalog', async function (assert) { + await visit(urls.GCPHostCatalog); + await click(EDIT_BUTTON_SELECTOR, 'Activate edit mode'); + await fillIn('[name=project_id]', 'project-id'); + await click(SAVE_BUTTON_SELECTOR); + + assert.strictEqual( + this.server.schema.hostCatalogs.where({ type: 'plugin' }).models[0] + .attributes.project_id, + 'project-id', + ); + }); + test('can save changes to existing host catalog', async function (assert) { assert.notEqual(instances.hostCatalog.name, 'random string'); await visit(urls.hostCatalog);