example-page.cy.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { checkErrors } from '../support';
  2. const PLUGIN_TEMPLATE_NAME = 'console-plugin-template';
  3. const PLUGIN_TEMPLATE_PULL_SPEC = Cypress.env('PLUGIN_TEMPLATE_PULL_SPEC');
  4. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  5. export const isLocalDevEnvironment = Cypress.config('baseUrl')!.includes('localhost');
  6. const installHelmChart = (path: string) => {
  7. // Install the plugin in a dedicated namespace using the helm chart from this repo
  8. cy.exec(
  9. `cd ../../console-plugin-template && ${path} upgrade -i ${PLUGIN_TEMPLATE_NAME} charts/openshift-console-plugin -n ${PLUGIN_TEMPLATE_NAME} --create-namespace --set plugin.image=${PLUGIN_TEMPLATE_PULL_SPEC}`,
  10. {
  11. failOnNonZeroExit: false,
  12. },
  13. ).then((result) => {
  14. result.stderr && cy.log('Error installing helm chart: ', result.stderr);
  15. result.stdout && cy.log('Successfully installed helm chart: ', result.stdout);
  16. });
  17. // Wait for the plugin deployment to be ready
  18. cy.exec(
  19. `oc rollout status -n ${PLUGIN_TEMPLATE_NAME} deploy/${PLUGIN_TEMPLATE_NAME} -w --timeout=300s`,
  20. { timeout: 360000, failOnNonZeroExit: false },
  21. );
  22. // Wait for console pods to restart with the new plugin
  23. cy.exec('oc rollout status -w deploy/console -n openshift-console --timeout=300s', {
  24. timeout: 360000,
  25. failOnNonZeroExit: false,
  26. });
  27. cy.visit('/k8s/cluster/operator.openshift.io~v1~Console/cluster/console-plugins');
  28. cy.get(`[data-test="${PLUGIN_TEMPLATE_NAME}-status"]`).should('include.text', 'Loaded');
  29. };
  30. const deleteHelmChart = (path: string) => {
  31. cy.exec(
  32. `cd ../../console-plugin-template && ${path} uninstall ${PLUGIN_TEMPLATE_NAME} -n ${PLUGIN_TEMPLATE_NAME} && oc delete namespaces ${PLUGIN_TEMPLATE_NAME}`,
  33. {
  34. failOnNonZeroExit: false,
  35. },
  36. ).then((result) => {
  37. cy.log('Error uninstalling helm chart: ', result.stderr);
  38. cy.log('Successfully uninstalled helm chart: ', result.stdout);
  39. });
  40. };
  41. describe('Console plugin template test', () => {
  42. before(() => {
  43. cy.login();
  44. cy.get(`[data-test="tour-step-footer-secondary"]`).contains('Skip tour').click();
  45. if (!isLocalDevEnvironment) {
  46. console.log('this is not a local env, installing helm');
  47. cy.exec('cd ../../console-plugin-template && ./install_helm.sh', {
  48. failOnNonZeroExit: false,
  49. }).then((result) => {
  50. cy.log('Error installing helm binary: ', result.stderr);
  51. cy.log('Successfully installed helm binary in "/tmp" directory: ', result.stdout);
  52. installHelmChart('/tmp/helm');
  53. });
  54. } else {
  55. console.log('this is a local env, not installing helm');
  56. installHelmChart('helm');
  57. }
  58. });
  59. afterEach(() => {
  60. checkErrors();
  61. });
  62. after(() => {
  63. if (!isLocalDevEnvironment) {
  64. deleteHelmChart('/tmp/helm');
  65. } else {
  66. deleteHelmChart('helm');
  67. }
  68. cy.logout();
  69. });
  70. it('Verify the example page title', () => {
  71. cy.get('[data-quickstart-id="qs-nav-home"]').click();
  72. cy.get('[data-test="nav"]').contains('Plugin example').click();
  73. cy.url().should('include', '/example');
  74. cy.get('title').should('contain', 'Hello, plugin!');
  75. });
  76. });