import Vue from 'vue'
import { mount } 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(),
    folio: faker.finance.bic(),
    subtotal: faker.finance.amount(),
    total: faker.finance.amount(),
    status: 1
  });
}

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(),
  setModalVisible: jest.fn(),
  setModalImportVisible: 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 = mount(PurchaseOrders, {
      store,
    })

    setTimeout(() => {
      expect(wrapper.findAll('.tr-table')).toHaveLength(mockPurchaseOrders.length)

      done()
    }, 1500)
  })

})
