Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
fix: eslint issues resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
BilalQamar committed Jun 7, 2022
1 parent 79a5ef7 commit 4584fa7
Show file tree
Hide file tree
Showing 155 changed files with 11,192 additions and 11,117 deletions.
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 analytics_dashboard/static/apps/components/alert/views/alert-view.js
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;
});
Loading

0 comments on commit 4584fa7

Please sign in to comment.