This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
BilalQamar
committed
Jun 7, 2022
1 parent
79a5ef7
commit 4584fa7
Showing
155 changed files
with
11,192 additions
and
11,117 deletions.
There are no files selected for viewing
120 changes: 60 additions & 60 deletions
120
analytics_dashboard/static/apps/components/alert/spec/alert-view-spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
define(function(require) { | ||
'use strict'; | ||
|
||
var AlertView = require('components/alert/views/alert-view'); | ||
|
||
describe('AlertView', function() { | ||
it('throws exception for invalid alert types', function() { | ||
expect(function() { | ||
new AlertView({alertType: 'scooby-doo'}); // eslint-disable-line no-new | ||
}).toThrow(new Error('AlertView error: "scooby-doo" is not valid. Valid types are error, info.')); | ||
}); | ||
|
||
it('renders an error alert', function() { | ||
var fixture = setFixtures('<div id="error-alert"></div>'), | ||
alertView = new AlertView({ | ||
alertType: 'error', | ||
el: '#error-alert', | ||
title: 'edX Error Alert' | ||
}); | ||
|
||
alertView.render(); | ||
|
||
expect(fixture).toContainElement('span.fa-exclamation-triangle'); | ||
expect(fixture).toContainElement('.alert-error'); | ||
}); | ||
|
||
it('renders an info alert', function() { | ||
var fixture = setFixtures('<div class="info-alert"></div>'), | ||
alertView = new AlertView({ | ||
el: '.info-alert', | ||
alertType: 'info', | ||
title: 'edX Info Alert', | ||
body: 'More description about an information alert.', | ||
suggestions: ['Display alerts.', 'Alerts are helpful messages!'] | ||
}); | ||
alertView.render(); | ||
|
||
expect(fixture).toContainElement('span.fa-bullhorn'); | ||
expect(fixture).toContainElement('.alert-information'); | ||
expect(fixture).toContainElement('li'); | ||
}); | ||
|
||
it('renders an alert with a link', function() { | ||
var fixture = setFixtures('<div class="info-alert"></div>'), | ||
alertView = new AlertView({ | ||
el: '.info-alert', | ||
alertType: 'info', | ||
title: 'edX Info Alert', | ||
body: 'More description about an information alert.', | ||
suggestions: ['Display alerts.', 'Alerts are helpful messages!'], | ||
link: {url: 'http://example.com', text: 'A helpful link.'} | ||
}); | ||
alertView.render(); | ||
|
||
expect(fixture).toContainElement('span.fa-bullhorn'); | ||
expect(fixture).toContainElement('.alert-information'); | ||
expect(fixture).toContainElement('li'); | ||
expect(fixture).toContainElement('.link'); | ||
expect(fixture).toContainElement('a'); | ||
}); | ||
define((require) => { | ||
'use strict'; | ||
|
||
const AlertView = require('components/alert/views/alert-view'); | ||
|
||
describe('AlertView', () => { | ||
it('throws exception for invalid alert types', () => { | ||
expect(() => { | ||
new AlertView({ alertType: 'scooby-doo' }); // eslint-disable-line no-new | ||
}).toThrow(new Error('AlertView error: "scooby-doo" is not valid. Valid types are error, info.')); | ||
}); | ||
|
||
it('renders an error alert', () => { | ||
const fixture = setFixtures('<div id="error-alert"></div>'); | ||
const alertView = new AlertView({ | ||
alertType: 'error', | ||
el: '#error-alert', | ||
title: 'edX Error Alert', | ||
}); | ||
|
||
alertView.render(); | ||
|
||
expect(fixture).toContainElement('span.fa-exclamation-triangle'); | ||
expect(fixture).toContainElement('.alert-error'); | ||
}); | ||
|
||
it('renders an info alert', () => { | ||
const fixture = setFixtures('<div class="info-alert"></div>'); | ||
const alertView = new AlertView({ | ||
el: '.info-alert', | ||
alertType: 'info', | ||
title: 'edX Info Alert', | ||
body: 'More description about an information alert.', | ||
suggestions: ['Display alerts.', 'Alerts are helpful messages!'], | ||
}); | ||
alertView.render(); | ||
|
||
expect(fixture).toContainElement('span.fa-bullhorn'); | ||
expect(fixture).toContainElement('.alert-information'); | ||
expect(fixture).toContainElement('li'); | ||
}); | ||
|
||
it('renders an alert with a link', () => { | ||
const fixture = setFixtures('<div class="info-alert"></div>'); | ||
const alertView = new AlertView({ | ||
el: '.info-alert', | ||
alertType: 'info', | ||
title: 'edX Info Alert', | ||
body: 'More description about an information alert.', | ||
suggestions: ['Display alerts.', 'Alerts are helpful messages!'], | ||
link: { url: 'http://example.com', text: 'A helpful link.' }, | ||
}); | ||
alertView.render(); | ||
|
||
expect(fixture).toContainElement('span.fa-bullhorn'); | ||
expect(fixture).toContainElement('.alert-information'); | ||
expect(fixture).toContainElement('li'); | ||
expect(fixture).toContainElement('.link'); | ||
expect(fixture).toContainElement('a'); | ||
}); | ||
}); | ||
}); |
103 changes: 51 additions & 52 deletions
103
analytics_dashboard/static/apps/components/alert/views/alert-view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,71 @@ | ||
/** | ||
* Renders an alert, given an alert type (e.g. error, info). | ||
*/ | ||
define(function(require) { | ||
'use strict'; | ||
define((require) => { | ||
'use strict'; | ||
|
||
var _ = require('underscore'), | ||
Marionette = require('marionette'), | ||
const _ = require('underscore'); | ||
const Marionette = require('marionette'); | ||
|
||
alertTemplate = require('components/alert/templates/alert.underscore'), | ||
const alertTemplate = require('components/alert/templates/alert.underscore'); | ||
|
||
AlertView; | ||
let AlertView; | ||
|
||
AlertView = Marionette.ItemView.extend({ | ||
AlertView = Marionette.ItemView.extend({ | ||
|
||
template: _.template(alertTemplate), | ||
template: _.template(alertTemplate), | ||
|
||
// add new alert types with template variables | ||
alertTypes: { | ||
error: { | ||
iconClass: 'fa-exclamation-triangle', | ||
containerClass: 'alert-error' | ||
}, | ||
info: { | ||
iconClass: 'fa-bullhorn', | ||
containerClass: 'alert-information' | ||
} | ||
}, | ||
// add new alert types with template variables | ||
alertTypes: { | ||
error: { | ||
iconClass: 'fa-exclamation-triangle', | ||
containerClass: 'alert-error', | ||
}, | ||
info: { | ||
iconClass: 'fa-bullhorn', | ||
containerClass: 'alert-information', | ||
}, | ||
}, | ||
|
||
defaults: { | ||
alertType: 'info', // default alert type | ||
title: undefined, // string title of alert | ||
body: undefined, // string body of alert | ||
suggestions: [], // list of strings to display after the body | ||
link: undefined // string to display and url of link on alert | ||
}, | ||
defaults: { | ||
alertType: 'info', // default alert type | ||
title: undefined, // string title of alert | ||
body: undefined, // string body of alert | ||
suggestions: [], // list of strings to display after the body | ||
link: undefined, // string to display and url of link on alert | ||
}, | ||
|
||
/** | ||
/** | ||
* Throws an error if the alert type isn't valid. | ||
*/ | ||
validateAlertType: function(alertType) { | ||
var types = _(this.alertTypes).keys(); | ||
if (_(types).contains(alertType)) { | ||
return this; | ||
} else { | ||
throw new Error('AlertView error: "' + alertType + '" is not valid. Valid types are ' + | ||
types.join(', ') + '.'); | ||
} | ||
}, | ||
validateAlertType(alertType) { | ||
const types = _(this.alertTypes).keys(); | ||
if (_(types).contains(alertType)) { | ||
return this; | ||
} | ||
throw new Error(`AlertView error: "${alertType}" is not valid. Valid types are ${ | ||
types.join(', ')}.`); | ||
}, | ||
|
||
updateTemplateSetings: function(alertType) { | ||
// fill in the alert template variables | ||
this.options = _.extend({}, this.alertTypes[alertType], this.options); | ||
}, | ||
updateTemplateSetings(alertType) { | ||
// fill in the alert template variables | ||
this.options = _.extend({}, this.alertTypes[alertType], this.options); | ||
}, | ||
|
||
initialize: function(options) { | ||
var alertType; | ||
initialize(options) { | ||
let alertType; | ||
|
||
this.options = _.extend({}, this.defaults, options); | ||
this.options = _.extend({}, this.defaults, options); | ||
|
||
alertType = this.options.alertType; | ||
this.validateAlertType(alertType) | ||
.updateTemplateSetings(alertType); | ||
}, | ||
alertType = this.options.alertType; | ||
this.validateAlertType(alertType) | ||
.updateTemplateSetings(alertType); | ||
}, | ||
|
||
templateHelpers: function() { | ||
return this.options; | ||
} | ||
}); | ||
templateHelpers() { | ||
return this.options; | ||
}, | ||
}); | ||
|
||
return AlertView; | ||
return AlertView; | ||
}); |
Oops, something went wrong.