-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84cefa1
commit 820dd2a
Showing
9 changed files
with
319 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import React, { useState } from 'react'; | ||
import TestRenderer from 'react-test-renderer'; | ||
import '@testing-library/jest-dom'; | ||
import Alpha, { BACKGROUND_IMG } from '../packages/color-alpha/src'; | ||
|
||
it('Alpha', async () => { | ||
const MyComponent = () => { | ||
const [hsva, setHsva] = useState({ h: 0, s: 0, v: 68, a: 1 }); | ||
return ( | ||
<Alpha | ||
hsva={hsva} | ||
onChange={(newAlpha) => { | ||
setHsva({ ...hsva, ...newAlpha }); | ||
}} | ||
/> | ||
); | ||
}; | ||
const component = TestRenderer.create(<MyComponent />); | ||
let tree = component.toJSON(); | ||
if (tree && !Array.isArray(tree)) { | ||
expect(tree.type).toEqual('div'); | ||
expect(tree.props.className).toEqual('w-color-alpha '); | ||
expect(tree.props.style).toMatchObject({ | ||
width: 320, | ||
height: 16, | ||
borderRadius: 0, | ||
position: 'relative', | ||
backgroundColor: '#fff', | ||
}); | ||
expect(tree.props.style.background).toEqual(`url(${BACKGROUND_IMG}) left center`); | ||
if (tree.children) { | ||
expect(tree.children.length).toEqual(2); | ||
tree.children.forEach((child) => { | ||
if (typeof child === 'object') { | ||
expect(child.type).toEqual('div'); | ||
} | ||
}); | ||
} | ||
} | ||
}); |
30 changes: 15 additions & 15 deletions
30
packages/color-convert/tests/index.test.ts → test/convert.test.tsx
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 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import React, { useState } from 'react'; | ||
import TestRenderer from 'react-test-renderer'; | ||
import '@testing-library/jest-dom'; | ||
import Interactive from '../packages/drag-event-interactive/src'; | ||
|
||
it('Interactive', async () => { | ||
const MyComponent = () => { | ||
return <Interactive />; | ||
}; | ||
const component = TestRenderer.create(<MyComponent />); | ||
let tree = component.toJSON(); | ||
if (tree && !Array.isArray(tree)) { | ||
expect(tree.type).toEqual('div'); | ||
expect(tree.props).toHaveProperty('onMouseDown'); | ||
expect(tree.props).toHaveProperty('onTouchStart'); | ||
} | ||
}); |
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,75 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import React, { useState } from 'react'; | ||
import TestRenderer from 'react-test-renderer'; | ||
import { screen, render, fireEvent } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import Hue from '../packages/color-hue/src'; | ||
import { BACKGROUND_IMG } from '../packages/color-alpha/src'; | ||
|
||
it('Hue', async () => { | ||
const MyComponent = () => { | ||
const [hsva, setHsva] = useState({ h: 0, s: 0, v: 68, a: 1 }); | ||
return ( | ||
<Hue | ||
hue={hsva.h} | ||
onChange={(newHue) => { | ||
setHsva({ ...hsva, ...newHue }); | ||
}} | ||
/> | ||
); | ||
}; | ||
const component = TestRenderer.create(<MyComponent />); | ||
let tree = component.toJSON(); | ||
if (tree && !Array.isArray(tree)) { | ||
expect(tree.type).toEqual('div'); | ||
expect(tree.props.className).toEqual('w-color-alpha w-color-hue '); | ||
expect(tree.props.style).toMatchObject({ | ||
width: 320, | ||
height: 16, | ||
borderRadius: 0, | ||
position: 'relative', | ||
backgroundColor: '#fff', | ||
}); | ||
expect(tree.props.style.background).toEqual(`url(${BACKGROUND_IMG}) left center`); | ||
if (tree.children) { | ||
expect(tree.children.length).toEqual(2); | ||
tree.children.forEach((child, idx) => { | ||
if (typeof child === 'object') { | ||
expect(child.type).toEqual('div'); | ||
if (idx === 0) { | ||
expect(child.props.style).toMatchObject({ | ||
inset: 0, | ||
position: 'absolute', | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
// it('Hue onChange', async () => { | ||
// const MyComponent = () => { | ||
// const [hsva, setHsva] = useState({ h: 209, s: 36, v: 90, a: 1 }); | ||
// return ( | ||
// <div> | ||
// <Hue | ||
// hue={hsva.h} | ||
// data-testid="custom-element" | ||
// innerProps={{ | ||
// // ['data-testid']: 'custom-element', | ||
// }} | ||
// onChange={(newHue) => { | ||
// console.log('newHue') | ||
// // setHsva({ ...hsva, ...newHue }); | ||
// }} | ||
// /> | ||
// <div>Load Greeting</div> | ||
// </div> | ||
// ); | ||
// }; | ||
// render(<MyComponent />); | ||
// fireEvent.click(screen.getByTestId('custom-element')); | ||
// }); |
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,33 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import React, { useState } from 'react'; | ||
import TestRenderer from 'react-test-renderer'; | ||
import '@testing-library/jest-dom'; | ||
import Saturation from '../packages/color-saturation/src'; | ||
|
||
it('Saturation', async () => { | ||
const MyComponent = () => { | ||
const [hsva, setHsva] = useState({ h: 0, s: 0, v: 68, a: 1 }); | ||
return ( | ||
<Saturation | ||
hsva={hsva} | ||
onChange={(newColor) => { | ||
setHsva({ ...hsva, ...newColor, a: hsva.a }); | ||
}} | ||
/> | ||
); | ||
}; | ||
const component = TestRenderer.create(<MyComponent />); | ||
let tree = component.toJSON(); | ||
if (tree && !Array.isArray(tree)) { | ||
expect(tree.type).toEqual('div'); | ||
expect(tree.props.className).toEqual('w-color-saturation '); | ||
expect(tree.props.style).toMatchObject({ | ||
width: 200, | ||
height: 200, | ||
position: 'relative', | ||
backgroundColor: 'hsl(0,100%, 50%)', | ||
}); | ||
} | ||
}); |
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,52 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import React, { useState } from 'react'; | ||
import TestRenderer from 'react-test-renderer'; | ||
import '@testing-library/jest-dom'; | ||
import ShadeSlider from '../packages/color-shade-slider/src'; | ||
import { BACKGROUND_IMG } from '../packages/color-alpha/src'; | ||
|
||
it('ShadeSlider', async () => { | ||
const MyComponent = () => { | ||
const [hsva, setHsva] = useState({ h: 0, s: 0, v: 68, a: 1 }); | ||
return ( | ||
<ShadeSlider | ||
hsva={hsva} | ||
onChange={(newShade) => { | ||
setHsva({ ...hsva, ...newShade }); | ||
}} | ||
/> | ||
); | ||
}; | ||
const component = TestRenderer.create(<MyComponent />); | ||
let tree = component.toJSON(); | ||
if (tree && !Array.isArray(tree)) { | ||
expect(tree.type).toEqual('div'); | ||
expect(tree.props.className).toEqual('w-color-alpha w-color-saturation '); | ||
expect(tree.props.style).toMatchObject({ | ||
width: 320, | ||
height: 16, | ||
borderRadius: 0, | ||
position: 'relative', | ||
backgroundColor: '#fff', | ||
}); | ||
expect(tree.props.style.background).toEqual(`url(${BACKGROUND_IMG}) left center`); | ||
if (tree.children) { | ||
expect(tree.children.length).toEqual(2); | ||
tree.children.forEach((child, idx) => { | ||
if (typeof child === 'object') { | ||
expect(child.type).toEqual('div'); | ||
} | ||
if (idx === 0 && typeof child === 'object') { | ||
expect(child.props.style).toMatchObject({ | ||
inset: 0, | ||
position: 'absolute', | ||
background: 'linear-gradient(to right, hsla(0, 100%, 50%, 1), rgb(0, 0, 0))', | ||
borderRadius: 0, | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
}); |
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,43 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import React, { useState } from 'react'; | ||
import TestRenderer from 'react-test-renderer'; | ||
import '@testing-library/jest-dom'; | ||
import Sketch from '../packages/color-sketch/src'; | ||
|
||
it('Sketch', async () => { | ||
const MyComponent = () => { | ||
const [hsva, setHsva] = useState({ h: 0, s: 0, v: 68, a: 1 }); | ||
return ( | ||
<Sketch | ||
style={{ marginLeft: 20 }} | ||
color={hsva} | ||
onChange={(color) => { | ||
setHsva({ ...hsva, ...color.hsv }); | ||
}} | ||
/> | ||
); | ||
}; | ||
const component = TestRenderer.create(<MyComponent />); | ||
let tree = component.toJSON(); | ||
if (tree && !Array.isArray(tree)) { | ||
expect(tree.type).toEqual('div'); | ||
expect(tree.props.className).toEqual('w-color-sketch '); | ||
expect(tree.props.style).toMatchObject({ | ||
background: 'rgb(255, 255, 255)', | ||
borderRadius: 4, | ||
boxShadow: 'rgb(0 0 0 / 15%) 0px 0px 0px 1px, rgb(0 0 0 / 15%) 0px 8px 16px', | ||
width: 218, | ||
marginLeft: 20, | ||
}); | ||
if (tree.children) { | ||
expect(tree.children.length).toEqual(2); | ||
tree.children.forEach((child) => { | ||
if (typeof child === 'object') { | ||
expect(child.type).toEqual('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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import React, { useState } from 'react'; | ||
import TestRenderer from 'react-test-renderer'; | ||
import '@testing-library/jest-dom'; | ||
import Slider from '../packages/color-slider/src'; | ||
|
||
it('Slider', async () => { | ||
const MyComponent = () => { | ||
const [hsva, setHsva] = useState({ h: 0, s: 0, v: 68, a: 1 }); | ||
return ( | ||
<Slider | ||
color={hsva} | ||
onChange={(newShade) => { | ||
setHsva({ ...hsva, ...newShade }); | ||
}} | ||
/> | ||
); | ||
}; | ||
const component = TestRenderer.create(<MyComponent />); | ||
let tree = component.toJSON(); | ||
if (tree && !Array.isArray(tree)) { | ||
expect(tree.type).toEqual('div'); | ||
expect(tree.props.className).toEqual('w-color-slider'); | ||
expect(tree.props.style).toMatchObject({ display: 'flex' }); | ||
if (tree.children) { | ||
expect(tree.children.length).toEqual(5); | ||
tree.children.forEach((child) => { | ||
if (typeof child === 'object') { | ||
expect(child.type).toEqual('div'); | ||
} | ||
}); | ||
} | ||
} | ||
}); |