example-page.cy.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. const installHelmChart = (path: string) => {
  6. cy.exec(
  7. `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}`,
  8. {
  9. failOnNonZeroExit: false,
  10. },
  11. )
  12. .get('[data-test="refresh-web-console"]', { timeout: 300000 })
  13. .should('exist')
  14. .then((result) => {
  15. cy.reload();
  16. cy.visit(`/dashboards`);
  17. cy.log('Error installing helm chart: ', result.stderr);
  18. cy.log('Successfully installed helm chart: ', result.stdout);
  19. });
  20. };
  21. const deleteHelmChart = (path: string) => {
  22. cy.exec(
  23. `cd ../../console-plugin-template && ${path} uninstall ${PLUGIN_TEMPLATE_NAME} -n ${PLUGIN_TEMPLATE_NAME} && oc delete namespaces ${PLUGIN_TEMPLATE_NAME}`,
  24. {
  25. failOnNonZeroExit: false,
  26. },
  27. ).then((result) => {
  28. cy.log('Error uninstalling helm chart: ', result.stderr);
  29. cy.log('Successfully uninstalled helm chart: ', result.stdout);
  30. });
  31. };
  32. describe('Console plugin template test', () => {
  33. before(() => {
  34. cy.login();
  35. if (!isLocalDevEnvironment) {
  36. console.log('this is not a local env, installig helm');
  37. cy.exec('cd ../../console-plugin-template && ./install_helm.sh', {
  38. failOnNonZeroExit: false,
  39. }).then((result) => {
  40. cy.log('Error installing helm binary: ', result.stderr);
  41. cy.log('Successfully installed helm binary in "/tmp" directory: ', result.stdout);
  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('contain', 'Hello, Plugin!');
  65. });
  66. });