<commit_before>const PropertySelectView = require('style_manager/view/PropertySelectView');
const Property = require('style_manager/model/Property');
const Component = require('dom_components/model/Component');

module.exports = {
  run() {

      describe('PropertySelectView', () => {

        var component;
        var $fixtures;
        var $fixture;
        var target;
        var model;
        var view;
        var propTarget;
        var options;
        var propName = 'testprop';
        var propValue = 'test1value';
        var defValue = 'test2value';
        var options = [
              {value: 'test1value', style: 'test:style'},
              {name: 'test2', value: 'test2value'}
            ];

        before(() => {
          $fixtures  = $("#fixtures");
          $fixture   = $('<div class="sm-fixture"></div>');
        });

        beforeEach(() => {
          propTarget = Object.assign({}, Backbone.Events);
          target = new Component();
          component = new Component();
          model = new Property({
            type: 'select',
            list: options,
            property: propName
          });
          propTarget.model = component;
          view = new PropertySelectView({
            model,
            propTarget
          });
          $fixture.empty().appendTo($fixtures);
          view.render();
          $fixture.html(view.el);
        });

        afterEach(() => {
          //view.remove(); // strange errors ???
        });

        after(() => {
          $fixture.remove();
          component = null;
        });

        it('Rendered correctly', () => {
          var prop = view.el;
          expect($fixture.get(0).querySelector('.property')).toExist();
          expect(prop.querySelector('.label')).toExist();
          expect(prop.querySelector('.field')).toExist();
        });

        it('Select rendered', () => {
          var prop = view.el;
          expect(prop.querySelector('select')).toExist();
        });

        it('Options rendered', () => {
          var select = view.el.querySelector('select');
          expect(select.children.length).toEqual(options.length);
        });

        it('Options rendered correctly', () => {
          var select = view.el.querySelector('select');
          var children = select.children;
          expect(children[0].value).toEqual(options[0].value);
          expect(children[1].value).toEqual(options[1].value);
          expect(children[0].textContent).toEqual(options[0].value);
          expect(children[1].textContent).toEqual(options[1].name);
          expect(children[0].getAttribute('style')).toEqual(options[0].style);
          expect(children[1].getAttribute('style')).toEqual(null);
        });

        it('Input should exist', () => {
          expect(view.input).toExist();
        });

        it('Input value is empty', () => {
          expect(view.model.get('value')).toNotExist();
        });

        it('Update model on input change', () => {
          view.getInputEl().value = propValue;
          view.inputValueChanged();
          expect(view.model.get('value')).toEqual(propValue);
        });

        it('Update input on value change', () => {
          view.model.set('value', propValue);
          expect(view.getInputValue()).toEqual(propValue);
        });

        it('Update target on value change', () => {
          view.selectedComponent = component;
          view.model.set('value', propValue);
          var compStyle = view.selectedComponent.get('style');
          var assertStyle = {};
          assertStyle[propName] = propValue;
          expect(compStyle).toEqual(assertStyle);
        });

        describe('With target setted', () => {

          beforeEach(() => {
            target.model = component;
            view = new PropertySelectView({
              model,
              propTarget: target
            });
            $fixture.empty().appendTo($fixtures);
            view.render();
            $fixture.html(view.el);
          });

          it('Update value and input on target swap', () => {
            var style = {};
            style[propName] = propValue;
            component.set('style', style);
            view.propTarget.trigger('update');
            expect(view.model.get('value')).toEqual(propValue);
            expect(view.getInputValue()).toEqual(propValue);
          });

          it('Update value after multiple swaps', () => {
            var style = {};
            style[propName] = propValue;
            component.set('style', style);
            view.propTarget.trigger('update');
            style[propName] = 'test2value';
            component.set('style', style);
            view.propTarget.trigger('update');
            expect(view.model.get('value')).toEqual('test2value');
            expect(view.getInputValue()).toEqual('test2value');
          });

        })

        describe('Init property', () => {

          beforeEach(() => {
            component = new Component();
            model = new Property({
              type: 'select',
              list: options,
              defaults: defValue,
              property: propName
            });
            view = new PropertySelectView({
              model
            });
            $fixture.empty().appendTo($fixtures);
            view.render();
            $fixture.html(view.el);
          });

          it('Value as default', () => {
            expect(view.model.get('value')).toEqual(defValue);
          });

          it('Empty value as default', () => {
            options = [
                {value: '', name: 'test'},
                {value: 'test1value', name: 'test1'},
                {value: 'test2value', name: 'test2'},
                {value: '', name: 'TestDef'}
              ];
            component = new Component();
            model = new Property({
              type: 'select',
              list: options,
              defaults: '',
              property: 'emptyDefault'
            });
            view = new PropertySelectView({
              model
            });
            view.render();
            $fixture.html(view.el);
            expect(view.getInputValue()).toEqual('');
          });

          it('Input value is as default', () => {
            expect(view.model.getDefaultValue()).toEqual(defValue);
          });

        });

    });
  }
};<commit_msg>Fix select property view tests<commit_after>const PropertySelectView = require('style_manager/view/PropertySelectView');
const Property = require('style_manager/model/Property');
const Component = require('dom_components/model/Component');

module.exports = {
  run() {

      describe('PropertySelectView', () => {

        var component;
        var fixtures;
        var target;
        var model;
        var view;
        var propTarget;
        var options;
        var propName = 'testprop';
        var propValue = 'test1value';
        var defValue = 'test2value';
        var options = [
              {value: 'test1value', style: 'test:style'},
              {name: 'test2', value: 'test2value'}
            ];

        beforeEach(() => {
          propTarget = Object.assign({}, Backbone.Events);
          target = new Component();
          component = new Component();
          model = new Property({
            type: 'select',
            list: options,
            property: propName
          });
          propTarget.model = component;
          view = new PropertySelectView({
            model,
            propTarget
          });
          document.body.innerHTML = '<div id="fixtures"></div>';
          fixtures = document.body.firstChild;
          view.render();
          fixtures.appendChild(view.el);
        });

        afterEach(() => {
          //view.remove(); // strange errors ???
        });

        after(() => {
          component = null;
        });

        it('Rendered correctly', () => {
          var prop = view.el;
          expect(fixtures.querySelector('.property')).toExist();
          expect(prop.querySelector('.label')).toExist();
          expect(prop.querySelector('.field')).toExist();
        });

        it('Select rendered', () => {
          var prop = view.el;
          expect(prop.querySelector('select')).toExist();
        });

        it('Options rendered', () => {
          var select = view.el.querySelector('select');
          expect(select.children.length).toEqual(options.length);
        });

        it('Options rendered correctly', () => {
          var select = view.el.querySelector('select');
          var children = select.children;
          expect(children[0].value).toEqual(options[0].value);
          expect(children[1].value).toEqual(options[1].value);
          expect(children[0].textContent).toEqual(options[0].value);
          expect(children[1].textContent).toEqual(options[1].name);
          expect(children[0].getAttribute('style')).toEqual(options[0].style);
          expect(children[1].getAttribute('style')).toEqual(null);
        });

        it('Input should exist', () => {
          expect(view.input).toExist();
        });

        it('Input value is empty', () => {
          expect(view.model.get('value')).toNotExist();
        });

        it('Update model on input change', () => {
          view.getInputEl().value = propValue;
          view.inputValueChanged();
          expect(view.model.get('value')).toEqual(propValue);
        });

        it('Update input on value change', () => {
          view.model.set('value', propValue);
          expect(view.getInputValue()).toEqual(propValue);
        });

        it('Update target on value change', () => {
          view.selectedComponent = component;
          view.model.set('value', propValue);
          var compStyle = view.selectedComponent.get('style');
          var assertStyle = {};
          assertStyle[propName] = propValue;
          expect(compStyle).toEqual(assertStyle);
        });

        describe('With target setted', () => {

          beforeEach(() => {
            target.model = component;
            view = new PropertySelectView({
              model,
              propTarget: target
            });
            fixtures.innerHTML = '';
            view.render();
            fixtures.appendChild(view.el);
          });

          it('Update value and input on target swap', () => {
            var style = {};
            style[propName] = propValue;
            component.set('style', style);
            view.propTarget.trigger('update');
            expect(view.model.get('value')).toEqual(propValue);
            expect(view.getInputValue()).toEqual(propValue);
          });

          it('Update value after multiple swaps', () => {
            var style = {};
            style[propName] = propValue;
            component.set('style', style);
            view.propTarget.trigger('update');
            style[propName] = 'test2value';
            component.set('style', style);
            view.propTarget.trigger('update');
            expect(view.model.get('value')).toEqual('test2value');
            expect(view.getInputValue()).toEqual('test2value');
          });

        })

        describe('Init property', () => {

          beforeEach(() => {
            component = new Component();
            model = new Property({
              type: 'select',
              list: options,
              defaults: defValue,
              property: propName
            });
            view = new PropertySelectView({
              model
            });
            fixtures.innerHTML = '';
            view.render();
            fixtures.appendChild(view.el);
          });

          it('Value as default', () => {
            expect(view.model.get('value')).toEqual(defValue);
          });

          it('Empty value as default', () => {
            options = [
                {value: '', name: 'test'},
                {value: 'test1value', name: 'test1'},
                {value: 'test2value', name: 'test2'},
                {value: '', name: 'TestDef'}
              ];
            component = new Component();
            model = new Property({
              type: 'select',
              list: options,
              defaults: '',
              property: 'emptyDefault'
            });
            view = new PropertySelectView({
              model
            });
            view.render();
            fixtures.innerHTML = '';
            fixtures.appendChild(view.el);
            expect(view.getInputValue()).toEqual('');
          });

          it('Input value is as default', () => {
            expect(view.model.getDefaultValue()).toEqual(defValue);
          });

        });

    });
  }
};
{'fraction_non_alphanumeric': 0.1527035523420308, 'fraction_numerical': 0.003693806978937441, 'mean_word_length': 1.7132196162046909, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 52, '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': '4818294', 'n_tokens_mistral': 3197, 'n_tokens_neox': 3208, 'n_words': 582}