Skip to content

Commit

Permalink
chore: update unit tests, multiline test failing #2025
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-mihok authored and mturoci committed Sep 6, 2023
1 parent 798057f commit d5b27a0
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion ui/src/copyable_text.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { render } from '@testing-library/react'
import { fireEvent, render } from '@testing-library/react'
import React from 'react'
import { CopyableText, XCopyableText } from './copyable_text'

Expand All @@ -34,4 +34,29 @@ describe('CopyableText.tsx', () => {
expect(getByTestId(name)).toHaveValue('B')
})

it('Shows copy to clipboard button', () => {
const { container } = render(<XCopyableText model={copyableTextProps} />)
const copyButton = container.querySelector('button')

expect(copyButton).toBeInTheDocument()
expect(copyButton).toBeVisible()
})

it('Shows copy to clipboard button on hover - multiline text', async () => {
const { container } = render(<XCopyableText model={{ ...copyableTextProps, multiline: true }} />)
const copyButton = container.querySelector('button')
const textfield = container.querySelector('textarea')!
expect(copyButton).toBeInTheDocument()
expect(copyButton).toBeVisible()
// Move cursor out of container.
fireEvent.mouseLeave(textfield)
await new Promise(resolve => setTimeout(resolve, 1000))

expect(copyButton).not.toBeVisible()

fireEvent.mouseEnter(textfield)
await new Promise(resolve => setTimeout(resolve, 1000))

expect(copyButton).toBeVisible()
})
})

0 comments on commit d5b27a0

Please sign in to comment.