<commit_before>import React from 'react';
import ReactDOM from 'react-dom';
import Seed from '../../../Seed';

function getRequestOptions() {
  return {
    url: '/api/users/Vincenzo',
    method: 'POST',
    data: {
      nickname: 'vncz'
    },
    headers: {
      'Content-Type': 'application/json'
    }
  };
}

function checkResponseData(res) {
  expect(res.data).toBeDefined();
  expect(res.headers).toBeDefined();
  /*
    Yeah ok not a great test, but it's an easy way to understand if we
    were able to overcome the CORS limitations
  */
  expect(res.headers['x-powered-by']).toBeDefined();
  expect(res.status).toBe(200);
}

describe('Component interface test', () => {
  let seed = undefined;

  beforeAll(() => {
    const div = document.createElement('div');
    div.setAttribute('id', 'container');
    document.body.appendChild(div);
  });

  afterEach(() => {
    ReactDOM.unmountComponentAtNode(document.getElementById('container'));
  });

  describe('seed with everything set (Chrome)', () => {

    beforeAll((done) => {
      seed = ReactDOM.render(<Seed onReady={done} seedUrl="ijlncpebbpeeagehccegnddhhdgcaflf"/>,
        document.getElementById('container')
      );
    });

    it('valid http request', (done) => {
      const options = getRequestOptions();
      options.url = 'http://localhost:3001' + options.url;
      return seed.request(options).then((res) => {
        checkResponseData(res);
        done()
      }, done.fail.bind(this, new Error('This promise should not have been rejected')));
    });

  });

});
<commit_msg>Test iframe creation/destruction<commit_after>import React from 'react';
import ReactDOM from 'react-dom';
import Seed from '../../../Seed';

function getRequestOptions() {
  return {
    url: '/api/users/Vincenzo',
    method: 'POST',
    data: {
      nickname: 'vncz'
    },
    headers: {
      'Content-Type': 'application/json'
    }
  };
}

function checkResponseData(res) {
  expect(res.data).toBeDefined();
  expect(res.headers).toBeDefined();
  /*
    Yeah ok not a great test, but it's an easy way to understand if we
    were able to overcome the CORS limitations
  */
  expect(res.headers['x-powered-by']).toBeDefined();
  expect(res.status).toBe(200);
}

describe('Component interface test', () => {
  let seed = undefined;
  let containerElement = undefined;

  beforeAll(() => {
    containerElement = document.createElement('div');
    containerElement.setAttribute('id', 'container');
    document.body.appendChild(containerElement);
  });

  afterEach(() => {
    ReactDOM.unmountComponentAtNode(containerElement);
  });

  describe('seed with everything set (Chrome)', () => {

    beforeAll((done) => {
      seed = ReactDOM.render(<Seed onReady={done} seedUrl="ijlncpebbpeeagehccegnddhhdgcaflf" />, containerElement);
    });

    it('valid http request', (done) => {
      const options = getRequestOptions();
      options.url = 'http://localhost:3001' + options.url;
      return seed.request(options).then((res) => {
        checkResponseData(res);
        done()
      }, done.fail.bind(this, new Error('This promise should not have been rejected')));
    });

  });

  describe('change method from iframe to extension and vice versa', () => {
    describe('from iframe to extension', () => {
      it('should find an iframe', () => {
        seed = ReactDOM.render(<Seed seedUrl="https://www.google.it" />, containerElement);
        expect(document.querySelectorAll('#container iframe').length).toBe(1);

        seed = ReactDOM.render(<Seed seedUrl="ijlncpebbpeeagehccegnddhhdgcaflf" />, containerElement);
        expect(document.querySelectorAll('#container iframe').length).toBe(0);
      });
    });

    describe('from extension to iframe', () => {
      it('should not find an iframe', () => {
        seed = ReactDOM.render(<Seed seedUrl="ijlncpebbpeeagehccegnddhhdgcaflf" />, containerElement);
        expect(document.querySelectorAll('#container iframe').length).toBe(0);

        seed = ReactDOM.render(<Seed seedUrl="https://www.google.it" />, containerElement);
        expect(document.querySelectorAll('#container iframe').length).toBe(1);
      })
    });
  });
});
{'fraction_non_alphanumeric': 0.16383233532934133, 'fraction_numerical': 0.004311377245508982, 'mean_word_length': 3.456776947705443, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 28, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4819817', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1250, 'n_words': 258}