<commit_before>import React from "react"
import { shallow, mount } from "enzyme"
import sinon from "sinon"
import "../../setupTests"
import { InfoPageView } from "./InfoPageView"
import { Container } from "styles"
import { Editor } from "draft-js"

describe("InfoPage/InfoPageView", () => {
  let props
  let mountedInfoPageView
  const infoPageView = () => {
    if (!mountedInfoPageView) {
      mountedInfoPageView = shallow(<InfoPageView {...props} />)
    }
    return mountedInfoPageView
  }

  beforeEach(() => {
    props = {
      page: undefined,
      match: undefined,
      editPage: undefined,
      fetchUserInfo: undefined,
      fetchedUserData: undefined,
      loggedInUser: undefined,
      isAuthenticated: undefined,
    }
    mountedInfoPageView = 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",
            },
          },
        },
        match: {
          params: {
            name: "order",
          },
        },
        fetchUserInfo: () => {},
      }
    })

    it("always renders a Container", () => {
      expect(infoPageView().find(Container).length).toBeGreaterThan(0)
    })
    it("always renders an Editor", () => {
      expect(infoPageView().find(Editor).length).toBeGreaterThan(0)
    })
    it("Editor is readOnly", () => {
      const editor = infoPageView().find(Editor)
      expect(editor.props().readOnly).toBe(true)
    })
  })

  describe("user is authenticated with no other permissions", () => {
    beforeEach(() => {
      props = {
        page: {
          data: {
            attributes: {
              content: content,
              updated_at: "999",
            },
          },
        },
        match: {
          params: {
            name: "order",
          },
        },
        fetchUserInfo: () => {},
        isAuthenticated: true,
      }
    })
    it("calls componentDidMount", () => {
      sinon.spy(InfoPageView.prototype, "componentDidMount")
      infoPageView()
      expect(InfoPageView.prototype.componentDidMount.calledOnce).toEqual(true)
    })
  })

  describe("user is authenticated with editing privileges and valid JWT", () => {
    // add tests here
  })

  describe("user is authenticated with editing privileges but JWT is invalid", () => {
    // add tests here
  })
})<commit_msg>add more unit tests for InfoPageView<commit_after>import React from "react"
import { shallow, mount } from "enzyme"
import sinon from "sinon"
import "../../setupTests"
import { InfoPageView } from "./InfoPageView"
import Authorization from "components/authentication/Authorization"
import ErrorNotification from "components/authentication/ErrorNotification"
import { Container, ToolbarNav } from "styles"
import { Editor } from "draft-js"

describe("InfoPage/InfoPageView", () => {
  let props
  let mountedInfoPageView
  const infoPageView = () => {
    if (!mountedInfoPageView) {
      mountedInfoPageView = shallow(<InfoPageView {...props} />)
    }
    return mountedInfoPageView
  }

  beforeEach(() => {
    props = {
      page: undefined,
      match: undefined,
      editPage: undefined,
      fetchUserInfo: undefined,
      fetchedUserData: undefined,
      loggedInUser: undefined,
      isAuthenticated: undefined,
    }
    mountedInfoPageView = 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",
            },
          },
        },
        match: {
          params: {
            name: "order",
          },
        },
        fetchUserInfo: () => {},
      }
    })

    it("always renders a Container", () => {
      expect(infoPageView().find(Container).length).toBe(1)
    })
    it("always renders an Editor", () => {
      expect(infoPageView().find(Editor).length).toBe(1)
    })
    it("Editor is readOnly", () => {
      const editor = infoPageView().find(Editor)
      expect(editor.props().readOnly).toBe(true)
    })
  })

  describe("user is not authenticated", () => {
    beforeEach(() => {
      props = {
        page: {
          data: {
            attributes: {
              content: content,
              updated_at: "999",
            },
          },
        },
        match: {
          params: {
            name: "order",
          },
        },
        fetchUserInfo: () => {},
        isAuthenticated: false,
      }
    })

    it("renders the Authorization component", () => {
      expect(infoPageView().find(Authorization).length).toBe(0)
    })
  })

  describe("user is authenticated with no other permissions", () => {
    beforeEach(() => {
      props = {
        page: {
          data: {
            attributes: {
              content: content,
              updated_at: "999",
            },
          },
        },
        match: {
          params: {
            name: "order",
          },
        },
        fetchUserInfo: () => {},
        isAuthenticated: true,
      }
    })
    it("calls componentDidMount", () => {
      sinon.spy(InfoPageView.prototype, "componentDidMount")
      infoPageView()
      expect(InfoPageView.prototype.componentDidMount.calledOnce).toEqual(true)
    })
    it("renders the Authorization component", () => {
      expect(infoPageView().find(Authorization).length).toBe(1)
    })
  })

  describe("user is authenticated with editing privileges and valid JWT", () => {
    beforeEach(() => {
      props = {
        page: {
          data: {
            attributes: {
              content: content,
              updated_at: "999",
            },
          },
        },
        match: {
          params: {
            name: "order",
          },
        },
        fetchUserInfo: () => {},
        isAuthenticated: true,
        canEditPages: true,
        verifiedToken: true,
      }
    })

    // jest.mock(
    //   "components/authentication/Authorization",
    //   () => ({ canEditPages, fetchedUserData, verifiedToken }) => render(),
    // )

    const AuthorizationMock = () => {}

    it("renders the Authorization component", () => {
      expect(infoPageView().find(Authorization).length).toBe(1)
    })
  })

  describe("user is authenticated with editing privileges but JWT is invalid", () => {
    beforeEach(() => {
      props = {
        page: {
          data: {
            attributes: {
              content: content,
              updated_at: "999",
            },
          },
        },
        match: {
          params: {
            name: "order",
          },
        },
        fetchUserInfo: () => {},
        isAuthenticated: true,
        canEditPages: true,
        verifiedToken: false,
      }
    })

    it("renders the Authorization component", () => {
      expect(infoPageView().find(Authorization).length).toBe(1)
    })
  })
})
{'fraction_non_alphanumeric': 0.1425852929183091, 'fraction_numerical': 0.005029223868424629, 'mean_word_length': 1.8159203980099503, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2641054', 'n_tokens_mistral': 2105, 'n_tokens_neox': 2057, 'n_words': 414}