example-page.cy.ts 2.7 KB

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