<commit_before>'use strict';


import React from 'react';
import ReactDOM from 'react-dom';
import ReactDOMServer from 'react-dom/server';
import _ from 'underscore';
import TestUtils, { act } from 'react-dom/test-utils';

jest.autoMockOff();

// Fixes https://github.com/facebook/jest/issues/78
jest.dontMock('react');
jest.dontMock('underscore');

describe("Server rendering", function () {
    // let App;
    // let document;
    // let store;
    // let sinon;
    // let server;
    // const home_url = "http://localhost/";
    // const home = {
    //     "@id": "/",
    //     "@type": ["HomePage", "StaticPage", "Portal"],
    //     "portal_title": "4DN Data Portal",
    //     "title": "Home",
    //     "content" : [
    //         {
    //             "filetype":"html",
    //             "date_created":"2018-04-27T17:51:09.297564+00:00",
    //             "@type":[
    //                 "StaticSection",
    //                 "Item"
    //             ],
    //             "display_title":"Introduction",
    //             "title":"Introduction",
    //             "uuid":"10000000-0000-0000-0000-fffff1000000",
    //             "link_id":"~static-sections~10000000-0000-0000-0000-fffff1000000~",
    //             "content":"<p>\nThe 4D Nucleome Data Portal hosts data generated by the 4DN Network and other reference nucleomics data sets.\nThe Portal is currently in pre-release as more data is being curated, and data processing and visualization tools are being incorporated.\nClick <a href=\"/browse/?type=ExperimentSetReplicate&experimentset_type=replicate\"><strong>Browse</strong></a> to see currently available data. \n</p>\n\n<p>\nThe 4DN program aims to understand the principles underlying nuclear organization in space and time, \nthe role nuclear organization plays in gene expression and cellular function, \nand how changes in nuclear organization affect normal development as well as various diseases. \nThe program is developing novel tools to explore the dynamic nuclear architecture and its role in gene expression programs,\nmodels to examine the relationship between nuclear organization and function,\nand reference maps of nuclear architecture in a variety of cells and tissues as a community resource.\n</p>",
    //             "section_type":"Page Section",
    //             "file":"/src/encoded/static/data/home/description.html",
    //             "name":"home.introduction",
    //             "@id":"/static-sections/10000000-0000-0000-0000-fffff1000000/",
    //             "status":"released",
    //         }
    //     ]
    // };
    

    // beforeAll(function(){
    //     sinon = require('sinon');
    //     server = sinon.fakeServer.create();
    //     server.respondWith(
    //         "GET",
    //         '/profiles/',
    //         [
    //             200, 
    //             { "Content-Type" : "application/json" },
    //             '<html></html>' // Don't actually need content JSON here for test. Just to silence loadSchemas XHR request error (no XHR avail in test)
    //         ]
    //     );
    // });

    // afterAll(function(){
    //     server.restore();
    // });

    // beforeEach(function () {
    //     App = require('..').default;
    //     store = require('../../store').store;
    //     // test dispatching some values to store
    //     const dispatch_vals = {
    //         'href': home_url,
    //         'context': home,
    //         'contextRequest': {},
    //         'slow': false
    //     };
    //     act(()=>{
    //         store.dispatch({
    //             type: dispatch_vals
    //         });
    //     });
    //     const props = store.getState();
    //     const server_app = <App {...props} />;
    //     const markup = '<!DOCTYPE html>\n' + ReactDOMServer.renderToString(server_app);
    //     const parser = new DOMParser();
    //     document = parser.parseFromString(markup, 'text/html');
    //     window.location.href = props['href'];
    // });

    it.skip("renders the application to html", function () {
        expect(document.title).toBe(home.portal_title);
    });

    it.skip("react render http-equiv correctly", function () {
        const meta_http_equiv = document.querySelectorAll('meta[http-equiv]');
        expect(meta_http_equiv.length).not.toBe(0);
    });

    it.skip("mounts the application over the rendered html", function () {
        const props = store.getState();
        let app;
        act(()=>{
            app = ReactDOM.render(<App {...props} />, document);
            app.loadSchemas = jest.fn(); // Mock func which would otherwise launch a XHR request
        });
        expect(ReactDOM.findDOMNode(app)).toBe(document.documentElement);
    });
});<commit_msg>active server render test<commit_after>'use strict';


import React from 'react';
import ReactDOM from 'react-dom';
import ReactDOMServer from 'react-dom/server';
import _ from 'underscore';
import TestUtils, { act } from 'react-dom/test-utils';

jest.autoMockOff();

// Fixes https://github.com/facebook/jest/issues/78
jest.dontMock('react');
jest.dontMock('underscore');

describe("Server rendering", function () {
    let App;
    let document;
    let store;
    let sinon;
    let server;
    const home_url = "http://localhost/";
    const home = {
        "@id": "/",
        "@type": ["HomePage", "StaticPage", "Portal"],
        "portal_title": "4DN Data Portal",
        "title": "Home",
        "content" : [
            {
                "filetype":"html",
                "date_created":"2018-04-27T17:51:09.297564+00:00",
                "@type":[
                    "StaticSection",
                    "Item"
                ],
                "display_title":"Introduction",
                "title":"Introduction",
                "uuid":"10000000-0000-0000-0000-fffff1000000",
                "link_id":"~static-sections~10000000-0000-0000-0000-fffff1000000~",
                "content":"<p>\nThe 4D Nucleome Data Portal hosts data generated by the 4DN Network and other reference nucleomics data sets.\nThe Portal is currently in pre-release as more data is being curated, and data processing and visualization tools are being incorporated.\nClick <a href=\"/browse/?type=ExperimentSetReplicate&experimentset_type=replicate\"><strong>Browse</strong></a> to see currently available data. \n</p>\n\n<p>\nThe 4DN program aims to understand the principles underlying nuclear organization in space and time, \nthe role nuclear organization plays in gene expression and cellular function, \nand how changes in nuclear organization affect normal development as well as various diseases. \nThe program is developing novel tools to explore the dynamic nuclear architecture and its role in gene expression programs,\nmodels to examine the relationship between nuclear organization and function,\nand reference maps of nuclear architecture in a variety of cells and tissues as a community resource.\n</p>",
                "section_type":"Page Section",
                "file":"/src/encoded/static/data/home/description.html",
                "name":"home.introduction",
                "@id":"/static-sections/10000000-0000-0000-0000-fffff1000000/",
                "status":"released",
            }
        ]
    };
    

    beforeAll(function(){
        sinon = require('sinon');
        server = sinon.fakeServer.create();
        server.respondWith(
            "GET",
            '/profiles/',
            [
                200, 
                { "Content-Type" : "application/json" },
                '<html></html>' // Don't actually need content JSON here for test. Just to silence loadSchemas XHR request error (no XHR avail in test)
            ]
        );
    });

    afterAll(function(){
        server.restore();
    });

    beforeEach(function () {
        App = require('..').default;
        store = require('../../store').store;
        // test dispatching some values to store
        const dispatch_vals = {
            'href': home_url,
            'context': home,
            'contextRequest': {},
            'slow': false
        };
        act(()=>{
            store.dispatch({
                type: dispatch_vals
            });
        });
        const props = store.getState();
        const server_app = <App {...props} />;
        const markup = '<!DOCTYPE html>\n' + ReactDOMServer.renderToString(server_app);
        const parser = new DOMParser();
        document = parser.parseFromString(markup, 'text/html');
        window.location.href = props['href'];
    });

    it("renders the application to html", function () {
        expect(document.title).toBe(home.portal_title);
    });

    it("react render http-equiv correctly", function () {
        const meta_http_equiv = document.querySelectorAll('meta[http-equiv]');
        expect(meta_http_equiv.length).not.toBe(0);
    });

    it("mounts the application over the rendered html", function () {
        const props = store.getState();
        let app;
        act(()=>{
            app = ReactDOM.render(<App {...props} />, document);
            app.loadSchemas = jest.fn(); // Mock func which would otherwise launch a XHR request
        });
        expect(ReactDOM.findDOMNode(app)).toBe(document.documentElement);
    });
});
{'fraction_non_alphanumeric': 0.14190424959655729, 'fraction_numerical': 0.02474448628294782, 'mean_word_length': 2.1352445193929173, 'pattern_counts': {'":': 34, '<': 29, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, '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': '7588503', 'n_tokens_mistral': 2707, 'n_tokens_neox': 2475, 'n_words': 655}