<commit_before>describe('DialogFieldRefresh', function() {
  beforeEach(function() {
    module('app.states');
    bard.inject('CollectionsApi', 'Notifications', 'AutoRefresh', 'DialogFieldRefresh');
  });

  describe('#refreshSingleDialogField with values not as an object', function() {
    var dialog1 = {name: 'dialog1', default_value: 'name1'};
    var dialog2 = {name: 'dialog2', default_value: 'name2'};
    var allDialogFields = [dialog1, dialog2];
    var collectionsApiSpy;
    var triggerAutoRefreshSpy;

    describe('when the API call is successful', function() {
      var successResponse;

      describe('when the dialogfield type is DialogFieldDateControl', function() {
        beforeEach(function() {
          successResponse = {
            result: {
              dialog1: {
                type: 'DialogFieldDateControl',
                options: 'options',
                read_only: false,
                required: false,
                values: '2016-01-02T00:00:00+00:00Z'
              }
            }
          };

          triggerAutoRefreshSpy = sinon.stub(DialogFieldRefresh, 'triggerAutoRefresh');
          collectionsApiSpy = sinon.stub(CollectionsApi, 'post').returns(Promise.resolve(successResponse));
        });

        it('updates the attributes for the dialog field', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(dialog1.options).to.eq('options');
          expect(dialog1.read_only).to.be.false;
          expect(dialog1.required).to.be.false;
          expect(dialog1.default_value).to.eq(new Date('2016-01-02T00:00:00+00:00Z'));
        });

        it('triggers an auto-refresh', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(triggerAutoRefreshSpy).to.have.been.called;
        });
      });

      describe('when the dialogfield type is DialogFieldDateTimeControl', function() {
        beforeEach(function() {
          successResponse = {
            result: {
              dialog1: {
                type: 'DialogFieldDateTimeControl',
                options: 'options',
                read_only: false,
                required: false,
                values: '2016-01-02T12:34:00+00:00Z'
              }
            }
          };

          triggerAutoRefreshSpy = sinon.stub(DialogFieldRefresh, 'triggerAutoRefresh');
          collectionsApiSpy = sinon.stub(CollectionsApi, 'post').returns(Promise.resolve(successResponse));
        });

        it('updates the attributes for the dialog field', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(dialog1.options).to.eq('options');
          expect(dialog1.read_only).to.be.false;
          expect(dialog1.required).to.be.false;
          expect(dialog1.default_value).to.eq('Text');
          expect(dialog1.default_value).to.eq(new Date('2016-01-02T12:34:00+00:00Z'));
        });

        it('triggers an auto-refresh', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(triggerAutoRefreshSpy).to.have.been.called;
        });
      });

      describe('when the dialogfield type is DialogFieldCheckBox', function() {
        beforeEach(function() {
          successResponse = {
            result: {
              dialog1: {
                type: 'DialogFieldCheckBox',
                options: 'options',
                read_only: false,
                required: false,
                values: 'f'
              }
            }
          };

          triggerAutoRefreshSpy = sinon.stub(DialogFieldRefresh, 'triggerAutoRefresh');
          collectionsApiSpy = sinon.stub(CollectionsApi, 'post').returns(Promise.resolve(successResponse));
        });

        it('updates the attributes for the dialog field', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(dialog1.options).to.eq('options');
          expect(dialog1.read_only).to.be.false;
          expect(dialog1.required).to.be.false;
          expect(dialog1.default_value).to.eq('f');
        });

        it('triggers an auto-refresh', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(triggerAutoRefreshSpy).to.have.been.called;
        });
      });

      describe('when the dialogfield type is anything else', function() {
        beforeEach(function() {
          successResponse = {
            result: {
              dialog1: {
                data_type: 'string',
                options: 'options',
                read_only: false,
                required: false,
                values: 'Text'
              }
            }
          };

          triggerAutoRefreshSpy = sinon.stub(DialogFieldRefresh, 'triggerAutoRefresh');
          collectionsApiSpy = sinon.stub(CollectionsApi, 'post').returns(Promise.resolve(successResponse));
        });
        it('allows a dialog field to be refreshed', () => {
           const dialogData = {
             'dialog1': 'value1',
             'dialog2': 'value2'
           };
            return DialogFieldRefresh.refreshDialogField(dialogData,['dialog1'],'/test/1',1234).then((response) => {
              expect(collectionsApiSpy).to.have.been.calledWith('/test/1', 1234, {});
            })
        });
        it('updates the attributes for the dialog field', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(dialog1.data_type).to.eq('string');
          expect(dialog1.options).to.eq('options');
          expect(dialog1.read_only).to.be.false;
          expect(dialog1.required).to.be.false;
          expect(dialog1.default_value).to.eq('Text');
        });

        it('triggers an auto-refresh', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(triggerAutoRefreshSpy).to.have.been.called;
        });
      });
    });
  });

  describe('#refreshSingleDialogField with values as an object', function() {
    var dialog1 = {name: 'dialog1', default_value: 'name1'};
    var dialog2 = {name: 'dialog2', default_value: 'name2'};<commit_msg>Added final field that is expected with Post<commit_after>describe('DialogFieldRefresh', function() {
  beforeEach(function() {
    module('app.states');
    bard.inject('CollectionsApi', 'Notifications', 'AutoRefresh', 'DialogFieldRefresh');
  });

  describe('#refreshSingleDialogField with values not as an object', function() {
    var dialog1 = {name: 'dialog1', default_value: 'name1'};
    var dialog2 = {name: 'dialog2', default_value: 'name2'};
    var allDialogFields = [dialog1, dialog2];
    var collectionsApiSpy;
    var triggerAutoRefreshSpy;

    describe('when the API call is successful', function() {
      var successResponse;

      describe('when the dialogfield type is DialogFieldDateControl', function() {
        beforeEach(function() {
          successResponse = {
            result: {
              dialog1: {
                type: 'DialogFieldDateControl',
                options: 'options',
                read_only: false,
                required: false,
                values: '2016-01-02T00:00:00+00:00Z'
              }
            }
          };

          triggerAutoRefreshSpy = sinon.stub(DialogFieldRefresh, 'triggerAutoRefresh');
          collectionsApiSpy = sinon.stub(CollectionsApi, 'post').returns(Promise.resolve(successResponse));
        });

        it('updates the attributes for the dialog field', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(dialog1.options).to.eq('options');
          expect(dialog1.read_only).to.be.false;
          expect(dialog1.required).to.be.false;
          expect(dialog1.default_value).to.eq(new Date('2016-01-02T00:00:00+00:00Z'));
        });

        it('triggers an auto-refresh', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(triggerAutoRefreshSpy).to.have.been.called;
        });
      });

      describe('when the dialogfield type is DialogFieldDateTimeControl', function() {
        beforeEach(function() {
          successResponse = {
            result: {
              dialog1: {
                type: 'DialogFieldDateTimeControl',
                options: 'options',
                read_only: false,
                required: false,
                values: '2016-01-02T12:34:00+00:00Z'
              }
            }
          };

          triggerAutoRefreshSpy = sinon.stub(DialogFieldRefresh, 'triggerAutoRefresh');
          collectionsApiSpy = sinon.stub(CollectionsApi, 'post').returns(Promise.resolve(successResponse));
        });

        it('updates the attributes for the dialog field', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(dialog1.options).to.eq('options');
          expect(dialog1.read_only).to.be.false;
          expect(dialog1.required).to.be.false;
          expect(dialog1.default_value).to.eq('Text');
          expect(dialog1.default_value).to.eq(new Date('2016-01-02T12:34:00+00:00Z'));
        });

        it('triggers an auto-refresh', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(triggerAutoRefreshSpy).to.have.been.called;
        });
      });

      describe('when the dialogfield type is DialogFieldCheckBox', function() {
        beforeEach(function() {
          successResponse = {
            result: {
              dialog1: {
                type: 'DialogFieldCheckBox',
                options: 'options',
                read_only: false,
                required: false,
                values: 'f'
              }
            }
          };

          triggerAutoRefreshSpy = sinon.stub(DialogFieldRefresh, 'triggerAutoRefresh');
          collectionsApiSpy = sinon.stub(CollectionsApi, 'post').returns(Promise.resolve(successResponse));
        });

        it('updates the attributes for the dialog field', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(dialog1.options).to.eq('options');
          expect(dialog1.read_only).to.be.false;
          expect(dialog1.required).to.be.false;
          expect(dialog1.default_value).to.eq('f');
        });

        it('triggers an auto-refresh', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(triggerAutoRefreshSpy).to.have.been.called;
        });
      });

      describe('when the dialogfield type is anything else', function() {
        beforeEach(function() {
          successResponse = {
            result: {
              dialog1: {
                data_type: 'string',
                options: 'options',
                read_only: false,
                required: false,
                values: 'Text'
              }
            }
          };

          triggerAutoRefreshSpy = sinon.stub(DialogFieldRefresh, 'triggerAutoRefresh');
          collectionsApiSpy = sinon.stub(CollectionsApi, 'post').returns(Promise.resolve(successResponse));
        });
        it('allows a dialog field to be refreshed', () => {
           const dialogData = {
             'dialog1': 'value1',
             'dialog2': 'value2'
           };
            return DialogFieldRefresh.refreshDialogField(dialogData,['dialog1'],'/test/1',1234).then((response) => {
              expect(collectionsApiSpy).to.have.been.calledWith('/test/1',
              1234,
              {},
              '{"action":"refresh_dialog_fields","resource":{"dialog_fields":{"dialog1":"value1","dialog2":"value2"},"fields":["dialog1"]}}');
            })
        });
        it('updates the attributes for the dialog field', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(dialog1.data_type).to.eq('string');
          expect(dialog1.options).to.eq('options');
          expect(dialog1.read_only).to.be.false;
          expect(dialog1.required).to.be.false;
          expect(dialog1.default_value).to.eq('Text');
        });

        it('triggers an auto-refresh', function(done) {
          DialogFieldRefresh.refreshSingleDialogField(allDialogFields, dialog1, 'the_url', 123);
          done();
          expect(triggerAutoRefreshSpy).to.have.been.called;
        });
      });
    });
  });

  describe('#refreshSingleDialogField with values as an object', function() {
    var dialog1 = {name: 'dialog1', default_value: 'name1'};
    var dialog2 = {name: 'dialog2', default_value: 'name2'};
{'fraction_non_alphanumeric': 0.12783474290846494, 'fraction_numerical': 0.023576079634757878, 'mean_word_length': 2.2870848708487084, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6955387', 'n_tokens_mistral': 3777, 'n_tokens_neox': 3563, 'n_words': 611}