From 648c5d61eebde5c7361e09012bd436e9071f3443 Mon Sep 17 00:00:00 2001 From: Andrew Breidenbach Date: Fri, 5 Jul 2024 19:58:43 +0200 Subject: [PATCH] standalone: add unfurl init test, use /-/overview for blueprint pages --- .github/workflows/build_test_release.yml | 8 ++ cypress/support/create-aws-environment.js | 4 +- cypress/support/e2e.js | 54 +++++++------- cypress/support/environments.js | 23 ++++-- .../components/cells/application-cell.vue | 13 +++- .../components/cells/combined-cell.vue | 73 +++++++++++++++++++ .../dashboard/components/cells/mixins.js | 11 +++ .../tables/deployment-index-table.vue | 19 +---- packages/oc-pages/dashboard/index.js | 3 + .../deployment-info/deployment-item.js | 6 +- packages/oc-pages/project_overview/index.js | 2 + .../project_overview/store/modules/misc.js | 5 +- packages/oc-pages/vue_shared/lib/normalize.js | 2 + scripts/src/forwarded-variables.json | 3 +- scripts/src/integration-test.js | 34 +++++++-- testing-shared/reloading-unfurl.sh | 2 +- testing-shared/setup.sh | 2 +- testing-shared/ufhome-add-environment.sh | 2 +- testing-shared/unfurl-init-setup.sh | 14 ++++ 19 files changed, 219 insertions(+), 61 deletions(-) create mode 100644 packages/oc-pages/dashboard/components/cells/combined-cell.vue create mode 100644 packages/oc-pages/dashboard/components/cells/mixins.js create mode 100755 testing-shared/unfurl-init-setup.sh diff --git a/.github/workflows/build_test_release.yml b/.github/workflows/build_test_release.yml index c8d7589a..cfbed918 100644 --- a/.github/workflows/build_test_release.yml +++ b/.github/workflows/build_test_release.yml @@ -42,6 +42,8 @@ jobs: - uses: actions/setup-node@v3 with: node-version: 16 + - name: git config + run: git config --global user.email "you@example.com"; git config --global user.name "Your Name" - name: Install yarn dependencies run: npm i -g yarn && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install # TODO add back ufsv-patch -- --runInBand @@ -55,6 +57,12 @@ jobs: run: yarn integration-test run --namespace onecommons/blueprints -- -e GENERATE_SUBDOMAINS=true --browser chrome -s cypress/e2e/blueprints/aws__baserow__baserow.cy.js - name: pkill run: pkill unfurl || /bin/true + - name: Integration test (unfurl init) + env: + STANDALONE_SETUP_SCRIPT: testing-shared/unfurl-init-setup.sh + run: yarn integration-test run --namespace onecommons/blueprints -- -e GENERATE_SUBDOMAINS=true --browser chrome -s cypress/e2e/blueprints/aws__minecraft__minecraft.cy.js + - name: pkill + run: pkill unfurl || /bin/true - name: Integration test (staging upstream) run: yarn integration-test run --namespace onecommons/blueprints -- -e GENERATE_SUBDOMAINS=true --browser chrome -s cypress/e2e/blueprints/aws__baserow__baserow.cy.js env: diff --git a/cypress/support/create-aws-environment.js b/cypress/support/create-aws-environment.js index 30c32c84..a36cb32c 100644 --- a/cypress/support/create-aws-environment.js +++ b/cypress/support/create-aws-environment.js @@ -104,7 +104,9 @@ Cypress.Commands.add('createAWSEnvironment', (options) => { // create external resource if (shouldCreateExternalResource) { - cy.whenInstancesAbsent(environmentName, () => { + cy.whenInstancesAbsent(environmentName, (env) => { + if(Object.keys(env.repositories).filter(repo => repo != '_dashboard').length == 0) return + viewingEnv || cy.visit(`/${DASHBOARD_DEST}/-/environments/${environmentName}`) if(shouldCreateDNS) { cy.uncheckedCreateDNS(AWS_DNS_TYPE, AWS_DNS_ZONE) diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 67a0edf4..213c7447 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -31,6 +31,7 @@ const INTEGRATION_TEST_ARGS = Cypress.env('INTEGRATION_TEST_ARGS') const UNFURL_SERVER_URL = Cypress.env('UNFURL_SERVER_URL') const UNFURL_CLOUDMAP_PATH = Cypress.env('UNFURL_CLOUDMAP_PATH') const UNFURL_PACKAGE_RULES = Cypress.env('UNFURL_PACKAGE_RULES') +const STANDALONE_UNFURL = Cypress.env('STANDALONE_UNFURL') const UNFURL_VALIDATION_MODE = Cypress.env('UNFURL_VALIDATION_MODE') || Cypress.env('VALIDATION_MODE') @@ -138,32 +139,35 @@ beforeEach(() => { }) } - cy.document().then(doc => { - const csrf = doc.querySelector('meta[name="csrf-token"]')?.content - - const win = doc.parentView || doc.defaultView - - cy.request({ - method: 'PATCH', - url: `/${DASHBOARD_DEST || win.gon.home_project}/-/variables`, - failOnStatusCode: false, - headers: { - 'X-CSRF-Token': csrf - }, - body: { - "variables_attributes": [ - { - "key": "UNFURL_SKIP_SAVE", - "secret_value": "never", - "environment_scope": "*", - "variable_type": "env_var", - "masked": false, - "protected": false - } - ] - } + // set via unfurl environment in standalone tests + if(!STANDALONE_UNFURL) { + cy.document().then(doc => { + const csrf = doc.querySelector('meta[name="csrf-token"]')?.content + + const win = doc.parentView || doc.defaultView + + cy.request({ + method: 'PATCH', + url: `/${DASHBOARD_DEST || win.gon.home_project}/-/variables`, + failOnStatusCode: false, + headers: { + 'X-CSRF-Token': csrf + }, + body: { + "variables_attributes": [ + { + "key": "UNFURL_SKIP_SAVE", + "secret_value": "never", + "environment_scope": "*", + "variable_type": "env_var", + "masked": false, + "protected": false + } + ] + } + }) }) - }) + } cy.window().then(win => { if(DEPLOY_IMAGE) { diff --git a/cypress/support/environments.js b/cypress/support/environments.js index 40e5cbf0..f1dbda76 100644 --- a/cypress/support/environments.js +++ b/cypress/support/environments.js @@ -19,6 +19,19 @@ const import slugify from '../../packages/oc-pages/vue_shared/slugify' +/** + * Custom Cypress command to wait until the environment is ready, + * then execute a callback with the environment and store as arguments. + * + * Note: Assertions can be directly chained on the return value of this command. + * This is because Cypress commands return Promises, allowing for assertions + * like `cy.withEnvironment('envName').should('exist')`. The callback function + * does not affect this behavior as long as the command returns the expected value. + * + * @param {string} environmentName - The name of the environment to look up. + * @param {Function} cb - A callback function that receives the environment and store. + * @returns {Cypress.Chainable} - Returns a chainable Cypress command. + */ Cypress.Commands.add('withEnvironment', (environmentName, cb) => { return cy.waitUntil(() => cy.withStore().then(store => { if(!store.getters.environmentsAreReady) return false @@ -30,25 +43,25 @@ Cypress.Commands.add('withEnvironment', (environmentName, cb) => { }), {timeout: BASE_TIMEOUT * 2, interval: 500}) .then(store => { const env = store.getters.lookupEnvironment(environmentName) || null - cb && cb(env) + cb && cb(env, store) // store in callback for convenience return env }) }) Cypress.Commands.add('whenEnvironmentExists', (environmentName, cb) => { - return cy.withEnvironment(environmentName).then(env => env && cb(env)) + return cy.withEnvironment(environmentName).then((env, store) => env && cb(env, store)) }) Cypress.Commands.add('whenEnvironmentAbsent', (environmentName, cb) => { - return cy.withEnvironment(environmentName).then(env => !env && cb()) + return cy.withEnvironment(environmentName).then((env, store) => !env && cb(store)) }) Cypress.Commands.add('whenInstancesAbsent', (environmentName, cb) => { - return cy.withEnvironment(environmentName).then( env => { + return cy.withEnvironment(environmentName).then((env, store) => { if(! env) return if(Object.values(env.instances || {}) .filter(instance => instance.name != 'dns-zone') == 0) { - cb() + cb(env, store) } }) }) diff --git a/packages/oc-pages/dashboard/components/cells/application-cell.vue b/packages/oc-pages/dashboard/components/cells/application-cell.vue index 374defac..4238972a 100644 --- a/packages/oc-pages/dashboard/components/cells/application-cell.vue +++ b/packages/oc-pages/dashboard/components/cells/application-cell.vue @@ -1,8 +1,10 @@