Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update tests#423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mrholek merged 5 commits intocoreui:mainfrommrholek:main
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,12 +22,12 @@
"test:update": "npm-run-all charts:test:update icons:test:update lib:test:update"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"@typescript-eslint/eslint-plugin": "^8.19.0",
"@typescript-eslint/parser": "^8.19.0",
"eslint": "8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react": "^7.37.3",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-unicorn": "^56.0.1",
"lerna": "^8.1.9",
Expand Down
6 changes: 4 additions & 2 deletionspackages/coreui-react/package.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,10 +49,12 @@
"@rollup/plugin-commonjs": "^28.0.2",
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-typescript": "^12.1.2",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"@types/jest": "^29.5.14",
"@types/react": "18.3.17",
"@types/prop-types": "15.7.13",
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"@types/react-transition-group": "^4.4.12",
"classnames": "^2.5.1",
Expand All@@ -62,7 +64,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-transition-group": "^4.4.5",
"rollup": "^4.28.1",
"rollup": "^4.29.1",
"ts-jest": "^29.2.5",
"tslib": "^2.8.1",
"typescript": "^5.7.2"
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,6 @@
exports[`CAccordionButton customize 1`] = `
<div>
<button
aria-expanded="true"
class="accordion-button collapsed bazinga"
type="button"
>
Expand All@@ -15,7 +14,6 @@ exports[`CAccordionButton customize 1`] = `
exports[`loads and displays CAccordionButton component 1`] = `
<div>
<button
aria-expanded="true"
class="accordion-button collapsed"
type="button"
>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,6 @@ exports[`CAccordionHeader customize 1`] = `
class="accordion-header bazinga"
>
<button
aria-expanded="true"
class="accordion-button collapsed"
type="button"
>
Expand All@@ -22,7 +21,6 @@ exports[`loads and displays CAccordionHeader component 1`] = `
class="accordion-header"
>
<button
aria-expanded="true"
class="accordion-button collapsed"
type="button"
>
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
import React from 'react'
import { render, fireEvent } from '@testing-library/react'
import { getByText } from '@testing-library/dom'
import { render, fireEvent, getByText } from '@testing-library/react'
import '@testing-library/jest-dom'
import { CCarousel, CCarouselCaption, CCarouselItem } from '../../../index'

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { render, screen, fireEvent } from '@testing-library/react'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import '@testing-library/jest-dom'
import {
CDropdown,
Expand DownExpand Up@@ -52,26 +52,50 @@ test('CDropdown customize', async () => {
// jest.useRealTimers()
// })

test('CDropdown click', async () => {
test('CDropdownopens on toggleclick and closes on clicking outside', async () => {
render(
<CDropdown>
<CDropdownToggle>Test</CDropdownToggle>
<CDropdownMenu>
<CDropdownItem>A</CDropdownItem>
<CDropdownItem>B</CDropdownItem>
</CDropdownMenu>
</CDropdown>,
<div>
{/* External element to simulate clicking outside the dropdown */}
<div data-testid="external-area">External Area</div>

{/* The dropdown component */}
<CDropdown>
<CDropdownToggle>Test</CDropdownToggle>
<CDropdownMenu>
<CDropdownItem>A</CDropdownItem>
<CDropdownItem>B</CDropdownItem>
</CDropdownMenu>
</CDropdown>
</div>,
)
expect(screen.getByText('Test')).not.toHaveClass('show')
const el = screen.getByText('Test')
if (el !== null) {
fireEvent.click(el) //click on element
}
jest.runAllTimers()
expect(screen.getByText('Test').closest('div')).toHaveClass('show')
fireEvent.mouseUp(document.body) //click outside
await new Promise((r) => setTimeout(r, 1000))
expect(screen.getByText('Test').closest('div')).not.toHaveClass('show')

// Ensure the dropdown is initially closed
const toggleButton = screen.getByText('Test')
expect(toggleButton).toBeInTheDocument()

// Assuming the 'show' class is applied to the CDropdownMenu
const dropdownMenu = screen.getByRole('menu', { hidden: true }) // Adjust role if different
expect(dropdownMenu).not.toHaveClass('show')

// Click on the toggle to open the dropdown
fireEvent.click(toggleButton)

// Wait for the dropdown menu to become visible
await waitFor(() => {
const openedMenu = screen.getByRole('menu') // Adjust role if different
expect(openedMenu).toBeVisible()
expect(openedMenu).toHaveClass('show')
})

// Click outside the dropdown to close it
const externalArea = screen.getByTestId('external-area')
fireEvent.mouseUp(externalArea)

// Wait for the dropdown menu to be hidden
await waitFor(() => {
const closedMenu = screen.getByRole('menu', { hidden: true }) // Adjust role if different
expect(closedMenu).not.toHaveClass('show')
})
})

test('CDropdown example', async () => {
Expand Down
3 changes: 1 addition & 2 deletionspackages/coreui-react/src/components/modal/CModal.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -158,13 +158,12 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
}, [_visible])

const handleDismiss = () => {
console.log('handleDismiss')
if (backdrop === 'static') {
return setStaticBackdrop(true)
}

setVisible(false)

return onClose && onClose()
}

useLayoutEffect(() => {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { render, fireEvent } from '@testing-library/react'
import { render, fireEvent, screen, waitFor } from '@testing-library/react'
import '@testing-library/jest-dom'
import { CModal } from '../../../index'

Expand DownExpand Up@@ -33,34 +33,42 @@ test('CModal dialog close on press ESC', async () => {
</CModal>,
)
expect(onClose).toHaveBeenCalledTimes(0)
const modal = document.querySelector('.modal')

const modal = screen.getByText('Test').closest('.modal')
expect(modal).toBeInTheDocument()

if (modal !== null) {
fireEvent.keyDown(modal, {
key: 'Escape',
code: 'Escape',
keyCode: 27,
charCode: 27,
})
}
await new Promise((r) => setTimeout(r, 1000))
console.log(modal)
expect(onClose).toHaveBeenCalledTimes(1)
})

test('CModal dialog close on backdrop', async () => {
jest.useFakeTimers()
const onClose = jest.fn()
render(
<CModal onClose={onClose} portal={false} visible={true}>
Test
</CModal>,
)
expect(onClose).toHaveBeenCalledTimes(0)
const backdrop = document.querySelector('.modal-backdrop')
if (backdrop !== null) {
fireEvent.click(backdrop)
await waitFor(() => {
expect(onClose).toHaveBeenCalledTimes(1)
})
}
jest.runAllTimers()
expect(onClose).toHaveBeenCalledTimes(1)
jest.useRealTimers()
})

// test('CModal dialog closes when clicking outside the modal', async () => {
// const onClose = jest.fn()

// render(
// <CModal onClose={onClose} portal={false} visible>
// Test
// </CModal>,
// )

// // Ensure onClose hasn't been called yet
// expect(onClose).not.toHaveBeenCalled()

// // Optionally, verify that the modal is in the document
// const modal = screen.getByText('Test').closest('.modal')
// expect(modal).toBeInTheDocument()

// // Simulate a click on the external area (outside the modal)
// fireEvent.mouseDown(document.body)

// // Wait for onClose to be called once
// await waitFor(() => {
// expect(onClose).toHaveBeenCalledTimes(1)
// })
// })
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,12 +7,13 @@ exports[`CNavGroup customize 1`] = `
>
<a
class="nav-link nav-group-toggle"
href="#"
>
anchorText
</a>
<ul
class="nav-group-items"
style="display: block; height: 0px;"
style="height: 0px; display: block;"
/>
</li>
</div>
Expand All@@ -25,11 +26,13 @@ exports[`loads and displays CNavGroup component 1`] = `
>
<a
class="nav-link nav-group-toggle"
href="#"
>
anchorText
</a>
<ul
class="nav-group-items"
style="height: 0px;"
/>
</li>
</div>
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ test('CPopover customize', async () => {
expect(container).toMatchSnapshot()
let arrLength = container.getElementsByClassName('popover').length
expect(arrLength).toBe(1)
arrLength = container.getElementsByClassName('bs-popover-end').length
arrLength = container.getElementsByClassName('bs-popover-auto').length
expect(arrLength).toBe(1)
arrLength = container.getElementsByClassName('popover-arrow').length
expect(arrLength).toBe(1)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,15 +3,14 @@
exports[`CPopover customize 1`] = `
<body>
<button
aria-describedby="popover744956"
class="btn btn-primary"
type="button"
>
Test
</button>
<div
class="popover bs-popover-auto fade show"
id="popover744956"
class="popover bs-popover-auto fade"
id="popover:r1:"
role="tooltip"
style="position: absolute; left: 0px; top: 0px; margin: 0px;"
>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,6 @@
exports[`CTooltip customize 1`] = `
<div>
<a
aria-describedby="tooltip97108"
class="link"
>
Test
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp