<commit_before>const CssGenerator = require('code_manager/model/CssGenerator');
const HtmlGenerator = require('code_manager/model/HtmlGenerator');
const DomComponents = require('dom_components');
const Component = require('dom_components/model/Component');
const Editor = require('editor/model/Editor');
const CssComposer = require('css_composer');

module.exports = {
  run() {
    let comp;
    let dcomp;
    let obj;
    let em;
    let cc;

    describe('HtmlGenerator', () => {
      beforeEach(() => {
        em = new Editor();
        obj = new HtmlGenerator();
        dcomp = new DomComponents();
        comp = new Component(
          {},
          {
            em,
            componentTypes: dcomp.componentTypes
          }
        );
      });

      afterEach(() => {
        obj = null;
      });

      it('Build correctly one component', () => {
        expect(obj.build(comp)).toEqual('');
      });

      it('Build correctly empty component inside', () => {
        var m1 = comp.get('components').add({});
        expect(obj.build(comp)).toEqual('<div></div>');
      });

      it('Build correctly not empty component inside', () => {
        var m1 = comp.get('components').add({
          tagName: 'article',
          attributes: {
            'data-test1': 'value1',
            'data-test2': 'value2'
          }
        });
        expect(obj.build(comp)).toEqual(
          '<article data-test1="value1" data-test2="value2"></article>'
        );
      });

      it('Build correctly component with classes', () => {
        var m1 = comp.get('components').add({
          tagName: 'article',
          attributes: {
            'data-test1': 'value1',
            'data-test2': 'value2'
          }
        });
        ['class1', 'class2'].forEach(item => {
          m1.get('classes').add({ name: item });
        });
        expect(obj.build(comp)).toEqual(
          '<article data-test1="value1" data-test2="value2" class="class1 class2"></article>'
        );
      });
    });

    describe('CssGenerator', () => {
      var newCssComp = () => new CssComposer().init();
      beforeEach(() => {
        em = new Editor({});
        cc = em.get('CssComposer');
        obj = new CssGenerator();
        dcomp = new DomComponents();
        comp = new Component(
          {},
          {
            em,
            componentTypes: dcomp.componentTypes
          }
        );
      });

      afterEach(() => {
        obj = null;
      });

      it('Build correctly one component', () => {
        expect(obj.build(comp)).toEqual('');
      });

      it('Build correctly empty component inside', () => {
        var m1 = comp.get('components').add({ tagName: 'article' });
        expect(obj.build(comp)).toEqual('');
      });

      it('Build correctly component with style inside', () => {
        var m1 = comp.get('components').add({
          tagName: 'article',
          style: {
            prop1: 'value1',
            prop2: 'value2'
          }
        });
        expect(obj.build(comp)).toEqual(
          '#' + m1.cid + '{prop1:value1;prop2:value2;}'
        );
      });

      it('Build correctly component with class styled', () => {
        var m1 = comp.get('components').add({ tagName: 'article' });
        var cls1 = m1.get('classes').add({ name: 'class1' });

        var cssc = newCssComp();
        var rule = cssc.add(cls1);
        rule.set('style', { prop1: 'value1', prop2: 'value2' });

        expect(obj.build(comp, { cssc })).toEqual(
          '.class1{prop1:value1;prop2:value2;}'<commit_msg>Fix regressions<commit_after>const CssGenerator = require('code_manager/model/CssGenerator');
const HtmlGenerator = require('code_manager/model/HtmlGenerator');
const DomComponents = require('dom_components');
const Component = require('dom_components/model/Component');
const Editor = require('editor/model/Editor');
const CssComposer = require('css_composer');

module.exports = {
  run() {
    let comp;
    let dcomp;
    let obj;
    let em;
    let cc;

    describe('HtmlGenerator', () => {
      beforeEach(() => {
        em = new Editor();
        obj = new HtmlGenerator();
        dcomp = new DomComponents();
        comp = new Component(
          {},
          {
            em,
            componentTypes: dcomp.componentTypes
          }
        );
      });

      afterEach(() => {
        obj = null;
      });

      it('Build correctly one component', () => {
        expect(obj.build(comp)).toEqual('');
      });

      it('Build correctly empty component inside', () => {
        var m1 = comp.get('components').add({});
        expect(obj.build(comp)).toEqual('<div></div>');
      });

      it('Build correctly not empty component inside', () => {
        var m1 = comp.get('components').add({
          tagName: 'article',
          attributes: {
            'data-test1': 'value1',
            'data-test2': 'value2'
          }
        });
        expect(obj.build(comp)).toEqual(
          '<article data-test1="value1" data-test2="value2"></article>'
        );
      });

      it('Build correctly component with classes', () => {
        var m1 = comp.get('components').add({
          tagName: 'article',
          attributes: {
            'data-test1': 'value1',
            'data-test2': 'value2'
          }
        });
        ['class1', 'class2'].forEach(item => {
          m1.get('classes').add({ name: item });
        });
        expect(obj.build(comp)).toEqual(
          '<article data-test1="value1" data-test2="value2" class="class1 class2"></article>'
        );
      });
    });

    describe('CssGenerator', () => {
      var newCssComp = () => new CssComposer().init();
      beforeEach(() => {
        em = new Editor({});
        cc = em.get('CssComposer');
        obj = new CssGenerator();
        dcomp = new DomComponents();
        comp = new Component(
          {},
          {
            em,
            componentTypes: dcomp.componentTypes
          }
        );
      });

      afterEach(() => {
        obj = null;
      });

      it('Build correctly one component', () => {
        expect(obj.build(comp)).toEqual('');
      });

      it('Build correctly empty component inside', () => {
        var m1 = comp.get('components').add({ tagName: 'article' });
        expect(obj.build(comp)).toEqual('');
      });

      it('Build correctly component with style inside', () => {
        var m1 = comp.get('components').add({
          tagName: 'article',
          style: {
            prop1: 'value1',
            prop2: 'value2'
          }
        });
        expect(obj.build(comp)).toEqual(
          '#' + m1.getId() + '{prop1:value1;prop2:value2;}'
        );
      });

      it('Build correctly component with class styled', () => {
        var m1 = comp.get('components').add({ tagName: 'article' });
        var cls1 = m1.get('classes').add({ name: 'class1' });

        var cssc = newCssComp();
        var rule = cssc.add(cls1);
        rule.set('style', { prop1: 'value1', prop2: 'value2' });

        expect(obj.build(comp, { cssc })).toEqual(
          '.class1{prop1:value1;prop2:value2;}'
{'fraction_non_alphanumeric': 0.1740346950195859, 'fraction_numerical': 0.013710128707330722, 'mean_word_length': 1.9713216957605986, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 47, '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': '7239116', 'n_tokens_mistral': 2069, 'n_tokens_neox': 2063, 'n_words': 404}