-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
11 changed files
with
1,196 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
node_modules | ||
.cache | ||
dist | ||
doc | ||
doc | ||
yarn.lock |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import * as React from 'react'; | ||
//import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import { Thing } from '../src'; | ||
|
||
|
||
describe('it', () => { | ||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render(<Thing />, div); | ||
// ReactDOM.render(<Thing />, div); | ||
ReactDOM.unmountComponentAtNode(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,50 @@ | ||
import * as React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import { ProductCard } from "../../src/components"; | ||
import { products } from '../data/products'; | ||
|
||
|
||
const {act} = renderer; | ||
|
||
|
||
describe('ProductCard', () => { | ||
test('debe mostrar el componente correctamente', () => { | ||
const wrapper = renderer.create( | ||
<ProductCard product={products[0]} className='custom-class'> | ||
{ | ||
()=>( | ||
<h1>Product Card</h1> | ||
) | ||
} | ||
</ProductCard> | ||
) | ||
|
||
expect(wrapper.toJSON()).toMatchSnapshot(); | ||
}) | ||
|
||
test('debe incrementar el contador', () => { | ||
const wrapper = renderer.create( | ||
<ProductCard product={products[0]} className='custom-class'> | ||
{ | ||
({count, increaseBy})=>( | ||
<> | ||
<h1>Product Card</h1> | ||
<span>{count}</span> | ||
<button onClick={()=> increaseBy(1)}></button> | ||
</> | ||
) | ||
} | ||
</ProductCard> | ||
) | ||
|
||
let tree = wrapper.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
|
||
// Como hace el cambio en el estado, es necesario que esté dentro de 'act' | ||
act(()=>{ | ||
(tree as any).children[2].props.onClick(); | ||
}) | ||
tree = wrapper.toJSON(); | ||
expect((tree as any).children[1].children[0]).toBe('1'); | ||
}) | ||
}) |
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,29 @@ | ||
import * as React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import { ProductCard, ProductImage } from "../../src/components"; | ||
import { products } from '../data/products'; | ||
|
||
|
||
describe('ProductImage', () => { | ||
test('Debe mostrar el componente correctamente con la imagen personalizada', () => { | ||
const wrapper = renderer.create( | ||
<ProductImage img='hola.jpg' /> | ||
) | ||
|
||
expect(wrapper.toJSON()).toMatchSnapshot(); | ||
}) | ||
|
||
test('debe mostrar el componente con la imagen del producto', () => { | ||
const wrapper = renderer.create( | ||
<ProductCard product={products[1]} className='custom-class'> | ||
{ | ||
()=>( | ||
<ProductImage /> | ||
) | ||
} | ||
</ProductCard> | ||
) | ||
|
||
expect(wrapper.toJSON()).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,29 @@ | ||
import * as React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import { ProductCard, ProductTitle } from "../../src/components"; | ||
import { products } from '../data/products'; | ||
|
||
|
||
describe('ProductTitle', () => { | ||
test('Debe mostrar el componente correctamente con el título personalizado', () => { | ||
const wrapper = renderer.create( | ||
<ProductTitle title='Custom Product' className='custom-class' /> | ||
) | ||
|
||
expect(wrapper.toJSON()).toMatchSnapshot(); | ||
}) | ||
|
||
test('debe mostrar el componente con el nombre del producto', () => { | ||
const wrapper = renderer.create( | ||
<ProductCard product={products[0]} className='custom-class'> | ||
{ | ||
()=>( | ||
<ProductTitle /> | ||
) | ||
} | ||
</ProductCard> | ||
) | ||
|
||
expect(wrapper.toJSON()).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,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ProductCard debe incrementar el contador 1`] = ` | ||
<div | ||
className="productCard custom-class" | ||
> | ||
<h1> | ||
Product Card | ||
</h1> | ||
<span> | ||
0 | ||
</span> | ||
<button | ||
onClick={[Function]} | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`ProductCard debe mostrar el componente correctamente 1`] = ` | ||
<div | ||
className="productCard custom-class" | ||
> | ||
<h1> | ||
Product Card | ||
</h1> | ||
</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,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ProductImage Debe mostrar el componente correctamente con la imagen personalizada 1`] = ` | ||
<img | ||
alt="Product" | ||
className="productImg " | ||
src="hola.jpg" | ||
/> | ||
`; | ||
|
||
exports[`ProductImage debe mostrar el componente con la imagen del producto 1`] = ` | ||
<div | ||
className="productCard custom-class" | ||
> | ||
<img | ||
alt="Product" | ||
className="productImg " | ||
src="./coffee-mug2.png" | ||
/> | ||
</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,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ProductTitle Debe mostrar el componente correctamente con el título personalizado 1`] = ` | ||
<span | ||
className="productDescription custom-class" | ||
> | ||
Custom Product | ||
</span> | ||
`; | ||
|
||
exports[`ProductTitle debe mostrar el componente con el nombre del producto 1`] = ` | ||
<div | ||
className="productCard custom-class" | ||
> | ||
<span | ||
className="productDescription " | ||
> | ||
Coffee Mug - Card | ||
</span> | ||
</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,12 @@ | ||
export const products = [ | ||
{ | ||
id: '1', | ||
title: 'Coffee Mug - Card', | ||
img: './coffee-mug.png' | ||
}, | ||
{ | ||
id: '2', | ||
title: 'Coffee Mug - Meme', | ||
img: './coffee-mug2.png' | ||
} | ||
]; |
Oops, something went wrong.