summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/assets/javascripts/pages/sessions/new/preserve_url_fragment.js9
-rw-r--r--spec/javascripts/lib/utils/url_utility_spec.js17
-rw-r--r--spec/javascripts/oauth_remember_me_spec.js6
-rw-r--r--spec/javascripts/pages/sessions/new/preserve_url_fragment_spec.js14
4 files changed, 36 insertions, 10 deletions
diff --git a/app/assets/javascripts/pages/sessions/new/preserve_url_fragment.js b/app/assets/javascripts/pages/sessions/new/preserve_url_fragment.js
index 71b7ca8ec31..56ea39f1259 100644
--- a/app/assets/javascripts/pages/sessions/new/preserve_url_fragment.js
+++ b/app/assets/javascripts/pages/sessions/new/preserve_url_fragment.js
@@ -13,7 +13,7 @@ export default function preserveUrlFragment(fragment) {
// Append the fragment to all sign-in/sign-up form actions so it is preserved when the user is
// eventually redirected back to the originally requested URL.
const forms = document.querySelectorAll('#signin-container form');
- Array.prototype.forEach.call(forms, (form) => {
+ Array.prototype.forEach.call(forms, form => {
const actionWithFragment = setUrlFragment(form.getAttribute('action'), `#${normalFragment}`);
form.setAttribute('action', actionWithFragment);
});
@@ -21,8 +21,11 @@ export default function preserveUrlFragment(fragment) {
// Append a redirect_fragment query param to all oauth provider links. The redirect_fragment
// query param will be available in the omniauth callback upon successful authentication
const anchors = document.querySelectorAll('#signin-container a.oauth-login');
- Array.prototype.forEach.call(anchors, (anchor) => {
- const newHref = mergeUrlParams({ redirect_fragment: normalFragment }, anchor.getAttribute('href'));
+ Array.prototype.forEach.call(anchors, anchor => {
+ const newHref = mergeUrlParams(
+ { redirect_fragment: normalFragment },
+ anchor.getAttribute('href'),
+ );
anchor.setAttribute('href', newHref);
});
}
diff --git a/spec/javascripts/lib/utils/url_utility_spec.js b/spec/javascripts/lib/utils/url_utility_spec.js
index fe787baf08e..1ac1c414df7 100644
--- a/spec/javascripts/lib/utils/url_utility_spec.js
+++ b/spec/javascripts/lib/utils/url_utility_spec.js
@@ -32,8 +32,13 @@ describe('URL utility', () => {
expect(urlUtils.mergeUrlParams({ w: 1 }, '#frag')).toBe('?w=1#frag');
expect(urlUtils.mergeUrlParams({ w: 1 }, '/path#frag')).toBe('/path?w=1#frag');
expect(urlUtils.mergeUrlParams({ w: 1 }, 'https://host/path')).toBe('https://host/path?w=1');
- expect(urlUtils.mergeUrlParams({ w: 1 }, 'https://host/path#frag')).toBe('https://host/path?w=1#frag');
- expect(urlUtils.mergeUrlParams({ w: 1 }, 'https://h/p?k1=v1#frag')).toBe('https://h/p?k1=v1&w=1#frag');
+ expect(urlUtils.mergeUrlParams({ w: 1 }, 'https://host/path#frag')).toBe(
+ 'https://host/path?w=1#frag',
+ );
+
+ expect(urlUtils.mergeUrlParams({ w: 1 }, 'https://h/p?k1=v1#frag')).toBe(
+ 'https://h/p?k1=v1&w=1#frag',
+ );
});
it('updates w', () => {
@@ -59,21 +64,25 @@ describe('URL utility', () => {
it('should remove param when url has no other params', () => {
const url = urlUtils.removeParams(['size'], '/feature/home?size=5');
+
expect(url).toBe('/feature/home');
});
it('should remove param when url has other params', () => {
const url = urlUtils.removeParams(['size'], '/feature/home?q=1&size=5&f=html');
+
expect(url).toBe('/feature/home?q=1&f=html');
});
it('should remove param and preserve fragment', () => {
const url = urlUtils.removeParams(['size'], '/feature/home?size=5#H2');
+
expect(url).toBe('/feature/home#H2');
});
it('should remove multiple params', () => {
const url = urlUtils.removeParams(['z', 'a'], '/home?z=11111&l=en_US&a=true#H2');
+
expect(url).toBe('/home?l=en_US#H2');
});
});
@@ -87,6 +96,7 @@ describe('URL utility', () => {
});
const url = urlUtils.removeParams(['locale']);
+
expect(url).toBe('https://mysite.com/?zip=11111&ads=false#privacy');
});
});
@@ -95,16 +105,19 @@ describe('URL utility', () => {
describe('setUrlFragment', () => {
it('should set fragment when url has no fragment', () => {
const url = urlUtils.setUrlFragment('/home/feature', 'usage');
+
expect(url).toBe('/home/feature#usage');
});
it('should set fragment when url has existing fragment', () => {
const url = urlUtils.setUrlFragment('/home/feature#overview', 'usage');
+
expect(url).toBe('/home/feature#usage');
});
it('should set fragment when given fragment includes #', () => {
const url = urlUtils.setUrlFragment('/home/feature#overview', '#install');
+
expect(url).toBe('/home/feature#install');
});
});
diff --git a/spec/javascripts/oauth_remember_me_spec.js b/spec/javascripts/oauth_remember_me_spec.js
index f363aa7a407..4125706a407 100644
--- a/spec/javascripts/oauth_remember_me_spec.js
+++ b/spec/javascripts/oauth_remember_me_spec.js
@@ -22,7 +22,7 @@ describe('OAuthRememberMe', () => {
);
expect($('#oauth-container .oauth-login.facebook').attr('href')).toBe(
- 'http://example.com/?redirect_fragment=L1&remember_me=1'
+ 'http://example.com/?redirect_fragment=L1&remember_me=1',
);
});
@@ -32,6 +32,8 @@ describe('OAuthRememberMe', () => {
expect($('#oauth-container .oauth-login.twitter').attr('href')).toBe('http://example.com/');
expect($('#oauth-container .oauth-login.github').attr('href')).toBe('http://example.com/');
- expect($('#oauth-container .oauth-login.facebook').attr('href')).toBe('http://example.com/?redirect_fragment=L1');
+ expect($('#oauth-container .oauth-login.facebook').attr('href')).toBe(
+ 'http://example.com/?redirect_fragment=L1',
+ );
});
});
diff --git a/spec/javascripts/pages/sessions/new/preserve_url_fragment_spec.js b/spec/javascripts/pages/sessions/new/preserve_url_fragment_spec.js
index c3be06ce6f9..de308127a0f 100644
--- a/spec/javascripts/pages/sessions/new/preserve_url_fragment_spec.js
+++ b/spec/javascripts/pages/sessions/new/preserve_url_fragment_spec.js
@@ -19,8 +19,16 @@ describe('preserve_url_fragment', () => {
it('adds the "redirect_fragment" query parameter to all OAuth and SAML login buttons', () => {
preserveUrlFragment('#L65');
- expect($('.omniauth-container #oauth-login-auth0').attr('href')).toBe('/users/auth/auth0?redirect_fragment=L65');
- expect($('.omniauth-container #oauth-login-facebook').attr('href')).toBe('/users/auth/facebook?remember_me=1&redirect_fragment=L65');
- expect($('.omniauth-container #oauth-login-saml').attr('href')).toBe('/users/auth/saml?redirect_fragment=L65');
+ expect($('.omniauth-container #oauth-login-auth0').attr('href')).toBe(
+ '/users/auth/auth0?redirect_fragment=L65',
+ );
+
+ expect($('.omniauth-container #oauth-login-facebook').attr('href')).toBe(
+ '/users/auth/facebook?remember_me=1&redirect_fragment=L65',
+ );
+
+ expect($('.omniauth-container #oauth-login-saml').attr('href')).toBe(
+ '/users/auth/saml?redirect_fragment=L65',
+ );
});
});