import Vue from 'vue'
import { shallowMount } from '@vue/test-utils'
import faker from 'faker'

import configStore from '../mocks/config-store'
import storeMock from '../mocks/store-mock'

import PurchaseOrders from '@/views/PurchaseOrders.vue'

const mockPurchaseOrders = []

for (let i = 0; i < 10; i++) {
  mockPurchaseOrders.push({
    id: faker.random.number()
  });
}

Vue.prototype.$auth = {
  user: jest.fn(() => ({
    name,
  }))
}

jest.doMock('axios', () => {
  return {
    get: jest.fn(() => Promise.resolve({
      status: 200,
      data: {
        data: mockPurchaseOrders,
      },
    })),
  };
});

storeMock.state = {
  user: {
    name: faker.name.findName(),
    view_permissions: 'Admin',
  }
}

storeMock.modules.PurchaseOrders.actions = {
  deletePurchaseOrder: jest.fn(),
  deletePurchaseOrders: jest.fn(),
  loadPurchaseOrders: jest.fn(),
  actionPurchaseOrder: jest.fn(),
  loadCatalog: jest.fn(),
  printReport: jest.fn(),
  applyFilter: jest.fn(),
  clearFilter: jest.fn(),
}

storeMock.modules.PurchaseOrders.state.purchaseOrders = mockPurchaseOrders;

describe('PurchaseOrders.vue', () => {

  const store = configStore(Vue, storeMock)
  beforeEach(() => {
    jest.resetModules()
    jest.clearAllMocks()
  })

  it('should render correct contents', (done) => {
    const wrapper = shallowMount(PurchaseOrders, {
      store,
    })

    setTimeout(() => {
      // console.log(wrapper.html());
      expect(wrapper.html()).toBe('<div class="crud"><div class="container-fluid"><vm-row-stub vmtype="flex" vmw="12" class="heading"><vm-col-stub vmw="12" vmxs="" vmsm="12" vmlg="6" vmoffset="0" vmtype="flex" vmalign="center"><div><h2>Ordenes de Compra:</h2><span>Un resumen de sus Ordenes de Compra</span></div><div style="display: none;"><vm-button-stub type="default" color="primary" lineorigin="center" lineposition="bottom" gradientdirection="30deg" gradientcolorsecondary="primary" icon="list" iconpack="eva" href=""></vm-button-stub><vm-button-stub type="default" color="rgba(var(--gray),1)" lineorigin="center" lineposition="bottom" gradientdirection="30deg" gradientcolorsecondary="primary" icon="grid" iconpack="eva" href=""></vm-button-stub></div></vm-col-stub><vm-col-stub vmw="12" vmxs="" vmsm="6" vmlg="6" vmoffset="0" vmtype="flex" vmjustify="flex-end" vmalign="center"><div><vm-button-stub type="filled" color="primary" lineorigin="center" lineposition="bottom" gradientdirection="30deg" gradientcolorsecondary="primary" icon="plus" iconpack="eva" href="">Agregar</vm-button-stub><vm-tooltip-stub text="Más opciones" position="top" delay=".5s"><vm-dropdown-stub vmtriggerclick="true" color="primary" vmcustomcontent="true"><vm-button-stub type="border" color="#afbbc6" lineorigin="center" lineposition="bottom" gradientdirection="30deg" gradientcolorsecondary="primary" icon="more-horizotnal" iconpack="eva" href=""></vm-button-stub><vm-dropdown-menu-stub><vm-dropdown-item-stub class="d-flex justify-content-between"><vm-icon-stub icon="printer-outline" iconpack="eva"></vm-icon-stub>&nbsp;Imprimir</vm-dropdown-item-stub><vm-dropdown-item-stub disabled="true" class="d-flex justify-content-between"><vm-icon-stub icon="trash-2-outline" iconpack="eva"></vm-icon-stub>&nbsp;Eliminar</vm-dropdown-item-stub></vm-dropdown-menu-stub></vm-dropdown-stub></vm-tooltip-stub></div></vm-col-stub></vm-row-stub><vm-row-stub vmtype="flex" vmw="12"><vm-col-stub vmw="12" vmxs="" vmsm="12" vmlg="" vmoffset="0" class="card"><vm-table-stub value="" color="primary" maxheight="350px" multiple="true" data="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]" maxitems="5"><template></template><template></template></vm-table-stub><vm-pagination-stub color="primary" total="1" value="1" max="9" goto="true" previcon="chevron-left" nexticon="chevron-right" iconpack="eva"></vm-pagination-stub><!----></vm-col-stub></vm-row-stub></div></div>')
      // expect(wrapper.findAll('.tr-table')).toHaveLength(mockPurchaseOrders.length)
      // expect(wrapper.findAll('.vm-table--td span').at(0).text()).toEqual(mockPurchaseOrders[0].contact);

      done()
    }, 1500)
  })

})
