example-page.cy.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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: any) => {
  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: any) => {
  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. });
  53. after(() => {
  54. cy.logout();
  55. if (!isLocalDevEnvironment) {
  56. deleteHelmChart('/tmp/helm');
  57. } else {
  58. deleteHelmChart('helm');
  59. }
  60. });
  61. it('Verify the url', () => {
  62. cy.url().should('include', '/example');
  63. });
  64. it('Verify the example page title', () => {
  65. cy.get('[data-quickstart-id="qs-nav-home"]').click();
  66. cy.get('[data-test="nav"]').contains('Plugin Example').click();
  67. cy.get('[data-test="example-page-title"]').should(
  68. 'contain',
  69. 'Hello, Plugin!',
  70. );
  71. });
  72. });
  73. }