import React from "react"
import { shallow, mount, render } from "enzyme"
import sinon from "sinon"
import "../setupTests"
import { InlineEditor } from "./InlineEditor"
import Authorization from "components/authentication/Authorization"
import { EditPanel } from "styles"
import Editor from "draft-js-plugins-editor"

describe("InlineEditor", () => {
  let props
  let mountedInlineEditor
  const inlineEditor = () => {
    if (!mountedInlineEditor) {
      mountedInlineEditor = shallow(<InlineEditor {...props} />)
    }
    return mountedInlineEditor
  }

  beforeEach(() => {
    props = {
      page: undefined,
      id: undefined,
      updated_by: undefined,
      saveInlineEditing: undefined,
      editInline: undefined,
    }
    mountedInlineEditor = undefined
  })

  const content = JSON.stringify({
    entityMap: {},
    blocks: [
      {
        key: "abc",
        text: "123",
        type: "unstyled",
        depth: 0,
      },
    ],
  })

  describe("initial render", () => {
    beforeEach(() => {
      props = {
        page: {
          data: {
            attributes: {
              content: content,
              updated_at: "999",
            },
          },
        },
      }
    })

    it("always renders an EditPanel component", () => {
      expect(inlineEditor().find(EditPanel).length).toBe(1)
    })
    it("always renders an Editor", () => {
      expect(inlineEditor().find(Editor).length).toBe(1)
    })
    it("renders the Authorization component", () => {
      expect(inlineEditor().find(Authorization).length).toBe(1)
    })
  })
})

@@ -238,16 +238,18 @@
 import %7B
+%0A 
  EditPan
@@ -250,17 +250,76 @@
 ditPanel
- 
+,%0A  DefaultBlockButton,%0A  SuccessBlockButton,%0A  ToolbarNav,%0A
 %7D from %22
@@ -1628,16 +1628,639 @@
 %0A    %7D)%0A
+    it(%22renders ToolbarNav if editor isn't read only%22, () =%3E %7B%0A      inlineEditor().setState(%7B%0A        readOnly: false,%0A      %7D)%0A      expect(inlineEditor().find(ToolbarNav).length).toBe(1)%0A    %7D)%0A    it(%22renders DefaultBlockButton if editor isn't read only%22, () =%3E %7B%0A      inlineEditor().setState(%7B%0A        readOnly: false,%0A      %7D)%0A      expect(inlineEditor().find(DefaultBlockButton).length).toBe(1)%0A    %7D)%0A    it(%22renders SuccessBlockButton if editor isn't read only%22, () =%3E %7B%0A      inlineEditor().setState(%7B%0A        readOnly: false,%0A      %7D)%0A      expect(inlineEditor().find(SuccessBlockButton).length).toBe(1)%0A    %7D)%0A
   %7D)%0A%7D)%0A

add more unit tests for when InlineEditor is not readOnly