import commonModule from '../..';

describe('wsFooter directive', () => {
  let outerScope;
  let isolatedScope;
  let element;

  beforeEach(angular.mock.module(commonModule));

  function injectElement(elementHtml) {
    beforeEach(angular.mock.inject(($rootScope, $compile) => {
      outerScope = $rootScope.$new();
      element = angular.element(elementHtml);
      $compile(element)(outerScope);
      outerScope.$digest();
      isolatedScope = element.isolateScope();
    }));
  }

  describe('with no attributes set', () => {
    injectElement('<ws-footer />');

    describe('nav.currentYear', () => {
      it('returns a 4-digit year starting with 2', () => {
        expect(isolatedScope.nav.currentYear).toMatch(/^2[0-9]{3}$/);
      });
    });

    describe('nav.location.sages', () => {
      it('returns the link on www site', () => {
        expect(isolatedScope.nav.location.sages('why-invest')).toEqual('https://www.wealthsimple.com/why-invest');
      });
    });

    describe('nav.location.blog', () => {
      it('returns the link on grow site', () => {
        expect(isolatedScope.nav.location.blog('adam-tune-money-diary')).toEqual('http://grow.wealthsimple.com/adam-tune-money-diary');
      });
    });

    describe('generated HTML', () => {
      it('includes links to Google Play and iOS apps', () => {
        expect(element.html()).toContain('https://itunes.apple.com/ca/app/wealthsimple/id948087968');
        expect(element.html()).toContain('https://play.google.com/store/apps/details?id=com.wealthsimple');
      });

      it('includes social media links', () => {
        expect(element.html()).toContain('https://twitter.com/wealthsimple');
        expect(element.html()).toContain('https://www.facebook.com/wealthsimple');
        expect(element.html()).toContain('https://www.linkedin.com/company/wealthsimple');
      });

      it('includes our support email', () => {
        expect(element.html()).toContain('support@wealthsimple.com');
      });

      it('includes our office address', () => {
        expect(element.html()).toContain('860 Richmond Street West, 3rd floor');
        expect(element.html()).toContain('Toronto, ON, M6J 1C9, Canada');
      });

      it('includes a link to Grow', () => {
        expect(element.html()).toContain('http://grow.wealthsimple.com/');
      });

      it('includes a link to FAQs', () => {
        expect(element.html()).toContain('http://help.wealthsimple.com/');
      });
    });
  });

  describe('with fr_CA as the language, and then toggling to en_CA', () => {
    injectElement('<ws-footer lang="\'fr_CA\'" />');

    it('outputs in French first, then English', () => {
      expect(element.html()).toContain('Notre mission');
      expect(element.html()).not.toContain('Our mission');

      isolatedScope.setLanguage('en_CA');
      outerScope.$digest();
      expect(element.html()).toContain('Our mission');
      expect(element.html()).not.toContain('Notre mission');
    });
  });

  describe('with en_CA as the only supported language', () => {
    injectElement('<ws-footer langs="\'en_CA\'" />');

    it('only outputs English in the language toggler', () => {
      expect(element.html()).toContain('English');
      expect(element.html()).not.toContain('Français');
    });
  });
});
