-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
296 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import '@testing-library/jest-dom'; | ||
import { Message } from './Message'; | ||
|
||
import { snapshot } from '../../test'; | ||
|
||
describe('Message', () => { | ||
snapshot(<Message />, 'default'); | ||
snapshot(<Message severity="success" text="Jest" />, 'severity success'); | ||
snapshot(<Message severity="info" text="Jest" />, 'severity info'); | ||
snapshot(<Message severity="warn" text="Jest" />, 'severity warn'); | ||
snapshot(<Message severity="error" text="Jest" />, 'severity error'); | ||
snapshot(<Message icon="pi pi-check" />, 'icon'); | ||
snapshot(<Message content={<span>Test</span>} />, 'content'); | ||
snapshot( | ||
<Message> | ||
<span>Jester</span> | ||
</Message>, | ||
'templating' | ||
); | ||
}); |
142 changes: 142 additions & 0 deletions
142
components/lib/message/__snapshots__/Message.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Message content 1`] = ` | ||
<div> | ||
<div | ||
aria-live="polite" | ||
class="p-inline-message p-component p-inline-message-info p-inline-message-icon-only" | ||
role="alert" | ||
> | ||
<span> | ||
Test | ||
</span> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Message default 1`] = ` | ||
<div> | ||
<div | ||
aria-live="polite" | ||
class="p-inline-message p-component p-inline-message-info p-inline-message-icon-only" | ||
role="alert" | ||
> | ||
<span | ||
class="p-inline-message-icon pi pi-info-circle" | ||
/> | ||
<span | ||
class="p-inline-message-text" | ||
/> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Message icon 1`] = ` | ||
<div> | ||
<div | ||
aria-live="polite" | ||
class="p-inline-message p-component p-inline-message-info p-inline-message-icon-only" | ||
role="alert" | ||
> | ||
<span | ||
class="p-inline-message-icon pi pi-check" | ||
/> | ||
<span | ||
class="p-inline-message-text" | ||
/> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Message severity error 1`] = ` | ||
<div> | ||
<div | ||
aria-live="polite" | ||
class="p-inline-message p-component p-inline-message-error" | ||
role="alert" | ||
> | ||
<span | ||
class="p-inline-message-icon pi pi-times-circle" | ||
/> | ||
<span | ||
class="p-inline-message-text" | ||
> | ||
Jest | ||
</span> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Message severity info 1`] = ` | ||
<div> | ||
<div | ||
aria-live="polite" | ||
class="p-inline-message p-component p-inline-message-info" | ||
role="alert" | ||
> | ||
<span | ||
class="p-inline-message-icon pi pi-info-circle" | ||
/> | ||
<span | ||
class="p-inline-message-text" | ||
> | ||
Jest | ||
</span> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Message severity success 1`] = ` | ||
<div> | ||
<div | ||
aria-live="polite" | ||
class="p-inline-message p-component p-inline-message-success" | ||
role="alert" | ||
> | ||
<span | ||
class="p-inline-message-icon pi pi-check" | ||
/> | ||
<span | ||
class="p-inline-message-text" | ||
> | ||
Jest | ||
</span> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Message severity warn 1`] = ` | ||
<div> | ||
<div | ||
aria-live="polite" | ||
class="p-inline-message p-component p-inline-message-warn" | ||
role="alert" | ||
> | ||
<span | ||
class="p-inline-message-icon pi pi-exclamation-triangle" | ||
/> | ||
<span | ||
class="p-inline-message-text" | ||
> | ||
Jest | ||
</span> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Message templating 1`] = ` | ||
<div> | ||
<div | ||
aria-live="polite" | ||
class="p-inline-message p-component p-inline-message-info p-inline-message-icon-only" | ||
role="alert" | ||
> | ||
<span | ||
class="p-inline-message-icon pi pi-info-circle" | ||
/> | ||
<span | ||
class="p-inline-message-text" | ||
/> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import '@testing-library/jest-dom'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { userAgent } from '../../test'; | ||
import PrimeReact from '../api/PrimeReact'; | ||
import { Button } from '../button/Button'; | ||
|
||
describe('Ripple', () => { | ||
test('when Ripple is enabled, button should have ripple effect on desktop device', async () => { | ||
// Arrange | ||
userAgent('Chrome'); | ||
PrimeReact.ripple = true; | ||
const { container } = render(<Button />); | ||
const button = container.getElementsByClassName('p-button')[0]; | ||
|
||
// Act | ||
await userEvent.click(button); | ||
|
||
// Assert | ||
expect(button).toBeEnabled(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
test('when Ripple is enabled, button should have ripple effect on touch device', async () => { | ||
// Arrange | ||
userAgent('iPhone'); | ||
PrimeReact.ripple = true; | ||
const { container } = render(<Button />); | ||
const button = container.getElementsByClassName('p-button')[0]; | ||
|
||
// Act | ||
fireEvent.touchStart(button, { targetTouches: [{ pageX: '50', pageY: '50' }] }); | ||
|
||
// Assert | ||
expect(button).toBeEnabled(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Ripple when Ripple is enabled, button should have ripple effect on desktop device 1`] = ` | ||
<div> | ||
<button | ||
class="p-button p-component" | ||
> | ||
<span | ||
class="p-button-label p-c" | ||
> | ||
</span> | ||
<span | ||
class="p-ink p-ink-active" | ||
role="presentation" | ||
style="height: 0px; width: 0px;" | ||
/> | ||
</button> | ||
</div> | ||
`; | ||
|
||
exports[`Ripple when Ripple is enabled, button should have ripple effect on touch device 1`] = ` | ||
<div> | ||
<button | ||
class="p-button p-component" | ||
> | ||
<span | ||
class="p-button-label p-c" | ||
> | ||
</span> | ||
<span | ||
class="p-ink p-ink-active" | ||
role="presentation" | ||
style="height: 0px; width: 0px;" | ||
/> | ||
</button> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,56 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/react'; | ||
|
||
// Set the userAgent inside the navigator | ||
Object.defineProperty( | ||
window.navigator, | ||
'userAgent', | ||
((value) => ({ | ||
get() { | ||
return value; | ||
}, | ||
set(v) { | ||
value = v; | ||
} | ||
}))(window.navigator.userAgent) | ||
); | ||
|
||
// Set the maxTouchPoints inside the navigator for touch devices | ||
Object.defineProperty( | ||
window.navigator, | ||
'maxTouchPoints', | ||
((value) => ({ | ||
get() { | ||
return value; | ||
}, | ||
set(v) { | ||
value = v; | ||
} | ||
}))(window.navigator.maxTouchPoints) | ||
); | ||
|
||
/** | ||
* Run a single snapshot test. | ||
* | ||
* @param {*} element the element to render | ||
* @param {*} name the name of the test | ||
*/ | ||
export function snapshot(element, name) { | ||
test(name, () => { | ||
expect(render(element).container).toMatchSnapshot(); | ||
}); | ||
} | ||
|
||
/** | ||
* Sets the browser user agent so it can simulate browsers. If its IOS adds touch setting to allow DomUtils.isTouchDevice. | ||
* | ||
* @param {*} name the name of the user agent. | ||
*/ | ||
export function userAgent(name) { | ||
// Set the userAgent that you wanna test on your function | ||
global.navigator.userAgent = name; | ||
|
||
if (name.match(/iPhone|iPad|iPod/i)) { | ||
global.navigator.maxTouchPoints = 2; | ||
} | ||
} |