<commit_before>import * as React from "react";
import * as ReactDOM from "react-dom";
import * as TestUtils from "react-addons-test-utils";
import { App } from "components/container/App";
import { PublicationContentPresentation } from "components/PublicationContent/PublicationContentPresentation";
import { Url } from "utils/Url";
import { TestBase } from "sdl-models";
import { PageService } from "test/mocks/services/PageService";
import { PublicationService } from "test/mocks/services/PublicationService";
import { TaxonomyService } from "test/mocks/services/TaxonomyService";
import { localization } from "test/mocks/services/LocalizationService";
import { hashHistory } from "react-router";
import { isPage } from "utils/Page";

const services = {
    pageService: new PageService(),
    publicationService: new PublicationService,
    localizationService: localization,
    taxonomyService: new TaxonomyService()
};

class AppComponent extends TestBase {

    public runTests(): void {

        describe(`App component tests.`, (): void => {
            const target = super.createTargetElement();

            afterEach(() => {
                const domNode = ReactDOM.findDOMNode(target);
                ReactDOM.unmountComponentAtNode(domNode);
            });

            beforeAll(() => {
                hashHistory.push("");
            });

            afterAll(() => {
                if (target.parentElement) {
                    target.parentElement.removeChild(target);
                }
            });

            it("renders publication content component on root", (): void => {
                const onRender = function (this: PublicationContentPresentation): JSX.Element {
                    const { publicationId, pageId, publication, page } = this.props;

                    expect(publicationId).toBe("1420746");
                    expect(pageId).toBe("publication-mp330");
                    expect(publication.title).toEqual("");
                    expect(page.title).toEqual("");

                    return (<div />);
                };

                spyOn(PublicationContentPresentation.prototype, "render").and.callFake(onRender);
                this._renderComponent(target);
            });

            it("renders publication content component when publication id and page id are set", (): void => {
                const onRender = function (this: PublicationContentPresentation): JSX.Element {
                    const { publicationId, pageId, publication, page } = this.props;

                    if (publicationId === "pub-id-with-page") {
                        expect(pageId).toBe("page-id");
                        expect(publication.title).toBe("pub-title");
                        expect(page.title).toBe("page-title");
                    } else {
                        expect(publicationId).toBe("pub-id");
                        expect(publication.title).toBe("pub-title");
                        expect(isPage(page)).toBeFalsy();
                        expect(page.title).toBe("");
                    }

                    return (<div />);
                };

                const app = this._renderComponent(target);

                spyOn(PublicationContentPresentation.prototype, "render").and.callFake(onRender);

                // Publication content
                hashHistory.push(Url.getPublicationUrl("pub-id", "pub-title"));
                expect(TestUtils.findRenderedComponentWithType(app, PublicationContentPresentation)).not.toBeNull();

                hashHistory.push(Url.getPageUrl("pub-id-with-page", "page-id", "pub-title", "page-title"));
                expect(TestUtils.findRenderedComponentWithType(app, PublicationContentPresentation)).not.toBeNull();
            });
        });
    }

    private _renderComponent(target: HTMLElement): App {
        return ReactDOM.render(
                <App history={hashHistory} services={services} />
            , target) as App;
    }
}

new AppComponent().runTests();
<commit_msg>subtask/KCWA-468 Return appcomponent test<commit_after>import * as React from "react";
import * as ReactDOM from "react-dom";
import * as TestUtils from "react-addons-test-utils";
import { App } from "components/container/App";
import { PublicationContentPresentation } from "components/PublicationContent/PublicationContentPresentation";
import { Url } from "utils/Url";
import { TestBase } from "sdl-models";
import { PageService } from "test/mocks/services/PageService";
import { PublicationService } from "test/mocks/services/PublicationService";
import { TaxonomyService } from "test/mocks/services/TaxonomyService";
import { localization } from "test/mocks/services/LocalizationService";
import { hashHistory } from "react-router";
import { isPage } from "utils/Page";
import { configureStore } from "store/Store";
import { Provider } from "react-redux";
import { Store } from "redux";
import { IState } from "store/interfaces/State";

const services = {
    pageService: new PageService(),
    publicationService: new PublicationService,
    localizationService: localization,
    taxonomyService: new TaxonomyService()
};

class AppComponent extends TestBase {
    private store: Store<IState>;
    public runTests(): void {
        describe(`App component tests.`, (): void => {
            const target = super.createTargetElement();

            afterEach(() => {
                this.store = configureStore();
                const domNode = ReactDOM.findDOMNode(target);
                ReactDOM.unmountComponentAtNode(domNode);
            });

            beforeAll(() => {
                hashHistory.push("");
            });

            afterAll(() => {
                if (target.parentElement) {
                    target.parentElement.removeChild(target);
                }
            });

            it("renders publication content component on root", (): void => {
                const onRender = function (this: PublicationContentPresentation): JSX.Element {
                    const { publicationId, pageId, publication, page } = this.props;

                    expect(publicationId).toBe("1420746");
                    expect(pageId).toBe("publication-mp330");
                    expect(publication.title).toEqual("");
                    expect(page.title).toEqual("");

                    return (<div />);
                };

                spyOn(PublicationContentPresentation.prototype, "render").and.callFake(onRender);
                this._renderComponent(target);
            });

            it("renders publication content component when publication id and page id are set", (): void => {
                const onRender = function (this: PublicationContentPresentation): JSX.Element {
                    const { publicationId, pageId, publication, page } = this.props;

                    if (publicationId === "pub-id-with-page") {
                        expect(pageId).toBe("page-id");
                        expect(publication.title).toBe("pub-title");
                        expect(page.title).toBe("page-title");
                    } else {
                        expect(publicationId).toBe("pub-id");
                        expect(publication.title).toBe("pub-title");
                        expect(isPage(page)).toBeFalsy();
                        expect(page.title).toBe("");
                    }

                    return (<div />);
                };

                const app = this._renderComponent(target);

                spyOn(PublicationContentPresentation.prototype, "render").and.callFake(onRender);

                // Publication content
                hashHistory.push(Url.getPublicationUrl("pub-id", "pub-title"));
                expect(TestUtils.findRenderedComponentWithType(app, PublicationContentPresentation)).not.toBeNull();

                hashHistory.push(Url.getPageUrl("pub-id-with-page", "page-id", "pub-title", "page-title"));
                expect(TestUtils.findRenderedComponentWithType(app, PublicationContentPresentation)).not.toBeNull();
            });
        });
    }

    private _renderComponent(target: HTMLElement): App {
        return ReactDOM.render(
                <Provider store={this.store}>
                    <App history={hashHistory} services={services} />
                </Provider>
            , target) as App;
    }
}

new AppComponent().runTests();

{'fraction_non_alphanumeric': 0.11813856330509458, 'fraction_numerical': 0.00266914239294418, 'mean_word_length': 1.9737750172532782, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2269874', 'n_tokens_mistral': 2199, 'n_tokens_neox': 2042, 'n_words': 407}