Skip to content
Snippets Groups Projects
new-rent.spec.js 1.66 KiB
Newer Older
import { mount } from "@vue/test-utils";
henrikburmann's avatar
henrikburmann committed
import NewRent from "@/components/RentingComponents/NewRent.vue";
import axios from "axios";
henrikburmann's avatar
henrikburmann committed
// jest.mock("@/utils/token-utils", () => {
//   return {
//     tokenHeader: () => {
//       return {};
//     },
//     parseCurrentUser: () => {
//       return { accountId: 1 };
//     },
//   };
// });

jest.mock("@/utils/apiutil", () => {
  return {
henrikburmann's avatar
henrikburmann committed
    postNewRent: () => {
      return new Promise((resolve) => {
        resolve([]);
      });
henrikburmann's avatar
henrikburmann committed
    },
  };
});
jest.mock("axios");


describe("Confirm and send a rent request", () => {
  let wrapper;
henrikburmann's avatar
henrikburmann committed
  beforeEach(() => {
    wrapper = mount(NewRent, {
      props: {
        newRentBox: {
          title: "Telt",
          listingID: 1,
          fromTime: "2022-09-19",
          toTime: "2022-09-23",
          price: 200,
          renterId: 1,
          isAccepted: false,
        },
      },
henrikburmann's avatar
henrikburmann committed
  });
henrikburmann's avatar
henrikburmann committed
  it("Is instansiated", () => {
    expect(wrapper.exists()).toBeTruthy();
  });
  it("Check that fields show correct informations", () => {
henrikburmann's avatar
henrikburmann committed
    expect(wrapper.find("#rentTitle").text()).toEqual("Telt");
    expect(wrapper.find("#fromTime").text()).toMatch("19. September 2022");
    expect(wrapper.find("#toTime").text()).toMatch("23. September 2022");
    expect(wrapper.find("#price").text()).toEqual("Totaltpris: 200 kr");
  });

  it("Check that clicking rent opens confirmbox",async () => {
henrikburmann's avatar
henrikburmann committed
    const button = wrapper.find("#confirmButton");
    axios.post.mockResolvedValueOnce();
    button.trigger("click");   
henrikburmann's avatar
henrikburmann committed
    await wrapper.vm.$nextTick();
    

    // expect(wrapper.find("notification-modal").exists()).toBeTruthy();
    expect(axios.post).toHaveBeenCalledTimes(1);
  })
henrikburmann's avatar
henrikburmann committed
});