example-page.cy.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. cy.exec(
  7. `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}`,
  8. {
  9. failOnNonZeroExit: false,
  10. },
  11. ).then((result) => {
  12. result.stderr && cy.log('Error installing helm chart: ', result.stderr);
  13. result.stdout && cy.log('Successfully installed helm chart: ', result.stdout);
  14. cy.visit('/k8s/cluster/operator.openshift.io~v1~Console/cluster/console-plugins');
  15. cy.get('[data-test="console-plugin-template-status"]').should('include.text', 'loaded');
  16. });
  17. };
  18. const deleteHelmChart = (path: string) => {
  19. cy.exec(
  20. `cd ../../console-plugin-template && ${path} uninstall ${PLUGIN_TEMPLATE_NAME} -n ${PLUGIN_TEMPLATE_NAME} && oc delete namespaces ${PLUGIN_TEMPLATE_NAME}`,
  21. {
  22. failOnNonZeroExit: false,
  23. },
  24. ).then((result) => {
  25. cy.log('Error uninstalling helm chart: ', result.stderr);
  26. cy.log('Successfully uninstalled helm chart: ', result.stdout);
  27. });
  28. };
  29. describe('Console plugin template test', () => {
  30. before(() => {
  31. cy.login();
  32. cy.get(`[data-test="tour-step-footer-secondary"]`).contains('Skip tour').click();
  33. if (!isLocalDevEnvironment) {
  34. console.log('this is not a local env, installig helm');
  35. cy.exec('cd ../../console-plugin-template && ./install_helm.sh', {
  36. failOnNonZeroExit: false,
  37. }).then((result) => {
  38. cy.log('Error installing helm binary: ', result.stderr);
  39. cy.log('Successfully installed helm binary in "/tmp" directory: ', result.stdout);
  40. installHelmChart('/tmp/helm');
  41. });
  42. } else {
  43. console.log('this is a local env, not installing helm');
  44. installHelmChart('helm');
  45. }
  46. });
  47. afterEach(() => {
  48. checkErrors();
  49. });
  50. after(() => {
  51. if (!isLocalDevEnvironment) {
  52. deleteHelmChart('/tmp/helm');
  53. } else {
  54. deleteHelmChart('helm');
  55. }
  56. cy.logout();
  57. });
  58. it('Verify the example page title', () => {
  59. cy.get('[data-quickstart-id="qs-nav-home"]').click();
  60. cy.get('[data-test="nav"]').contains('Plugin example').click();
  61. cy.url().should('include', '/example');
  62. cy.get('title').should('contain', 'Hello, plugin!');
  63. });
  64. });