preserve_url_fragment_spec.js 2.0 KB
Newer Older
S
Scott Escue 已提交
1 2 3 4
import $ from 'jquery';
import preserveUrlFragment from '~/pages/sessions/new/preserve_url_fragment';

describe('preserve_url_fragment', () => {
5
  preloadFixtures('sessions/new.html');
S
Scott Escue 已提交
6 7

  beforeEach(() => {
8
    loadFixtures('sessions/new.html');
S
Scott Escue 已提交
9 10 11 12 13
  });

  it('adds the url fragment to all login and sign up form actions', () => {
    preserveUrlFragment('#L65');

14 15
    expect($('#new_user').attr('action')).toBe('http://test.host/users/sign_in#L65');
    expect($('#new_new_user').attr('action')).toBe('http://test.host/users#L65');
S
Scott Escue 已提交
16 17
  });

18 19 20 21 22 23 24 25 26 27 28
  it('does not add an empty url fragment to login and sign up form actions', () => {
    preserveUrlFragment();

    expect($('#new_user').attr('action')).toBe('http://test.host/users/sign_in');
    expect($('#new_new_user').attr('action')).toBe('http://test.host/users');
  });

  it('does not add an empty query parameter to OmniAuth login buttons', () => {
    preserveUrlFragment();

    expect($('#oauth-login-cas3').attr('href')).toBe('http://test.host/users/auth/cas3');
S
Scott Escue 已提交
29

S
Scott Escue 已提交
30
    expect($('.omniauth-container #oauth-login-auth0').attr('href')).toBe(
31
      'http://test.host/users/auth/auth0',
S
Scott Escue 已提交
32
    );
33
  });
S
Scott Escue 已提交
34

35 36 37
  describe('adds "redirect_fragment" query parameter to OmniAuth login buttons', () => {
    it('when "remember_me" is not present', () => {
      preserveUrlFragment('#L65');
S
Scott Escue 已提交
38

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
      expect($('#oauth-login-cas3').attr('href')).toBe(
        'http://test.host/users/auth/cas3?redirect_fragment=L65',
      );

      expect($('.omniauth-container #oauth-login-auth0').attr('href')).toBe(
        'http://test.host/users/auth/auth0?redirect_fragment=L65',
      );
    });

    it('when "remember-me" is present', () => {
      $('a.omniauth-btn').attr('href', (i, href) => `${href}?remember_me=1`);
      preserveUrlFragment('#L65');

      expect($('#oauth-login-cas3').attr('href')).toBe(
        'http://test.host/users/auth/cas3?remember_me=1&redirect_fragment=L65',
      );

      expect($('#oauth-login-auth0').attr('href')).toBe(
        'http://test.host/users/auth/auth0?remember_me=1&redirect_fragment=L65',
      );
    });
S
Scott Escue 已提交
60 61
  });
});