2018-06-04 21:28:18 +00:00
|
|
|
import $ from 'jquery';
|
|
|
|
import preserveUrlFragment from '~/pages/sessions/new/preserve_url_fragment';
|
|
|
|
|
|
|
|
describe('preserve_url_fragment', () => {
|
2020-06-10 00:08:55 +00:00
|
|
|
const findFormAction = selector => {
|
|
|
|
return $(`.omniauth-container ${selector}`)
|
|
|
|
.parent('form')
|
|
|
|
.attr('action');
|
|
|
|
};
|
|
|
|
|
2019-03-26 16:03:28 +00:00
|
|
|
preloadFixtures('sessions/new.html');
|
2018-06-04 21:28:18 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-03-26 16:03:28 +00:00
|
|
|
loadFixtures('sessions/new.html');
|
2018-06-04 21:28:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('adds the url fragment to all login and sign up form actions', () => {
|
|
|
|
preserveUrlFragment('#L65');
|
|
|
|
|
2018-12-02 06:46:11 +00:00
|
|
|
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');
|
2018-06-04 21:28:18 +00:00
|
|
|
});
|
|
|
|
|
2018-12-02 06:46:11 +00:00
|
|
|
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();
|
|
|
|
|
2020-06-10 00:08:55 +00:00
|
|
|
expect(findFormAction('#oauth-login-cas3')).toBe('http://test.host/users/auth/cas3');
|
2018-06-04 21:28:18 +00:00
|
|
|
|
2020-06-10 00:08:55 +00:00
|
|
|
expect(findFormAction('#oauth-login-auth0')).toBe('http://test.host/users/auth/auth0');
|
2018-12-02 06:46:11 +00:00
|
|
|
});
|
2018-11-27 13:16:24 +00:00
|
|
|
|
2018-12-02 06:46:11 +00:00
|
|
|
describe('adds "redirect_fragment" query parameter to OmniAuth login buttons', () => {
|
|
|
|
it('when "remember_me" is not present', () => {
|
|
|
|
preserveUrlFragment('#L65');
|
2018-11-27 13:16:24 +00:00
|
|
|
|
2020-06-10 00:08:55 +00:00
|
|
|
expect(findFormAction('#oauth-login-cas3')).toBe(
|
2018-12-02 06:46:11 +00:00
|
|
|
'http://test.host/users/auth/cas3?redirect_fragment=L65',
|
|
|
|
);
|
|
|
|
|
2020-06-10 00:08:55 +00:00
|
|
|
expect(findFormAction('#oauth-login-auth0')).toBe(
|
2018-12-02 06:46:11 +00:00
|
|
|
'http://test.host/users/auth/auth0?redirect_fragment=L65',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('when "remember-me" is present', () => {
|
2020-06-10 00:08:55 +00:00
|
|
|
$('.omniauth-btn')
|
|
|
|
.parent('form')
|
|
|
|
.attr('action', (i, href) => `${href}?remember_me=1`);
|
|
|
|
|
2018-12-02 06:46:11 +00:00
|
|
|
preserveUrlFragment('#L65');
|
|
|
|
|
2020-06-10 00:08:55 +00:00
|
|
|
expect(findFormAction('#oauth-login-cas3')).toBe(
|
2018-12-02 06:46:11 +00:00
|
|
|
'http://test.host/users/auth/cas3?remember_me=1&redirect_fragment=L65',
|
|
|
|
);
|
|
|
|
|
2020-06-10 00:08:55 +00:00
|
|
|
expect(findFormAction('#oauth-login-auth0')).toBe(
|
2018-12-02 06:46:11 +00:00
|
|
|
'http://test.host/users/auth/auth0?remember_me=1&redirect_fragment=L65',
|
|
|
|
);
|
|
|
|
});
|
2018-06-04 21:28:18 +00:00
|
|
|
});
|
|
|
|
});
|