<commit_before>/*
 * Copyright (C) 2021 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */
import React from 'react'
import RichContentEditor from '@canvas/rce/RichContentEditor'
import {DiscussionEdit} from '../DiscussionEdit'
import {render, fireEvent} from '@testing-library/react'

const setup = props => {
  return render(<DiscussionEdit {...props} />)
}

describe('DiscussionEdit', () => {
  beforeEach(() => {
    RichContentEditor.loadNewEditor = jest.fn()
    RichContentEditor.callOnRCE = jest.fn()
    RichContentEditor.closeRCE = jest.fn()
    RichContentEditor.destroyRCE = jest.fn()
  })

  afterEach(() => {
    jest.clearAllMocks()
  })

  describe('Rendering', () => {
    it('should render', () => {
      const component = setup()
      expect(component).toBeTruthy()
    })

    it('should not show when show is false', () => {
      const {getByTestId} = setup({show: false})
      const container = getByTestId('DiscussionEdit-container')
      expect(container.style.display).toBe('none')
    })

    it('should show by default', () => {
      const {getByTestId} = setup()
      const container = getByTestId('DiscussionEdit-container')
      expect(container.style.display).toBe('')
    })
  })

  describe('Callbacks', () => {
    it('should fire onCancel when clicked', () => {
      const onCancelMock = jest.fn()
      const {getByTestId} = setup({onCancel: onCancelMock})
      const cancelButton = getByTestId('DiscussionEdit-cancel')
      fireEvent.click(cancelButton)
      expect(onCancelMock.mock.calls.length).toBe(1)
    })

    it('should fire obSubmit when clicked', () => {
      const onSubmitMock = jest.fn()
      const {getByTestId} = setup({onSubmit: onSubmitMock})
      const submitButton = getByTestId('DiscussionEdit-submit')
      fireEvent.click(submitButton)
      expect(onSubmitMock.mock.calls.length).toBe(1)
    })<commit_msg>clean up DiscussionEdit test warnings<commit_after>/*
 * Copyright (C) 2021 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */
import React from 'react'
import RichContentEditor from '@canvas/rce/RichContentEditor'
import {DiscussionEdit} from '../DiscussionEdit'
import {render, fireEvent} from '@testing-library/react'

const setup = props => {
  return render(<DiscussionEdit {...props} />)
}

const defaultProps = ({
  show = undefined,
  value = undefined,
  onCancel = jest.fn(),
  onSubmit = jest.fn()
} = {}) => ({
  show,
  value,
  onCancel,
  onSubmit
})

describe('DiscussionEdit', () => {
  beforeEach(() => {
    RichContentEditor.loadNewEditor = jest.fn()
    RichContentEditor.callOnRCE = jest.fn()
    RichContentEditor.closeRCE = jest.fn()
    RichContentEditor.destroyRCE = jest.fn()
  })

  afterEach(() => {
    jest.clearAllMocks()
  })

  describe('Rendering', () => {
    it('should render', () => {
      const component = setup(defaultProps())
      expect(component).toBeTruthy()
    })

    it('should not show when show is false', () => {
      const {getByTestId} = setup(defaultProps({show: false}))
      const container = getByTestId('DiscussionEdit-container')
      expect(container.style.display).toBe('none')
    })

    it('should show by default', () => {
      const {getByTestId} = setup(defaultProps())
      const container = getByTestId('DiscussionEdit-container')
      expect(container.style.display).toBe('')
    })
  })

  describe('Callbacks', () => {
    it('should fire onCancel when clicked', () => {
      const onCancelMock = jest.fn()
      const {getByTestId} = setup(defaultProps({onCancel: onCancelMock}))
      const cancelButton = getByTestId('DiscussionEdit-cancel')
      fireEvent.click(cancelButton)
      expect(onCancelMock.mock.calls.length).toBe(1)
    })

    it('should fire obSubmit when clicked', () => {
      const onSubmitMock = jest.fn()
      const {getByTestId} = setup(defaultProps({onSubmit: onSubmitMock}))
      const submitButton = getByTestId('DiscussionEdit-submit')
      fireEvent.click(submitButton)
      expect(onSubmitMock.mock.calls.length).toBe(1)
    })
{'fraction_non_alphanumeric': 0.12774829416224412, 'fraction_numerical': 0.00265352539802881, 'mean_word_length': 3.6047120418848166, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4560820', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1491, 'n_words': 434}