debian-mirror-gitlab/spec/frontend/pages/sessions/new/preserve_url_fragment_spec.js

69 lines
2.2 KiB
JavaScript
Raw Normal View History

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