example-page.cy.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 = Cypress.config('baseUrl').includes('localhost');
  5. export const guidedTour = {
  6. close: () => {
  7. cy.get('body').then(($body) => {
  8. if ($body.find(`[data-test="guided-tour-modal"]`).length > 0) {
  9. cy.get(`[data-test="tour-step-footer-secondary"]`).contains('Skip tour').click();
  10. }
  11. });
  12. },
  13. isOpen: () => {
  14. cy.get('body').then(($body) => {
  15. if ($body.find(`[data-test="guided-tour-modal"]`).length > 0) {
  16. cy.get(`[data-test="guided-tour-modal"]`).should('be.visible');
  17. }
  18. });
  19. },
  20. };
  21. const installHelmChart = (path: string) => {
  22. cy.exec(
  23. `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}`,
  24. {
  25. failOnNonZeroExit: false,
  26. },
  27. )
  28. .get('[data-test="refresh-web-console"]', { timeout: 300000 })
  29. .should('exist')
  30. .then((result) => {
  31. cy.reload();
  32. cy.visit(`/dashboards`);
  33. cy.log('Error installing helm chart: ', result.stderr);
  34. cy.log('Successfully installed helm chart: ', result.stdout);
  35. });
  36. };
  37. const deleteHelmChart = (path: string) => {
  38. cy.exec(
  39. `cd ../../console-plugin-template && ${path} uninstall ${PLUGIN_TEMPLATE_NAME} -n ${PLUGIN_TEMPLATE_NAME} && oc delete namespaces ${PLUGIN_TEMPLATE_NAME}`,
  40. {
  41. failOnNonZeroExit: false,
  42. },
  43. ).then((result) => {
  44. cy.log('Error uninstalling helm chart: ', result.stderr);
  45. cy.log('Successfully uninstalled helm chart: ', result.stdout);
  46. });
  47. };
  48. describe('Console plugin template test', () => {
  49. before(() => {
  50. cy.login();
  51. guidedTour.isOpen();
  52. guidedTour.close();
  53. if (!isLocalDevEnvironment) {
  54. console.log('this is not a local env, installig helm');
  55. cy.exec('cd ../../console-plugin-template && ./install_helm.sh', {
  56. failOnNonZeroExit: false,
  57. }).then((result) => {
  58. cy.log('Error installing helm binary: ', result.stderr);
  59. cy.log('Successfully installed helm binary in "/tmp" directory: ', result.stdout);
  60. installHelmChart('/tmp/helm');
  61. });
  62. } else {
  63. console.log('this is a local env, not installing helm');
  64. installHelmChart('helm');
  65. }
  66. });
  67. afterEach(() => {
  68. checkErrors();
  69. });
  70. after(() => {
  71. if (!isLocalDevEnvironment) {
  72. deleteHelmChart('/tmp/helm');
  73. } else {
  74. deleteHelmChart('helm');
  75. }
  76. cy.logout();
  77. });
  78. it('Verify the example page title', () => {
  79. cy.get('[data-quickstart-id="qs-nav-home"]').click();
  80. cy.get('[data-test="nav"]').contains('Plugin Example').click();
  81. cy.url().should('include', '/example');
  82. cy.get('[data-test="example-page-title"]').should('contain', 'Hello, Plugin!');
  83. });
  84. });