import { microloansRoutes } from '../routes';

import {
  getMicroloansEntryPath,
  shouldShowMicroloansInSidebar,
} from './microloansNav';

describe('microloansNav', () => {
  describe('shouldShowMicroloansInSidebar', () => {
    it('is true when there is an offer', () => {
      expect(
        shouldShowMicroloansInSidebar({
          hasOffer: true,
          hasActivePlan: false,
          hasFinishedPlans: false,
        }),
      ).toBe(true);
    });

    it('is true when there is an active plan', () => {
      expect(
        shouldShowMicroloansInSidebar({
          hasOffer: false,
          hasActivePlan: true,
          hasFinishedPlans: false,
        }),
      ).toBe(true);
    });

    it('is true when there are finished plans', () => {
      expect(
        shouldShowMicroloansInSidebar({
          hasOffer: false,
          hasActivePlan: false,
          hasFinishedPlans: true,
        }),
      ).toBe(true);
    });

    it('is false when none of the three is present', () => {
      expect(
        shouldShowMicroloansInSidebar({
          hasOffer: false,
          hasActivePlan: false,
          hasFinishedPlans: false,
        }),
      ).toBe(false);
    });
  });

  describe('getMicroloansEntryPath', () => {
    it('prefers request-offer when there is an offer', () => {
      expect(
        getMicroloansEntryPath({
          hasOffer: true,
          hasActivePlan: true,
          hasFinishedPlans: true,
        }),
      ).toBe(microloansRoutes.requestOffer());
    });

    it('uses status when there is no offer but an active plan', () => {
      expect(
        getMicroloansEntryPath({
          hasOffer: false,
          hasActivePlan: true,
          hasFinishedPlans: true,
        }),
      ).toBe(microloansRoutes.status());
    });

    it('uses history when no offer, no active plan, and finished plans exist', () => {
      expect(
        getMicroloansEntryPath({
          hasOffer: false,
          hasActivePlan: false,
          hasFinishedPlans: true,
        }),
      ).toBe(microloansRoutes.history());
    });

    it('falls back to request-offer when none are present', () => {
      expect(
        getMicroloansEntryPath({
          hasOffer: false,
          hasActivePlan: false,
          hasFinishedPlans: false,
        }),
      ).toBe(microloansRoutes.requestOffer());
    });
  });
});
