example-page.cy.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 =
  5. Cypress.config('baseUrl').includes('localhost');
  6. const installHelmChart = (path: string) => {
  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. cy.visit(`/example`);
  14. cy.log('Error installing helm chart: ', result.stderr);
  15. cy.log('Successfully installed helm chart: ', result.stdout);
  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. // Adding this to further debug the failing test issues in CI
  30. describe('My First Test without installing hel chart', () => {
  31. it('Does not do much! Should pass', () => {
  32. expect(true).to.equal(true);
  33. });
  34. it('Does not do much! Should fail', () => {
  35. expect(true).to.equal(false);
  36. });
  37. });
  38. if (!Cypress.env('OPENSHIFT_CI') || Cypress.env('PLUGIN_TEMPLATE_PULL_SPEC')) {
  39. describe('Console plugin template test', () => {
  40. before(() => {
  41. cy.login();
  42. if (!isLocalDevEnvironment) {
  43. console.log('this is not a local env, installig helm');
  44. cy.exec('cd ../../console-plugin-template && ./install_helm.sh', {
  45. failOnNonZeroExit: false,
  46. }).then((result) => {
  47. cy.log('Error installing helm binary: ', result.stderr);
  48. cy.log(
  49. 'Successfully installed helm binary in "/tmp" directory: ',
  50. result.stdout,
  51. );
  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. cy.logout();
  62. });
  63. after(() => {
  64. cy.logout();
  65. if (!isLocalDevEnvironment) {
  66. deleteHelmChart('/tmp/helm');
  67. } else {
  68. deleteHelmChart('helm');
  69. }
  70. });
  71. it('Does not do much! Should pass', () => {
  72. expect(true).to.equal(true);
  73. });
  74. it('Verify the example page title', () => {
  75. cy.get('[data-quickstart-id="qs-nav-home"]').click();
  76. cy.get('[data-test="nav"]').contains('Plugin Example').click();
  77. cy.url().should('include', '/example');
  78. cy.get('[data-test="example-page-title"]').should(
  79. 'contain',
  80. 'Hello, Plugin!',
  81. );
  82. });
  83. it('Does not do much! Should fail', () => {
  84. expect(true).to.equal(false);
  85. });
  86. });
  87. }