example-page.cy.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. if (!Cypress.env('OPENSHIFT_CI') || Cypress.env('PLUGIN_TEMPLATE_PULL_SPEC')) {
  30. describe('Console plugin template test', () => {
  31. before(() => {
  32. cy.login();
  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(
  40. 'Successfully installed helm binary in "/tmp" directory: ',
  41. result.stdout,
  42. );
  43. installHelmChart('/tmp/helm');
  44. });
  45. } else {
  46. console.log('this is a local env, not installing helm');
  47. installHelmChart('helm');
  48. }
  49. });
  50. afterEach(() => {
  51. checkErrors();
  52. cy.logout();
  53. });
  54. after(() => {
  55. cy.logout();
  56. if (!isLocalDevEnvironment) {
  57. deleteHelmChart('/tmp/helm');
  58. } else {
  59. deleteHelmChart('helm');
  60. }
  61. });
  62. it('Verify the example page title', () => {
  63. cy.get('[data-quickstart-id="qs-nav-home"]').click();
  64. cy.get('[data-test="nav"]').contains('Plugin Example').click();
  65. cy.url().should('include', '/example');
  66. cy.get('[data-test="example-page-title"]').should(
  67. 'contain',
  68. 'Hello, Plugin!',
  69. );
  70. });
  71. });
  72. }