import axios from 'axios';
import courses from '../mixins/courses';

import {mount} from '@vue/test-utils';

import Vuex from 'vuex';

import inst_schedule from '../vuex/store/schedule/instructor';
import {createLocalVue} from './helper';

import UwCard from '../components/_templates/card.vue';
import InstructorCourseSummery from
  '../components/home/inst_course_summary/summary.vue';

import mockBill2013Summer from
  './mock_data/inst_schedule/bill2013summer.json';
import mockBillpce2013Summer from
  './mock_data/inst_schedule/billpce2013summer.json';
import mockBillsea2013Spring from
  './mock_data/inst_schedule/billsea2013spring.json';
import mockNoCourse2013Summer from
  './mock_data/inst_schedule/2013summer.json';

const localVue = createLocalVue(Vuex);
localVue.mixin(courses);

jest.mock('axios');

describe('Instructor Teaching Summary', () => {
  let store;

  beforeEach(() => {
    store = new Vuex.Store({
      modules: {
        'inst_schedule': inst_schedule,
      },
      state: {
        user: {
          netid:"billsea",
          affiliations: {
            instructor: true,
          }
        },
        termData: {
          year: 2013,
          quarter: 'spring',
        },
        nextTerm: {
          year: 2013,
          quarter: 'summer',
        },
        cardDisplayDates: {
          comparison_date: '2013-04-15T00:00:01',
        },
      }
    });
  });

  it('Verify current quarter summary card', async () => {
    axios.get.mockImplementation((url) => {
      const urlData = {
        '/api/v1/instructor_schedule/current': mockBillsea2013Spring,
      };
      return Promise.resolve({data: urlData[url], status: 200});
    });

    const wrapper = mount(InstructorCourseSummery, {store, localVue});
    await new Promise((r) => setTimeout(r, 30));

    expect(
      inst_schedule.getters.isReadyTagged(
        wrapper.vm.$store.state.inst_schedule
      )("current"),
    ).toBeTruthy();

    expect(
      inst_schedule.getters.isErroredTagged(
        wrapper.vm.$store.state.inst_schedule
      )("current"),
    ).toBeFalsy();

    expect(
      inst_schedule.getters.statusCodeTagged(
        wrapper.vm.$store.state.inst_schedule
      )("current"),
    ).toEqual(200);

    expect(
      wrapper.findComponent(UwCard).exists()
    ).toBe(true);

    expect(
      wrapper.find('h2').text()
    ).toEqual('Spring 2013 Teaching Schedule');

  });

  it('Verify no future quarter summary card', async () => {
    axios.get.mockImplementation((url) => {
      const urlData = {
          '/api/v1/instructor_schedule/2013,summer': mockNoCourse2013Summer,
        };
        return Promise.resolve({data: urlData[url], status: 200});
      });

    const wrapper = mount(
      InstructorCourseSummery, {
        store,
        localVue,
        propsData: {
          term: '2013,summer',
        }
      }
    );
    await new Promise((r) => setTimeout(r, 30));

    expect(
      inst_schedule.getters.isReadyTagged(
        wrapper.vm.$store.state.inst_schedule
      )("2013,summer"),
    ).toBeTruthy();

    expect(
      inst_schedule.getters.isErroredTagged(
        wrapper.vm.$store.state.inst_schedule
      )("2013,summer"),
    ).toBeFalsy();

    expect(
      inst_schedule.getters.statusCodeTagged(
        wrapper.vm.$store.state.inst_schedule
      )("2013,summer"),
    ).toEqual(200);

    expect(wrapper.findComponent(UwCard).exists()).toBe(false);
  });
});

@@ -380,16 +380,195 @@
 ry.vue';
+%0Aimport UwSummerSectionList from%0A  '../components/home/inst_course_summary/summer-list.vue';%0Aimport UwSectionList from%0A  '../components/home/inst_course_summary/section-list.vue';
 %0A%0Aimport
@@ -3610,13 +3610,1187 @@
 );%0A  %7D);
+%0A%0A  it('Verify Summer quarter summary card', async () =%3E %7B%0A    axios.get.mockImplementation((url) =%3E %7B%0A      const urlData = %7B%0A          '/api/v1/instructor_schedule/2013,summer': mockBillpce2013Summer,%0A        %7D;%0A        return Promise.resolve(%7Bdata: urlData%5Burl%5D, status: 200%7D);%0A      %7D);%0A%0A    const wrapper = mount(%0A      InstructorCourseSummery, %7B%0A        store,%0A        localVue,%0A        propsData: %7B%0A          term: '2013,summer',%0A        %7D%0A      %7D%0A    );%0A    await new Promise((r) =%3E setTimeout(r, 30));%0A%0A    expect(%0A      inst_schedule.getters.isReadyTagged(%0A        wrapper.vm.$store.state.inst_schedule%0A      )(%222013,summer%22),%0A    ).toBeTruthy();%0A%0A    expect(%0A      inst_schedule.getters.isErroredTagged(%0A        wrapper.vm.$store.state.inst_schedule%0A      )(%222013,summer%22),%0A    ).toBe(false);%0A%0A    expect(%0A      inst_schedule.getters.statusCodeTagged(%0A        wrapper.vm.$store.state.inst_schedule%0A      )(%222013,summer%22),%0A    ).toEqual(200);%0A%0A    expect(wrapper.findComponent(UwCard).exists()).toBe(true);%0A    expect(wrapper.findComponent(%0A      UwSummerSectionList).exists()).toBe(true);%0A    expect(wrapper.findAllComponents(UwSectionList).length).toBe(2);%0A  %7D);
 %0A%7D);%0A

Add test of summer term