import React from 'react';
import { expect } from 'chai';
import { shallow, mount, render } from 'enzyme';
import sinon from 'sinon';

import ProductsList from '../ProductList'
import messages from './en.js'

describe('component view <ProductList />', () => {

    const products = [{id: 777, description: 'product description'}]
    const onAddProduct = sinon.spy()
    const onDeleteProduct = sinon.spy()

    it('can render ProductList', () => {
        const wrapper = shallow(<ProductsList products={ products }
                                              addProduct={ onAddProduct }
                                              deleteProduct={ onDeleteProduct } />);

        expect(wrapper.html().includes(messages.title)).to.equal(true)
        expect(wrapper.html().includes(messages.addProductButton)).to.equal(true)
        expect(wrapper.html().includes(messages.deleteProductButton)).to.equal(true)

        expect(wrapper.html().includes(products[0].description)).to.equal(true)
        expect(wrapper.html().includes(products[0].id)).to.equal(true)

        wrapper.find('button.addProduct').simulate('click')
        expect(onAddProduct.calledOnce).to.equal(true)

        wrapper.find('button.deleteProduct').simulate('click')
        expect(onDeleteProduct.calledOnce).to.equal(true)
    });

});

@@ -405,53 +405,8 @@
 ()%0A%0A
-    it('can render ProductList', () =%3E %7B%0A    
     
@@ -507,20 +507,16 @@
         
- 
-   
 addProdu
@@ -535,20 +535,16 @@
 oduct %7D%0A
-    
         
@@ -617,16 +617,54 @@
 %7D /%3E);%0A%0A
+    it('can render messages', () =%3E %7B%0A
         
@@ -885,32 +885,90 @@
 .to.equal(true)%0A
+    %7D);%0A%0A    it('can render product informations', () =%3E %7B
 %0A        expect(
@@ -1095,32 +1095,80 @@
 .to.equal(true)%0A
+    %7D);%0A%0A    it('can handle addProduct', () =%3E %7B
 %0A        wrapper
@@ -1267,16 +1267,67 @@
 l(true)%0A
+    %7D);%0A%0A    it('can handle deleteProduct', () =%3E %7B
 %0A       

refactor productList tests