Commit bcab4bb5 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Changed the javascript class from using the global scope to exporting it via webpack

Also improved accesibility and change the id from user_callouts to a class
parent 19a21107
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
/* global Shortcuts */ /* global Shortcuts */
const ShortcutsBlob = require('./shortcuts_blob'); const ShortcutsBlob = require('./shortcuts_blob');
const UserCallout = require('./user_callout');
(function() { (function() {
var Dispatcher; var Dispatcher;
...@@ -277,6 +278,9 @@ const ShortcutsBlob = require('./shortcuts_blob'); ...@@ -277,6 +278,9 @@ const ShortcutsBlob = require('./shortcuts_blob');
case 'ci:lints:show': case 'ci:lints:show':
new gl.CILintEditor(); new gl.CILintEditor();
break; break;
case 'users:show':
new UserCallout();
break;
} }
switch (path.first()) { switch (path.first()) {
case 'sessions': case 'sessions':
...@@ -313,6 +317,7 @@ const ShortcutsBlob = require('./shortcuts_blob'); ...@@ -313,6 +317,7 @@ const ShortcutsBlob = require('./shortcuts_blob');
case 'dashboard': case 'dashboard':
case 'root': case 'root':
shortcut_handler = new ShortcutsDashboardNavigation(); shortcut_handler = new ShortcutsDashboardNavigation();
new UserCallout();
break; break;
case 'profiles': case 'profiles':
new NotificationsForm(); new NotificationsForm();
......
/* eslint-disable arrow-parens, class-methods-use-this, no-param-reassign */ /* eslint-disable arrow-parens, class-methods-use-this, no-param-reassign */
/* global Cookies */ /* global Cookies */
((global) => { const userCalloutElementName = '.user-callout';
const userCalloutElementName = '#user-callout'; const dismissIcon = '.dismiss-icon';
const dismissIcon = '.dismiss-icon'; const userCalloutBtn = '.user-callout-btn';
const userCalloutBtn = '.user-callout-btn';
const USER_CALLOUT_COOKIE = 'user_callout_dismissed'; const USER_CALLOUT_COOKIE = 'user_callout_dismissed';
class UserCallout { class UserCallout {
constructor() { constructor() {
this.isCalloutDismissed = Cookies.get(USER_CALLOUT_COOKIE); this.isCalloutDismissed = Cookies.get(USER_CALLOUT_COOKIE);
this.init(); this.init();
} this.isUserCalloutDismissed();
}
init() { init() {
$(document) $(document)
.on('click', dismissIcon, () => this.closeAndDismissCallout()) .on('click', dismissIcon, () => this.closeAndDismissCallout())
.on('click', userCalloutBtn, () => this.closeAndDismissCallout()) .on('click', userCalloutBtn, () => this.closeAndDismissCallout());
.on('DOMContentLoaded', () => this.isUserCalloutDismissed()); }
}
closeAndDismissCallout() { closeAndDismissCallout() {
$(userCalloutElementName).hide(); $(userCalloutElementName).hide();
Cookies.set(USER_CALLOUT_COOKIE, '1'); Cookies.set(USER_CALLOUT_COOKIE, '1');
} }
isUserCalloutDismissed() { isUserCalloutDismissed() {
if (!this.isCalloutDismissed) { if (!this.isCalloutDismissed) {
$(userCalloutElementName).show(); $(userCalloutElementName).show();
}
} }
} }
}
global.UserCallout = UserCallout; module.exports = UserCallout;
})(window.gl || (window.gl = {}));
...@@ -278,7 +278,7 @@ table.u2f-registrations { ...@@ -278,7 +278,7 @@ table.u2f-registrations {
} }
} }
#user-callout { .user-callout {
display: none; display: none;
margin: 24px auto 0; margin: 24px auto 0;
...@@ -289,11 +289,13 @@ table.u2f-registrations { ...@@ -289,11 +289,13 @@ table.u2f-registrations {
.landing { .landing {
margin-bottom: $gl-padding; margin-bottom: $gl-padding;
overflow: hidden;
.close {
margin-right: 20px;
}
.dismiss-icon { .dismiss-icon {
float: right; float: right;
margin-right: 20px;
cursor: pointer; cursor: pointer;
color: $cycle-analytics-dismiss-icon-color; color: $cycle-analytics-dismiss-icon-color;
} }
......
...@@ -17,6 +17,3 @@ ...@@ -17,6 +17,3 @@
= render 'projects' = render 'projects'
- else - else
= render "zero_authorized_projects" = render "zero_authorized_projects"
:javascript
var userCallout = new gl.UserCallout();
#user-callout .user-callout
.bordered-box.landing.content-block .bordered-box.landing.content-block
= icon("times", class: "dismiss-icon") %button.btn.btn-default.close{ type: "button" }
= icon("times", class: "dismiss-icon")
.row .row
.col-sm-3.col-xs-12.svg-container .col-sm-3.col-xs-12.svg-container
= custom_icon('icon_customization') = custom_icon('icon_customization')
......
...@@ -129,11 +129,8 @@ ...@@ -129,11 +129,8 @@
= spinner = spinner
:javascript :javascript
var userProfile, userCallout; var userProfile;
userProfile = new gl.User({ userProfile = new gl.User({
action: "#{controller.action_name}" action: "#{controller.action_name}"
}); });
userCallout = new gl.UserCallout();
...@@ -18,18 +18,18 @@ describe 'User Callouts', js: true do ...@@ -18,18 +18,18 @@ describe 'User Callouts', js: true do
describe 'user callout should appear in two routes' do describe 'user callout should appear in two routes' do
it 'shows up on the user profile' do it 'shows up on the user profile' do
visit user_path(user) visit user_path(user)
expect(find('#user-callout')).to have_content 'Customize your experience' expect(find('.user-callout')).to have_content 'Customize your experience'
end end
it 'shows up on the dashboard projects' do it 'shows up on the dashboard projects' do
visit dashboard_projects_path visit dashboard_projects_path
expect(find('#user-callout')).to have_content 'Customize your experience' expect(find('.user-callout')).to have_content 'Customize your experience'
end end
end end
it 'hides the user callout when click on the dismiss icon' do it 'hides the user callout when click on the dismiss icon' do
visit user_path(user) visit user_path(user)
within('#user-callout') do within('.user-callout') do
find('.dismiss-icon').click find('.dismiss-icon').click
end end
expect(page).not_to have_selector('#user-callout') expect(page).not_to have_selector('#user-callout')
......
#user-callout .user-callout
.bordered-box.landing.content-block .bordered-box.landing.content-block
%i.fa.fa-times.dismiss-icon %button.btn.btn-default.close{ type: "button" }
%i.fa.fa-times.dismiss-icon
.row .row
.col-sm-3.col-xs-12.svg-container .col-sm-3.col-xs-12.svg-container
.col-sm-8.col-xs-12.inner-content .col-sm-8.col-xs-12.inner-content
...@@ -9,4 +10,4 @@ ...@@ -9,4 +10,4 @@
%p %p
Change syntax themes, default project pages, and more in preferences. Change syntax themes, default project pages, and more in preferences.
%a{ href: 'foo', class:'user-callout-btn' } %a{ href: 'foo', class:'user-callout-btn' }
Check it out Check it out
\ No newline at end of file
/* esint-disable space-before-function-paren, arrow-body-style */ /* esint-disable space-before-function-paren, arrow-body-style */
require('~/user_callout'); const UserCallout = require('~/user_callout');
((global) => { const USER_CALLOUT_COOKIE = 'user_callout_dismissed';
const USER_CALLOUT_COOKIE = 'user_callout_dismissed'; const Cookie = window.Cookies;
const Cookie = window.Cookies;
describe('UserCallout', function () { describe('UserCallout', function () {
const fixtureName = 'static/user_callout.html.raw'; const fixtureName = 'static/user_callout.html.raw';
preloadFixtures(fixtureName); preloadFixtures(fixtureName);
it('should be defined in the global scope', () => { beforeEach(() => {
expect(global.UserCallout).toBeDefined(); loadFixtures(fixtureName);
}); this.userCallout = new UserCallout();
this.dismissIcon = $('.dismiss-icon');
beforeEach(() => { this.userCalloutContainer = $('.user-callout');
loadFixtures(fixtureName); this.userCalloutBtn = $('.user-callout-btn');
this.userCallout = new global.UserCallout(); Cookie.set(USER_CALLOUT_COOKIE, 0);
this.dismissIcon = $('.dismiss-icon'); });
this.userCalloutContainer = $('#user-callout');
this.userCalloutBtn = $('.user-callout-btn');
Cookie.set(USER_CALLOUT_COOKIE, 0);
});
it('shows when cookie is set to false', () => { it('shows when cookie is set to false', () => {
expect(Cookie.get(USER_CALLOUT_COOKIE)).toBeDefined(); expect(Cookie.get(USER_CALLOUT_COOKIE)).toBeDefined();
expect(this.userCalloutContainer.is(':visible')).toBe(true); expect(this.userCalloutContainer.is(':visible')).toBe(true);
}); });
it('hides when user clicks on the dismiss-icon', () => { it('hides when user clicks on the dismiss-icon', () => {
this.dismissIcon.click(); this.dismissIcon.click();
expect(this.userCalloutContainer.is(':visible')).toBe(false); expect(this.userCalloutContainer.is(':visible')).toBe(false);
expect(Cookie.get(USER_CALLOUT_COOKIE)).toBe('1'); expect(Cookie.get(USER_CALLOUT_COOKIE)).toBe('1');
}); });
it('hides when user clicks on the "check it out" button', () => { it('hides when user clicks on the "check it out" button', () => {
this.userCalloutBtn.click(); this.userCalloutBtn.click();
expect(this.userCalloutContainer.is(':visible')).toBe(false); expect(this.userCalloutContainer.is(':visible')).toBe(false);
expect(Cookie.get(USER_CALLOUT_COOKIE)).toBe('1'); expect(Cookie.get(USER_CALLOUT_COOKIE)).toBe('1');
});
}); });
})(window.gl || (window.gl = {})); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment