import { HomeAnnouncementContainer } from "../home-announcement-container";
import * as sinon from "sinon";
import { canvasEnvironmentFixture1 } from "./home-announcement.fixture";
import { formatDateForCanvas, getOneYearAgoToday } from "../../../utils/utils";
describe("lucan-home-announcement-container", () => {
  let element;
  const RealDate = Date.now;
  let testDate;
  beforeAll(() => {
    testDate = new Date();
    global.Date.now = jest.fn(() => new Date(testDate).getTime());
  });
  afterAll(() => {
    global.Date.now = RealDate;
  });
  beforeEach(() => {
    element = new HomeAnnouncementContainer();
    const glob = global;
    glob.window = {
      ENV: canvasEnvironmentFixture1
    };
  });
  it("should build", () => {
    expect(element).toBeTruthy();
  });
  describe("connectedCallback", () => {
    let fetchAnnouncementsStub;
    beforeEach(() => {
      fetchAnnouncementsStub = sinon.stub(element, "fetchAnnouncements");
    });
    it("should call fetchAnnouncements with the correct URL", () => {
      const expectedStartDate = formatDateForCanvas(getOneYearAgoToday(testDate));
      const expectedEndDate = formatDateForCanvas(testDate);
      element.connectedCallback();
      expect(fetchAnnouncementsStub.args[0][0]).toBe(`https://libertyuniversity.beta.instructure.com/api/v1/announcements?context_codes[]=course_35152&start_date=${expectedStartDate}&end_date=${expectedEndDate}`);
    });
  });
  describe("fetchAnnouncements", () => {
    beforeEach(() => {
      const glob = global;
      glob.fetch = () => {
        return Promise.resolve({
          json: () => {
            return Promise.resolve("too");
          }
        });
      };
    });
    it("should set current announcements with the response", async () => {
      await element.fetchAnnouncements("foo");
      expect(element.announcements).toBe("too");
    });
  });
});
//# sourceMappingURL=home-announcement-container.spec.js.map
