github.com/rancher/elemental/tests@v0.0.0-20240517125144-ae048c615b3f/cypress/latest/e2e/unit_tests/machine_registration.spec.ts (about) 1 /* 2 Copyright © 2022 - 2024 SUSE LLC 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 http://www.apache.org/licenses/LICENSE-2.0 8 Unless required by applicable law or agreed to in writing, software 9 distributed under the License is distributed on an "AS IS" BASIS, 10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 See the License for the specific language governing permissions and 12 limitations under the License. 13 */ 14 15 import '~/support/commands'; 16 import filterTests from '~/support/filterTests.js'; 17 import * as utils from "~/support/utils"; 18 import * as cypressLib from '@rancher-ecp-qa/cypress-library'; 19 import { qase } from 'cypress-qase-reporter/dist/mocha'; 20 import { slowCypressDown } from 'cypress-slow-down' 21 22 // slow down each command by 500ms 23 slowCypressDown(500) 24 25 Cypress.config(); 26 describe('Machine registration testing', () => { 27 const elementalUser = "elemental-user" 28 const uiAccount = Cypress.env('ui_account'); 29 const uiPassword = "rancherpassword" 30 31 before(() => { 32 (uiAccount == "user") ? cy.login(elementalUser, uiPassword) : cy.login(); 33 cy.visit('/'); 34 35 // Open the navigation menu 36 cypressLib.burgerMenuToggle(); 37 38 // Click on the Elemental's icon 39 cypressLib.accesMenu('OS Management'); 40 41 // In upgrade scenario, we need to add extra channels 42 // KEEP THIS COMMENTED FOR NOW 43 //if (utils.isCypressTag('upgrade')) { 44 // if (utils.isOperatorVersion('registry.suse.com')) { 45 // utils.isUpgradeOsChannel('dev') ? cy.addOsVersionChannel('dev') : cy.addOsVersionChannel('staging'); 46 // } else if (utils.isOperatorVersion('staging')) { 47 // cy.addOsVersionChannel('dev'); 48 // } else { 49 // cy.addOsVersionChannel('stable'); 50 // } 51 //} 52 }); 53 54 beforeEach(() => { 55 cy.viewport(1920, 1080); 56 (uiAccount == "user") ? cy.login(elementalUser, uiPassword) : cy.login(); 57 cy.visit('/'); 58 59 // Open the navigation menu 60 cypressLib.burgerMenuToggle(); 61 62 // Click on the Elemental's icon 63 cypressLib.accesMenu('OS Management'); 64 65 // Delete all files previously downloaded 66 cy.exec('rm cypress/downloads/*', {failOnNonZeroExit: false}); 67 68 // Delete all existing machine registrations 69 cy.getBySel('manage-reg-btn') 70 .click(); 71 cy.get('.outlet > header').contains('Registration Endpoints'); 72 cy.get('body').then(($body) => { 73 if (!$body.text().includes('There are no rows to show.')) { 74 cy.deleteAllResources(); 75 } 76 }); 77 }); 78 79 filterTests(['main'], () => { 80 qase(4, 81 it('Create machine registration with default options', () => { 82 cy.createMachReg('default-options-test'); 83 }) 84 ); 85 86 qase(6, 87 it('Create machine registration with labels and annotations', () => { 88 cy.createMachReg('labels-annotations-test', 'fleet-default', true, true); 89 }) 90 ); 91 92 qase(17, 93 it('Delete machine registration', () => { 94 cy.createMachReg('delete-test'); 95 cy.deleteMachReg('delete-test'); 96 }) 97 ); 98 99 qase(49, 100 it('Edit a machine registration with edit config button', () => { 101 cy.createMachReg('edit-config-test'); 102 cy.editMachReg('edit-config-test', true, true); 103 cy.getBySel('form-save') 104 .contains('Save') 105 .click(); 106 107 // Check that we can see our label and annotation in the YAML 108 cy.checkMachRegLabel('edit-config-test', 'myLabel1', 'myLabelValue1'); 109 cy.checkMachRegAnnotation('edit-config-test', 'myAnnotation1', 'myAnnotationValue1'); 110 }) 111 ); 112 113 qase(50, 114 it('Edit a machine registration with edit YAML button', () => { 115 cy.createMachReg('edit-yaml-test'); 116 cy.editMachReg('edit-yaml-test', true, true, true); 117 cy.getBySel('action-button-async-button') 118 .contains('Save') 119 .click(); 120 121 // Check that we can see our label and annotation in the YAML 122 cy.checkMachRegLabel('edit-yaml-test', 'myLabel1', 'myLabelValue1'); 123 cy.checkMachRegAnnotation('edit-yaml-test', 'myAnnotation1', 'myAnnotationValue1'); 124 }) 125 ); 126 127 qase(18, 128 it('Clone a machine registration', () => { 129 cy.createMachReg('clone-test', 'fleet-default', true, true); 130 cy.contains('clone-test') 131 .click(); 132 cy.get('div.actions > .role-multi-action') 133 .click() 134 cy.contains('li', 'Clone') 135 .click(); 136 cy.getBySel('name-ns-description-name') 137 .type('cloned-machine-reg') 138 cy.getBySel('form-save') 139 .contains('Create') 140 .click(); 141 cy.contains('.masthead', 'Registration Endpoint: cloned-machine-regActive') 142 .should('exist'); 143 144 // Check that we got the same label and annotation in both machine registration 145 cy.checkMachRegLabel('cloned-machine-reg','myLabel1', 'myLabelValue1'); 146 cy.contains('cloned-machine-reg') 147 .click(); 148 cy.checkMachRegAnnotation('cloned-machine-reg', 'myAnnotation1', 'myAnnotationValue1'); 149 cy.contains('cloned-machine-reg') 150 .click(); 151 }) 152 ); 153 154 qase(19, 155 it('Download Machine registration YAML', () => { 156 cy.createMachReg('download-yaml-test'); 157 cy.contains('download-yaml-test') 158 .click(); 159 cy.get('div.actions > .role-multi-action') 160 .click() 161 cy.contains('li', 'Download YAML') 162 .click(); 163 cy.verifyDownload('download-yaml-test.yaml'); 164 }) 165 ); 166 167 qase(51, 168 it('Check machine registration label name size', () => { 169 cy.checkLabelSize('name'); 170 }) 171 ); 172 173 qase(52, 174 it('Check machine registration label value size', () => { 175 cy.checkLabelSize('value'); 176 }) 177 ); 178 179 // This test must stay the last one because we use this machine registration when we test adding a node. 180 // It also tests using a custom cloud config by using read from file button. 181 qase([8,20,5], 182 it('Create Machine registration we will use to test adding a node', () => { 183 cy.createMachReg('machine-registration', 184 'fleet-default', 185 //checkLabels 186 false, 187 //checkAnnotations 188 false, 189 //checkInventoryLabels 190 true, 191 //checkInventoryAnnotations 192 true, 193 //checkIsoBuilding 194 true, 195 utils.isK8sVersion('k3s') ? 'custom_cloud-config_with_reset.yaml' : 'custom_cloud-config.yaml', 196 //checkDefaultCloudConfig 197 false); 198 cy.checkMachInvLabel('machine-registration', 'myInvLabel1', 'myInvLabelValue1', false); 199 }) 200 ); 201 }); 202 203 // In the upgrade test we test the ISO building feature 204 // and boot from the stable ISO, mainly because we can 205 // only select stable ISO for now. 206 // We will move the test to the standard scenario later 207 filterTests(['upgrade'], () => { 208 qase([8,20,5], 209 it('Create Machine registration we will use to test adding a node', () => { 210 cy.createMachReg('machine-registration', 211 'fleet-default', 212 //checkLabels 213 false, 214 //checkAnnotations 215 false, 216 //checkInventoryLabels 217 true, 218 //checkInventoryAnnotations 219 true, 220 //checkIsoBuilding 221 true, 222 'custom_cloud-config_upgrade.yaml', 223 //checkDefaultCloudConfig 224 false); 225 cy.checkMachInvLabel('machine-registration', 'myInvLabel1', 'myInvLabelValue1', false); 226 }) 227 ); 228 }); 229 });