import { mount, RouterLinkStub, createLocalVue } from "@vue/test-utils";
import Vuex from "vuex";
import GridItem from "@/components/Grid/GridItem.vue";

const localVue = createLocalVue();
localVue.use(Vuex);

describe("Test GridItem component.", () => {
  let store;

  const item = {
    id: 3,
    isFruit: true,
    name: "banana",
    image: "/image/path.jpg",
    price: "907.00",
    color: "#763e44",
    description: "Iusto illum vero voluptatem.",
    taste: "Handcrafted",
    expires: "2021-04-11T08:54:24.588Z"
  };

  beforeEach(() => {
    store = new Vuex.Store();
  });

  it("takes a snapshot of the component.", () => {
    const wrapper = mount(GridItem, {
      store,
      localVue,
      propsData: { item },
      stubs: ["router-link"]
    });
    expect(wrapper.html()).toMatchSnapshot();
  });

  it("checks link.", async () => {
    const wrapper = mount(GridItem, {
      store,
      localVue,
      propsData: { item },
      stubs: {
        RouterLink: RouterLinkStub
      }
    });

    expect(wrapper.findComponent(RouterLinkStub).props().to).toBe("/fruit/3");
  });
});
