<commit_before>import { expect } from 'chai';
import { spy } from 'sinon';
import React from 'react';
import { mount } from 'enzyme';
import WidgetFrame from '../../lib/components/WidgetFrame';
import DefaultFrame from '../../lib/components/DefaultFrame';
import TestCustomFrame from '../fake/TestCustomFrame';
import ContainerWithDndContext from '../fake/ContainerWithDndContext';

describe('<WidgetFrame />', () => {
  it('Default frame should be used when customized frame is not provided', () => {
    const onAdd = spy();
    const layout = {};
    const rowIndex = 1;
    const columnIndex = 2;
    const OriginalWidgetFrame = WidgetFrame.DecoratedComponent;
    const identity = (el) => el;
    const component = mount(
      <ContainerWithDndContext>
        <OriginalWidgetFrame
          layout={layout}
          rowIndex={rowIndex}
          columnIndex={columnIndex}
          onAdd={onAdd}
          editable
          connectDragSource={identity}
          connectDropTarget={identity}
        />
      </ContainerWithDndContext>
    );
    expect(component.find(DefaultFrame)).to.have.length(1);
  });

  it('DefaultFrame should be provided with necessary props', () => {
    const children = [];
    const editable = false;
    const onRemove = () => {};
    const title = 'Widget Title';
    const OriginalWidgetFrame = WidgetFrame.DecoratedComponent;
    const identity = (el) => el;
    const component = mount(
      <ContainerWithDndContext>
        <OriginalWidgetFrame
          children={children}
          editable={editable}
          onRemove={onRemove}
          title={title}
          connectDragSource={identity}
          connectDropTarget={identity}
        />
      </ContainerWithDndContext>
    );
    expect(component.find(DefaultFrame).first().prop('children')).to.equal(children);
    expect(component.find(DefaultFrame).first().prop('editable')).to.equal(editable);
    expect(component.find(DefaultFrame).first().prop('title')).to.equal(title);
  });

  it('DefaultFrame onRemove should be called when close is clicked', () => {
    const children = [];
    const editable = false;
    const onRemove = spy();
    const title = 'Widget Title';
    const layout = {
      rows: [{
        columns: [{
          className: 'col-md-4',
          widgets: [{ name: 'HelloWorld' }],
        }],
      }],
    };

    const newLayout = {
      rows: [{
        columns: [{
          className: 'col-md-4',
          widgets: [],
        }],
      }],
    };

    const OriginalWidgetFrame = WidgetFrame.DecoratedComponent;
    const identity = (el) => el;
    const component = mount(
      <ContainerWithDndContext>
        <OriginalWidgetFrame
          layout={layout}
          rowIndex={0}
          columnIndex={0}
          widgetIndex={0}
          children={children}
          editable={editable}
          onRemove={onRemove}
          title={title}
          editable
          connectDragSource={identity}
          connectDropTarget={identity}
        />
      </ContainerWithDndContext>
    );
    component.find('a.remove').simulate('click');
    console.log(JSON.stringify(newLayout));
    console.log(JSON.stringify(onRemove.lastCall.args[0]));
    expect(onRemove.calledWithExactly(newLayout)).to.equal(true);
  });
<commit_msg>updated spec<commit_after>import { expect } from 'chai';
import { spy } from 'sinon';
import React from 'react';
import { mount } from 'enzyme';
import WidgetFrame from '../../lib/components/WidgetFrame';
import DefaultFrame from '../../lib/components/DefaultFrame';
import TestCustomFrame from '../fake/TestCustomFrame';
import ContainerWithDndContext from '../fake/ContainerWithDndContext';

describe('<WidgetFrame />', () => {
  it('Default frame should be used when customized frame is not provided', () => {
    const onAdd = spy();
    const layout = {};
    const rowIndex = 1;
    const columnIndex = 2;
    const OriginalWidgetFrame = WidgetFrame.DecoratedComponent;
    const identity = (el) => el;
    const component = mount(
      <ContainerWithDndContext>
        <OriginalWidgetFrame
          layout={layout}
          rowIndex={rowIndex}
          columnIndex={columnIndex}
          onAdd={onAdd}
          editable
          connectDragSource={identity}
          connectDropTarget={identity}
        />
      </ContainerWithDndContext>
    );
    expect(component.find(DefaultFrame)).to.have.length(1);
  });

  it('DefaultFrame should be provided with necessary props', () => {
    const children = [];
    const editable = false;
    const onRemove = () => {};
    const title = 'Widget Title';
    const OriginalWidgetFrame = WidgetFrame.DecoratedComponent;
    const identity = (el) => el;
    const component = mount(
      <ContainerWithDndContext>
        <OriginalWidgetFrame
          children={children}
          editable={editable}
          onRemove={onRemove}
          title={title}
          connectDragSource={identity}
          connectDropTarget={identity}
        />
      </ContainerWithDndContext>
    );
    expect(component.find(DefaultFrame).first().prop('children')).to.equal(children);
    expect(component.find(DefaultFrame).first().prop('editable')).to.equal(editable);
    expect(component.find(DefaultFrame).first().prop('title')).to.equal(title);
  });

  it('DefaultFrame onRemove should be called when close is clicked', () => {
    const children = [];
    const editable = false;
    const onRemove = spy();
    const title = 'Widget Title';
    const layout = {
      rows: [{
        columns: [{
          className: 'col-md-4',
          widgets: [{ name: 'HelloWorld' }],
        }],
      }],
    };

    const OriginalWidgetFrame = WidgetFrame.DecoratedComponent;
    const identity = (el) => el;
    const component = mount(
      <ContainerWithDndContext>
        <OriginalWidgetFrame
          layout={layout}
          rowIndex={0}
          columnIndex={0}
          widgetIndex={0}
          children={children}
          editable={editable}
          onRemove={onRemove}
          title={title}
          editable
          connectDragSource={identity}
          connectDropTarget={identity}
        />
      </ContainerWithDndContext>
    );
    component.find('a.remove').simulate('click');
    expect(onRemove.calledWithExactly({
      rows: [{
        columns: [{
          className: 'col-md-4',
          widgets: [],
        }],
      }],
    }, 0, 0, 0)).to.equal(true);
  });

{'fraction_non_alphanumeric': 0.13404784094439268, 'fraction_numerical': 0.0031065548306927616, 'mean_word_length': 2.5931919642857144, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 39, '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': '6870169', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1738, 'n_words': 362}