jasmine.Ajax.withMock(() => {
      const responseMessage = `Pipeline 'up43' unlocked successfully.`;
      jasmine.Ajax.stubRequest(`/go/api/pipelines/up43/unlock`, undefined, 'POST').andReturn({
        responseText:    JSON.stringify({"message": responseMessage}),
        responseHeaders: {
          'Content-Type': 'application/vnd.go.cd.v1+json'
        },
        status:          200
      });

      const searchField = helper.findByDataTestId('search-box').get(0);
      expect(helper.find('.pipeline')).toHaveLength(2);

      $(searchField).val('up43');
      simulateEvent.simulate(searchField, 'input');
      m.redraw();

      expect(helper.find('.pipeline')).toHaveLength(1);

      expect(doCancelPolling).not.toHaveBeenCalled();
      expect(doRefreshImmediately).not.toHaveBeenCalled();

      simulateEvent.simulate(helper.find('.pipeline_locked').get(0), 'click');

      expect(doCancelPolling).toHaveBeenCalled();
      expect(doRefreshImmediately).toHaveBeenCalled();

      expect(helper.find('.pipeline_message')).toContainText(responseMessage);
      expect(helper.find('.pipeline_message')).toHaveClass("success");
    });
Beispiel #2
0
      it("should pause a pipeline", () => {
        const responseMessage = `Pipeline '${pipeline.name}' paused successfully.`;
        jasmine.Ajax.stubRequest(`/go/api/pipelines/${pipeline.name}/pause`, undefined, 'POST').andReturn({
          responseText:    JSON.stringify({"message": responseMessage}),
          responseHeaders: {
            'Content-Type': 'application/vnd.go.cd.v1+json'
          },
          status:          200
        });

        expect(doCancelPolling).not.toHaveBeenCalled();
        expect(doRefreshImmediately).not.toHaveBeenCalled();

        simulateEvent.simulate($root.find('.pause').get(0), 'click');
        $('.reveal input').val("test");

        doRefreshImmediately.and.callFake(() => pipeline.isPaused = true);
        simulateEvent.simulate($('.reveal .primary').get(0), 'click');

        expect(doCancelPolling).toHaveBeenCalled();
        expect(doRefreshImmediately).toHaveBeenCalled();

        expect($root.find('.pipeline_pause-message')).toBeInDOM();
        expect($root.find('.pipeline_message')).toContainText(responseMessage);
        expect($root.find('.pipeline_message')).toHaveClass("success");
      });
Beispiel #3
0
      it('should show modal appropriately when opened and closed multiple times', () => {
        stubTriggerOptions(pipelineName);
        const triggerWithOptionsButton = $root.find('.play_with_options');

        //open trigger with options modal
        expect($('.reveal:visible')).not.toBeInDOM();
        expect($('.pipeline_options-heading')).not.toContainText('Materials');

        simulateEvent.simulate(triggerWithOptionsButton.get(0), 'click');
        m.redraw();

        expect($('.reveal:visible')).toBeInDOM();
        expect($('.pipeline_options-heading')).toContainText('Materials');

        //close trigger with options modal
        $('.modal-buttons .button.save.secondary').click();

        //open again trigger with options modal
        expect($('.reveal:visible')).not.toBeInDOM();
        expect($('.pipeline_options-heading')).not.toContainText('Materials');

        simulateEvent.simulate(triggerWithOptionsButton.get(0), 'click');
        m.redraw();

        expect($('.reveal:visible')).toBeInDOM();
        expect($('.pipeline_options-heading')).toContainText('Materials');
      });
      it("should allow cloning an artifact store", () => {
        jasmine.Ajax.stubRequest(`/go/api/admin/artifact_stores/${dockerRegistryArtifactStoreJSON.id}`, undefined, 'GET').andReturn({
          responseText:    JSON.stringify(dockerRegistryArtifactStoreJSON),
          status:          200,
          responseHeaders: {
            'ETag':         '"foo"',
            'Content-Type': 'application/json'
          }
        });

        simulateEvent.simulate($root.find('.clone-button').get(0), 'click');
        m.redraw();

        const storeId = $('.reveal:visible .modal-body').find('[data-prop-name="id"]').get(0);
        $(storeId).val("foo-clone");
        simulateEvent.simulate(storeId, 'input');

        jasmine.Ajax.stubRequest('/go/api/admin/artifact_stores', undefined, 'POST').andReturn({
          responseText:    JSON.stringify({data: dockerRegistryArtifactStoreJSON}),
          status:          200,
          responseHeaders: {
            'Content-Type': 'application/json'
          }
        });

        simulateEvent.simulate($('.reveal:visible .modal-buttons').find('.save').get(0), 'click');

        const request = jasmine.Ajax.requests.at(jasmine.Ajax.requests.count() - 2);
        expect(request.url).toBe('/go/api/admin/artifact_stores');
        expect(request.method).toBe('POST');

        expect($('.success')).toContainText("The artifact store 'foo-clone' was cloned successfully");
      });
    it("it should display variable overriden message", () => {
      const valueInputField = helper.find('.environment-variables input').get(0);
      expect(valueInputField).toBeDisabled();

      expect(valueInputField).toHaveValue('*****');
      expect(helper.find('.reset')).not.toBeInDOM();

      simulateEvent.simulate(helper.find('.override').get(0), 'click');
      m.redraw();
      expect(valueInputField).not.toBeDisabled();
      expect(helper.find('.reset')).toBeInDOM();

      const newValue = "ldap";
      $(valueInputField).val(newValue);
      simulateEvent.simulate(valueInputField, 'input');
      m.redraw();

      expect(variables[0].value()).toBe(newValue);
      expect(valueInputField).toHaveValue(newValue);

      simulateEvent.simulate(helper.find('.reset').get(0), 'click');
      m.redraw();
      expect(valueInputField).toBeDisabled();
      expect(helper.find('.reset')).not.toBeInDOM();
    });
  it("should show appropriate modal for pausing a searched pipeline", () => {
    const searchField = helper.findByDataTestId('search-box').get(0);
    expect(helper.find('.pipeline')).toHaveLength(2);

    $(searchField).val('up42');
    simulateEvent.simulate(searchField, 'input');
    m.redraw();

    expect(helper.find('.pipeline')).toHaveLength(1);

    simulateEvent.simulate(helper.find('.pause').get(0), 'click');
    expect($('.modal-body').text()).toEqual('Specify a reason for pausing schedule on pipeline up42');

    //close specify pause cause popup for up42 pipeline
    Modal.destroyAll();

    $(searchField).val('up43');
    simulateEvent.simulate(searchField, 'input');
    m.redraw();

    expect(helper.find('.pipeline')).toHaveLength(1);

    simulateEvent.simulate(helper.find('.pause').get(0), 'click');
    expect($('.modal-body').text()).toEqual('Specify a reason for pausing schedule on pipeline up43');

    //close specify pause cause popup for up43 pipeline
    Modal.destroyAll();
  });
    jasmine.Ajax.withMock(() => {
      const responseMessage = `Pipeline 'up42' paused successfully.`;
      const pauseCause      = "test";

      jasmine.Ajax.stubRequest(`/go/api/pipelines/up42/pause`, undefined, 'POST').andReturn({
        responseText:    JSON.stringify({"message": responseMessage}),
        responseHeaders: {
          'Content-Type': 'application/vnd.go.cd.v1+json'
        },
        status:          200
      });

      simulateEvent.simulate(helper.find('.pause').get(0), 'click');
      expect($('.modal-body').text()).toEqual('Specify a reason for pausing schedule on pipeline up42');
      $('.reveal input').val(pauseCause);
      expect($('.reveal input')).toHaveValue(pauseCause);

      simulateEvent.simulate($('.reveal .primary').get(0), 'click');

      expect(helper.find('.pipeline_message')).toContainText(responseMessage);
      expect(helper.find('.pipeline_message')).toHaveClass("success");

      simulateEvent.simulate(helper.find('.pause').get(0), 'click');
      expect($('.reveal input')).toHaveValue('');

      Modal.destroyAll();
    });
Beispiel #8
0
      it("should not retain text entered when the pause popup is closed", () => {
        simulateEvent.simulate($root.find('.pause').get(0), 'click');
        expect($('.reveal:visible')).toBeInDOM();
        let pausePopupTextBox = $('.reveal input');
        pausePopupTextBox.val("test");
        $('.reveal .secondary').trigger('click');
        simulateEvent.simulate($root.find('.pause').get(0), 'click');
        pausePopupTextBox = $('.reveal input');

        expect(pausePopupTextBox).toHaveValue("");
      });
    it("should show success message when auth config is deleted", () => {
      jasmine.Ajax.stubRequest(`/go/api/admin/security/auth_configs/${authConfigJSON.id}`, undefined, 'DELETE').andReturn({
        responseText: JSON.stringify({message: 'Success!'}),
        status:       200
      });

      simulateEvent.simulate($root.find('.delete-button').get(0), 'click');
      m.redraw();
      simulateEvent.simulate($('.new-modal-container').find('.reveal:visible .delete-auth-config').get(0), 'click');
      m.redraw();

      expect($('.success')).toContainText('Success!');
    });
    it("should show error message when deletion of auth config fails", () => {
      jasmine.Ajax.stubRequest(`/go/api/admin/security/auth_configs/${  authConfigJSON.id}`, undefined, 'DELETE').andReturn({
        responseText: JSON.stringify({message: 'Boom!'}),
        status:       401
      });

      simulateEvent.simulate($root.find('.delete-auth-config-confirm').get(0), 'click');
      m.redraw();
      simulateEvent.simulate($('.new-modal-container').find('.reveal:visible .delete-auth-config').get(0), 'click');
      m.redraw();

      expect($('.alert')).toContainText('Boom!');
    });
      it("should show error message when deleting an artifact store fails", () => {
        jasmine.Ajax.stubRequest(`/go/api/admin/artifact_stores/${dockerRegistryArtifactStoreJSON.id}`, undefined, 'DELETE').andReturn({
          responseText:    JSON.stringify({message: 'Boom!'}),
          status:          400,
          responseHeaders: {
            'Content-Type': 'application/json'
          }
        });

        simulateEvent.simulate($root.find('.delete-button').get(0), 'click');
        m.redraw();
        simulateEvent.simulate($('.new-modal-container').find('.reveal:visible .delete-artifact-store').get(0), 'click');
        m.redraw();

        expect($('.alert')).toContainText('Boom!');
      });
      jasmine.Ajax.withMock(() => {
        const response = {
          "message": "boom!"
        };

        jasmine.Ajax.stubRequest('/go/api/data_sharing/settings', undefined, 'PATCH').andReturn({
          responseText:    JSON.stringify(response),
          status:          500,
          responseHeaders: {
            'Content-Type': 'application/vnd.go.cd.v1+json'
          }
        });

        expect(helper.find('.callout')).not.toBeInDOM();

        simulateEvent.simulate(helper.find('.update-consent').get(0), 'click');
        m.redraw();

        expect(helper.find('.callout')).toBeInDOM();
        expect(helper.find('.callout')).toHaveClass('alert');
        expect(helper.find('.callout')).toContainText(response.message);

        jasmine.clock().tick(5001);

        expect(helper.find('.callout')).not.toBeInDOM();
      });
 it('should show spinner and disable save button while artifact store is being loaded', () => {
   jasmine.Ajax.stubRequest(`/go/api/admin/artifact_stores/${dockerRegistryArtifactStoreJSON.id}`, undefined, 'GET');
   simulateEvent.simulate($root.find('.clone-button').get(0), 'click');
   m.redraw();
   expect($('.reveal:visible .page-spinner')).toBeInDOM();
   expect($('.reveal:visible .modal-buttons').find('.save').get(0)).toHaveAttr('disabled');
 });
    it("should change auth config view in modal on change of plugin from dropdown", () => {
      simulateEvent.simulate($root.find('.add-auth-config').get(0), 'click');
      m.redraw();

      expect($('.reveal .modal-body input[data-prop-name]')).not.toBeDisabled();
      expect($('.reveal .modal-body [data-prop-name=pluginId] option:selected').text()).toEqual(ldapPluginInfoJSON.about.name);
      expect($('.reveal .modal-body .form_item_block label').text()).toEqual("LDAP URI");

      $('.reveal [data-prop-name=pluginId]').val("cd.go.authorization.github");
      simulateEvent.simulate($('.reveal [data-prop-name=pluginId]').get(0), 'change');
      m.redraw();

      expect($('.reveal input[data-prop-name]')).not.toBeDisabled();
      expect($('.reveal .modal-body [data-prop-name=pluginId] option:selected').text()).toEqual(githubPluginInfoJSON.about.name);
      expect($('.reveal .modal-body .form_item_block label').text()).toEqual("GITHUB URL");
    });
      it("should change plugin view template in modal on change of plugin from dropdown", () => {
        simulateEvent.simulate($root.find('.add-artifact-store').get(0), 'click');
        m.redraw();

        expect($('.reveal .modal-body input[data-prop-name]')).not.toBeDisabled();
        expect($('.reveal .modal-body [data-prop-name=pluginId] option:selected').text()).toEqual(dockerRegistryPluginInfoJSON.about.name);
        expect($('.reveal .modal-body div.docker_registry_config').text()).toEqual("Docker Registry Url:");

        $('.reveal [data-prop-name=pluginId]').val("cd.go.example.artifactory");
        simulateEvent.simulate($('.reveal [data-prop-name=pluginId]').get(0), 'change');
        m.redraw();

        expect($('.reveal input[data-prop-name]')).not.toBeDisabled();
        expect($('.reveal .modal-body [data-prop-name=pluginId] option:selected').text()).toEqual(artifactoryPluginInfoJSON.about.name);
        expect($('.reveal .modal-body div.artifactory_store_config').text()).toEqual("Example");
      });
 it('should show modal when add button is clicked', () => {
   expect($root.find('.reveal:visible')).not.toBeInDOM();
   simulateEvent.simulate($root.find('.add-artifact-store').get(0), 'click');
   m.redraw();
   expect($('.reveal:visible')).toBeInDOM();
   expect($('.reveal:visible input[data-prop-name]')).not.toBeDisabled();
 });
    it("should show Connection Ok message on successful verification.", () => {
      jasmine.Ajax.stubRequest('/go/api/admin/internal/security/auth_configs/verify_connection', undefined, 'POST').andReturn({
        responseText: JSON.stringify(responseJSON()),
        status:       200
      });

      simulateEvent.simulate($root.find('.add-auth-config').get(0), 'click');

      const authConfigId = $('.reveal:visible .modal-body').find('[data-prop-name="id"]').get(0);
      $(authConfigId).val("ldap");
      simulateEvent.simulate(authConfigId, 'input');
      simulateEvent.simulate($('.reveal:visible .modal-buttons .verify-connection').get(0), 'click');
      m.redraw();
      expect($('.reveal:visible .modal-body .callout.success')).toContainText('Connection OK.');

    });
    it('should update the consent consent value on clicking save button', () => {
      expect(settings.allowed()).toBe(true);
      settings.toggleConsent();
      expect(settings.allowed()).toBe(false);

      simulateEvent.simulate(helper.find('.reset-consent').get(0), 'click');
      m.redraw();

      expect(settings.allowed()).toBe(true);

      jasmine.Ajax.withMock(() => {
        const updatedMetricsSettings = {
          "_embedded": {
            'allow': false, 'updated_by': 'Bob'
          }
        };
        jasmine.Ajax.stubRequest('/go/api/data_sharing/settings', undefined, 'PATCH').andReturn({
          responseText:    JSON.stringify(updatedMetricsSettings),
          status:          200,
          responseHeaders: {
            'Content-Type': 'application/vnd.go.cd.v1+json'
          }
        });

        expect(settings.allowed()).toBe(true);
        settings.toggleConsent();
        expect(settings.allowed()).toBe(false);

        simulateEvent.simulate(helper.find('.update-consent').get(0), 'click');
        m.redraw();

        expect(settings.allowed()).toBe(false);
      });
    });
 it("should render new modal to create auth config", () => {
   expect($root.find('.reveal:visible')).not.toBeInDOM();
   simulateEvent.simulate($root.find('.add-auth-config').get(0), 'click');
   m.redraw();
   expect($('.reveal:visible')).toBeInDOM();
   expect($('.reveal:visible input[data-prop-name]')).not.toBeDisabled();
 });
    it("should show error message on unsuccessful verification.", () => {

      jasmine.Ajax.stubRequest('/go/api/admin/internal/security/auth_configs/verify_connection', undefined, 'POST').andReturn({
        responseText: JSON.stringify({data: authConfigJSON, message: "Unable to connect ldap server."}),
        status:       412
      });

      simulateEvent.simulate($root.find('.add-auth-config').get(0), 'click');

      const authConfigId = $('.reveal:visible .modal-body').find('[data-prop-name="id"]').get(0);
      $(authConfigId).val("ldap");
      simulateEvent.simulate(authConfigId, 'input');

      simulateEvent.simulate($('.reveal:visible .modal-buttons .verify-connection').get(0), 'click');
      m.redraw();
      expect($('.reveal:visible .modal-body .callout.alert').text()).toEqual('Unable to connect ldap server.');
    });
    it("should keep the auth config expanded while edit modal is open", () => {
      jasmine.Ajax.stubRequest(`/go/api/admin/security/auth_configs/${  authConfigJSON.id}`, undefined, 'GET').andReturn({
        responseText: JSON.stringify(authConfigJSON),
        status:       200
      });

      expect($root.find('.plugin-config-read-only')).not.toHaveClass('show');
      simulateEvent.simulate($root.find('.auth-config-header').get(0), 'click');
      m.redraw();
      expect($root.find('.plugin-config-read-only')).toHaveClass('show');

      simulateEvent.simulate($root.find('.edit-auth-config').get(0), 'click');
      m.redraw();
      simulateEvent.simulate($('.new-modal-container').find('.reveal:visible .close-button span').get(0), 'click');
      m.redraw();
      expect($root.find('.plugin-config-read-only')).toHaveClass('show');
    });
    it('should show render modal and render auth config view for first plugin id', () => {
      simulateEvent.simulate($root.find('.add-auth-config').get(0), 'click');
      m.redraw();

      const pluginId = $('.reveal:visible .modal-body').find('[data-prop-name="pluginId"]').get(0);

      expect($(pluginId).val()).toEqual('cd.go.authorization.ldap');
    });
      it('should show modal and render view of first plugin id', () => {
        simulateEvent.simulate($root.find('.add-artifact-store').get(0), 'click');
        m.redraw();

        const pluginId = $('.reveal:visible .modal-body').find('[data-prop-name="pluginId"]').get(0);

        expect($(pluginId).val()).toEqual(dockerRegistryPluginInfoJSON.id);
      });
Beispiel #24
0
 it("should open up a modal when the analytics icon is clicked", () => {
   simulateEvent.simulate($root.find('.pipeline-analytics').get(0), 'click');
   m.redraw();
   expect($('.reveal:visible')).toBeInDOM();
   expect($(".frame-container")).toBeInDOM();
   const modalTitle = $('.modal-title:visible');
   expect(modalTitle).toHaveText("Analytics for pipeline: up42");
 });
Beispiel #25
0
 it("should close pause popup when escape is pressed", () => {
   simulateEvent.simulate($root.find('.pause').get(0), 'click');
   expect($('.reveal:visible')).toBeInDOM();
   const keydownEvent = $.Event("keydown");
   keydownEvent.key   = "Escape";
   $('body').trigger(keydownEvent);
   expect($('.reveal:visible')).not.toBeInDOM();
 });
    it("should show field specific error message on validation failed.", () => {
      jasmine.Ajax.stubRequest('/go/api/admin/internal/security/auth_configs/verify_connection', undefined, 'POST').andReturn({
        responseText: JSON.stringify(validationFailedJSON()),
        status:       422
      });

      simulateEvent.simulate($root.find('.add-auth-config').get(0), 'click');

      const authConfigId = $('.reveal:visible .modal-body').find('[data-prop-name="id"]').get(0);
      $(authConfigId).val("ldap");
      simulateEvent.simulate(authConfigId, 'input');

      simulateEvent.simulate($('.reveal:visible .modal-buttons .verify-connection').get(0), 'click');
      m.redraw();

      expect($('.reveal:visible .modal-body .callout.alert').text()).toEqual('Validation failed for the given Auth Config');
      expect($('.reveal:visible .modal-body .form_item_block span').text()).toEqual('LdapUrl must not be blank.');
    });
Beispiel #27
0
      it("should show appropriate header for trigger with options popup modal", () => {
        const pauseButton = $root.find('.play_with_options');

        simulateEvent.simulate(pauseButton.get(0), 'click');
        m.redraw();

        const modalTitle = $('.modal-title:visible');
        expect(modalTitle).toHaveText(`${pipeline.name} - Trigger`);
      });
Beispiel #28
0
      it("should show appropriate header for popup modal upon pause button click", () => {
        const pauseButton = $root.find('.pause');

        simulateEvent.simulate(pauseButton.get(0), 'click');
        m.redraw();

        const modalTitle = $('.modal-title:visible');
        expect(modalTitle).toHaveText(`Pause pipeline ${pipeline.name}`);
      });
    it("should add a new task", () => {
      expect(tasks().countTask()).toBe(5);
      expect($root.find('.task-definition')).toHaveLength(5);

      simulateEvent.simulate($root.find('.task-selector>div>.add-button').get(0), 'click');
      m.redraw();

      expect(tasks().countTask()).toBe(6);
      expect($root.find('.task-definition')).toHaveLength(6);
    });
    it("should display error message if fails to fetch auth config", () => {
      jasmine.Ajax.stubRequest(`/go/api/admin/security/auth_configs/${  authConfigJSON.id}`, undefined, 'GET').andReturn({
        responseText: JSON.stringify({message: 'Boom!'}),
        status:       401
      });

      simulateEvent.simulate($root.find('.edit-auth-config').get(0), 'click');

      expect($('.alert')).toContainText('Boom!');
    });