example-page.cy.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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(`/dashboards`);
  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. describe('Console plugin template test', () => {
  30. before(() => {
  31. cy.login();
  32. if (!isLocalDevEnvironment) {
  33. console.log('this is not a local env, installig helm');
  34. cy.exec('cd ../../console-plugin-template && ./install_helm.sh', {
  35. failOnNonZeroExit: false,
  36. }).then((result) => {
  37. cy.log('Error installing helm binary: ', result.stderr);
  38. cy.log(
  39. 'Successfully installed helm binary in "/tmp" directory: ',
  40. result.stdout,
  41. );
  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('[data-test="example-page-title"]').should(
  65. 'contain',
  66. 'Hello, Plugin!',
  67. );
  68. });
  69. });