example-page.cy.ts 3.0 KB

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