// From https://github.com/jesstelford/react-testing-mocha-jsdom
import jsdom from 'jsdom';

// A super simple DOM ready for React to render into
// Store this DOM and the window in global scope ready for React to access
global.document = jsdom.jsdom('<!doctype html><html><body></body></html>');
global.window = document.parentWindow;

// TODO: Insert rest of imports here... after creating the global window.
import React from "react";
import TestUtils from "react-addons-test-utils";
import sinon from "sinon";
import { assert } from "chai";

import { Actions } from "../../src/actions.js";
// import { JournalEntryStore } from "../src/stores/journal_entry_store.js";
import { JournalMarkdownView, __RewireAPI__ as JournalRewireAPI } from "../../src/views/journal_markdown_viewer.js";
import { Router, State } from "react-router";

describe('JournalMarkdownViewer', function() {
    describe("simple test", function () {
        it("prove that test infrastructure works", function () {
            assert.ok(true);
        });
    });

    describe.skip("Fetching of Articles by view linked to store", function () {

        beforeEach(function () {
            JournalRewireAPI.__Rewire__("Actions", sinon.stub(Actions));
            // JournalRewireAPI.__Rewire__("JournalEntryStore", sinon.stub(JournalEntryStore));
            JournalRewireAPI.__Rewire__("State", sinon.stub(State));
        });

        afterEach(function () {
            console.log('After');
            JournalRewireAPI.__ResetDependency__("Actions");
            JournalRewireAPI.__ResetDependency__("JournalEntryStore");
            JournalRewireAPI.__ResetDependency__("State");
        });

        it('The view should default to a loading text when initializing and then calling for data', function () {
            this.skip('Fix up later');
            let journalMarkdownView = TestUtils.renderIntoDocument(<JournalMarkdownView />);

            assert.ok(journalMarkdownView);

            let journalTitle = TestUtils.findRenderedDOMComponentWithTag(journalMarkdownView, 'h1');
            assert.ok(journalTitle);
            assert.equal(journalTitle.getDOMNode().textContent, 'Loading...');

            let journalContent = TestUtils.findRenderedDOMComponentWithTag(journalMarkdownView, 'span');
            assert.ok(journalContent);
            assert.include(journalContent.getDOMNode().textContent, 'Please wait while we load');
        });

        // TODO Add timer test
        // TODO Add mock call for data.

        it('The view should update its state given newer data', function () {
            this.skip('Implement me.');
        });
    });
});
