mirror of
https://github.com/nasa/openmct.git
synced 2025-02-07 11:30:28 +00:00
[Notification] Rename variables for clarity
In the spec: NotificationService knows about concepts like "info", "alert" and "error" only, having a plain info notification model called successModel doesn't help much and may be confusing at times (makes you think it's something the service treats separately).
This commit is contained in:
parent
e03c725b86
commit
0442a31153
@ -109,18 +109,18 @@ define(
|
|||||||
* @memberof platform/commonUI/notification
|
* @memberof platform/commonUI/notification
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param $timeout the Angular $timeout service
|
* @param $timeout the Angular $timeout service
|
||||||
* @param DEFAULT_AUTO_DISMISS The period of time that an
|
* @param defaultAutoDismissTimeout The period of time that an
|
||||||
* auto-dismissed message will be displayed for.
|
* auto-dismissed message will be displayed for.
|
||||||
* @param MINIMIZE_TIMEOUT When notifications are minimized, a brief
|
* @param minimizeAnimationTimeout When notifications are minimized, a brief
|
||||||
* animation is shown. This animation requires some time to execute,
|
* animation is shown. This animation requires some time to execute,
|
||||||
* so a timeout is required before the notification is hidden
|
* so a timeout is required before the notification is hidden
|
||||||
*/
|
*/
|
||||||
function NotificationService($timeout, topic, DEFAULT_AUTO_DISMISS, MINIMIZE_TIMEOUT) {
|
function NotificationService($timeout, topic, defaultAutoDismissTimeout, minimizeAnimationTimeout) {
|
||||||
this.notifications = [];
|
this.notifications = [];
|
||||||
this.$timeout = $timeout;
|
this.$timeout = $timeout;
|
||||||
this.highest = { severity: "info" };
|
this.highest = { severity: "info" };
|
||||||
this.DEFAULT_AUTO_DISMISS = DEFAULT_AUTO_DISMISS;
|
this.AUTO_DISMISS_TIMEOUT = defaultAutoDismissTimeout;
|
||||||
this.MINIMIZE_TIMEOUT = MINIMIZE_TIMEOUT;
|
this.MINIMIZE_ANIMATION_TIMEOUT = minimizeAnimationTimeout;
|
||||||
this.topic = topic;
|
this.topic = topic;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -162,7 +162,7 @@ define(
|
|||||||
// in order to allow the minimize animation to run through.
|
// in order to allow the minimize animation to run through.
|
||||||
service.$timeout(function () {
|
service.$timeout(function () {
|
||||||
service.setActiveNotification(service.selectNextNotification());
|
service.setActiveNotification(service.selectNextNotification());
|
||||||
}, service.MINIMIZE_TIMEOUT);
|
}, service.MINIMIZE_ANIMATION_TIMEOUT);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -325,7 +325,7 @@ define(
|
|||||||
|
|
||||||
notificationModel.severity = notificationModel.severity || "info";
|
notificationModel.severity = notificationModel.severity || "info";
|
||||||
if (notificationModel.autoDismiss === true) {
|
if (notificationModel.autoDismiss === true) {
|
||||||
notificationModel.autoDismiss = this.DEFAULT_AUTO_DISMISS;
|
notificationModel.autoDismiss = this.AUTO_DISMISS_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Notifications support a 'dismissable' attribute. This is a
|
//Notifications support a 'dismissable' attribute. This is a
|
||||||
@ -366,7 +366,7 @@ define(
|
|||||||
*/
|
*/
|
||||||
this.active.timeout = this.$timeout(function () {
|
this.active.timeout = this.$timeout(function () {
|
||||||
activeNotification.dismissOrMinimize();
|
activeNotification.dismissOrMinimize();
|
||||||
}, this.DEFAULT_AUTO_DISMISS);
|
}, this.AUTO_DISMISS_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
return notification;
|
return notification;
|
||||||
@ -390,7 +390,7 @@ define(
|
|||||||
if (notification && (notification.model.autoDismiss ||
|
if (notification && (notification.model.autoDismiss ||
|
||||||
this.selectNextNotification())) {
|
this.selectNextNotification())) {
|
||||||
|
|
||||||
timeout = notification.model.autoDismiss || this.DEFAULT_AUTO_DISMISS;
|
timeout = notification.model.autoDismiss || this.AUTO_DISMISS_TIMEOUT;
|
||||||
this.active.timeout = this.$timeout(function () {
|
this.active.timeout = this.$timeout(function () {
|
||||||
notification.dismissOrMinimize();
|
notification.dismissOrMinimize();
|
||||||
}, timeout);
|
}, timeout);
|
||||||
|
@ -30,9 +30,9 @@ define(
|
|||||||
mockTimeout,
|
mockTimeout,
|
||||||
mockAutoDismiss,
|
mockAutoDismiss,
|
||||||
mockMinimizeTimeout,
|
mockMinimizeTimeout,
|
||||||
successModel,
|
|
||||||
mockTopicFunction,
|
mockTopicFunction,
|
||||||
mockTopicObject,
|
mockTopicObject,
|
||||||
|
infoModel,
|
||||||
errorModel;
|
errorModel;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@ -44,27 +44,29 @@ define(
|
|||||||
mockAutoDismiss = mockMinimizeTimeout = 1000;
|
mockAutoDismiss = mockMinimizeTimeout = 1000;
|
||||||
notificationService = new NotificationService(
|
notificationService = new NotificationService(
|
||||||
mockTimeout, mockTopicFunction, mockAutoDismiss, mockMinimizeTimeout);
|
mockTimeout, mockTopicFunction, mockAutoDismiss, mockMinimizeTimeout);
|
||||||
successModel = {
|
|
||||||
title: "Mock Success Notification",
|
infoModel = {
|
||||||
|
title: "Mock Info Notification",
|
||||||
severity: "info"
|
severity: "info"
|
||||||
};
|
};
|
||||||
|
|
||||||
errorModel = {
|
errorModel = {
|
||||||
title: "Mock Error Notification",
|
title: "Mock Error Notification",
|
||||||
severity: "error"
|
severity: "error"
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it("activates success notifications", function () {
|
it("activates info notifications", function () {
|
||||||
var activeNotification;
|
var activeNotification;
|
||||||
notificationService.notify(successModel);
|
notificationService.notify(infoModel);
|
||||||
activeNotification = notificationService.getActiveNotification();
|
activeNotification = notificationService.getActiveNotification();
|
||||||
expect(activeNotification.model).toBe(successModel);
|
expect(activeNotification.model).toBe(infoModel);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("notifies listeners on dismissal of notification", function () {
|
it("notifies listeners on dismissal of notification", function () {
|
||||||
var notification,
|
var notification,
|
||||||
dismissListener = jasmine.createSpy("ondismiss");
|
dismissListener = jasmine.createSpy("ondismiss");
|
||||||
notification = notificationService.notify(successModel);
|
notification = notificationService.notify(infoModel);
|
||||||
notification.onDismiss(dismissListener);
|
notification.onDismiss(dismissListener);
|
||||||
expect(mockTopicObject.listen).toHaveBeenCalled();
|
expect(mockTopicObject.listen).toHaveBeenCalled();
|
||||||
notification.dismiss();
|
notification.dismiss();
|
||||||
@ -83,12 +85,12 @@ define(
|
|||||||
expect(activeNotification.model.severity).toBe("info");
|
expect(activeNotification.model.severity).toBe("info");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("gets a new success notification with numerical auto-dismiss specified. ", function () {
|
it("gets a new info notification with numerical auto-dismiss specified. ", function () {
|
||||||
var activeNotification;
|
var activeNotification;
|
||||||
successModel.autoDismiss = 1000;
|
infoModel.autoDismiss = 1000;
|
||||||
notificationService.notify(successModel);
|
notificationService.notify(infoModel);
|
||||||
activeNotification = notificationService.getActiveNotification();
|
activeNotification = notificationService.getActiveNotification();
|
||||||
expect(activeNotification.model).toBe(successModel);
|
expect(activeNotification.model).toBe(infoModel);
|
||||||
mockTimeout.mostRecentCall.args[0]();
|
mockTimeout.mostRecentCall.args[0]();
|
||||||
expect(mockTimeout.calls.length).toBe(2);
|
expect(mockTimeout.calls.length).toBe(2);
|
||||||
mockTimeout.mostRecentCall.args[0]();
|
mockTimeout.mostRecentCall.args[0]();
|
||||||
@ -98,10 +100,10 @@ define(
|
|||||||
|
|
||||||
it("gets a new notification with boolean auto-dismiss specified. ", function () {
|
it("gets a new notification with boolean auto-dismiss specified. ", function () {
|
||||||
var activeNotification;
|
var activeNotification;
|
||||||
successModel.autoDismiss = true;
|
infoModel.autoDismiss = true;
|
||||||
notificationService.notify(successModel);
|
notificationService.notify(infoModel);
|
||||||
activeNotification = notificationService.getActiveNotification();
|
activeNotification = notificationService.getActiveNotification();
|
||||||
expect(activeNotification.model).toBe(successModel);
|
expect(activeNotification.model).toBe(infoModel);
|
||||||
mockTimeout.mostRecentCall.args[0]();
|
mockTimeout.mostRecentCall.args[0]();
|
||||||
expect(mockTimeout.calls.length).toBe(2);
|
expect(mockTimeout.calls.length).toBe(2);
|
||||||
mockTimeout.mostRecentCall.args[0]();
|
mockTimeout.mostRecentCall.args[0]();
|
||||||
@ -113,11 +115,11 @@ define(
|
|||||||
var notification,
|
var notification,
|
||||||
activeNotification;
|
activeNotification;
|
||||||
|
|
||||||
successModel.autoDismiss = false;
|
infoModel.autoDismiss = false;
|
||||||
notification = notificationService.notify(successModel);
|
notification = notificationService.notify(infoModel);
|
||||||
|
|
||||||
activeNotification = notificationService.getActiveNotification();
|
activeNotification = notificationService.getActiveNotification();
|
||||||
expect(activeNotification.model).toBe(successModel);
|
expect(activeNotification.model).toBe(infoModel);
|
||||||
notification.minimize();
|
notification.minimize();
|
||||||
mockTimeout.mostRecentCall.args[0]();
|
mockTimeout.mostRecentCall.args[0]();
|
||||||
activeNotification = notificationService.getActiveNotification();
|
activeNotification = notificationService.getActiveNotification();
|
||||||
@ -129,11 +131,11 @@ define(
|
|||||||
var notification,
|
var notification,
|
||||||
activeNotification;
|
activeNotification;
|
||||||
|
|
||||||
successModel.autoDismiss = false;
|
infoModel.autoDismiss = false;
|
||||||
notification = notificationService.notify(successModel);
|
notification = notificationService.notify(infoModel);
|
||||||
|
|
||||||
activeNotification = notificationService.getActiveNotification();
|
activeNotification = notificationService.getActiveNotification();
|
||||||
expect(activeNotification.model).toBe(successModel);
|
expect(activeNotification.model).toBe(infoModel);
|
||||||
notification.dismiss();
|
notification.dismiss();
|
||||||
activeNotification = notificationService.getActiveNotification();
|
activeNotification = notificationService.getActiveNotification();
|
||||||
expect(activeNotification).toBeUndefined();
|
expect(activeNotification).toBeUndefined();
|
||||||
@ -144,11 +146,11 @@ define(
|
|||||||
it("auto-dismisses the previously active notification, making the new notification active", function () {
|
it("auto-dismisses the previously active notification, making the new notification active", function () {
|
||||||
var activeNotification;
|
var activeNotification;
|
||||||
//First pre-load with a info message
|
//First pre-load with a info message
|
||||||
notificationService.notify(successModel);
|
notificationService.notify(infoModel);
|
||||||
activeNotification =
|
activeNotification =
|
||||||
notificationService.getActiveNotification();
|
notificationService.getActiveNotification();
|
||||||
//Initially expect the active notification to be info
|
//Initially expect the active notification to be info
|
||||||
expect(activeNotification.model).toBe(successModel);
|
expect(activeNotification.model).toBe(infoModel);
|
||||||
//Then notify of an error
|
//Then notify of an error
|
||||||
notificationService.notify(errorModel);
|
notificationService.notify(errorModel);
|
||||||
//But it should be auto-dismissed and replaced with the
|
//But it should be auto-dismissed and replaced with the
|
||||||
@ -167,7 +169,7 @@ define(
|
|||||||
//First pre-load with an error message
|
//First pre-load with an error message
|
||||||
notificationService.notify(errorModel);
|
notificationService.notify(errorModel);
|
||||||
//Then notify of info
|
//Then notify of info
|
||||||
notificationService.notify(successModel);
|
notificationService.notify(infoModel);
|
||||||
expect(notificationService.notifications.length).toEqual(2);
|
expect(notificationService.notifications.length).toEqual(2);
|
||||||
//Mock the auto-minimize
|
//Mock the auto-minimize
|
||||||
mockTimeout.mostRecentCall.args[0]();
|
mockTimeout.mostRecentCall.args[0]();
|
||||||
@ -180,7 +182,7 @@ define(
|
|||||||
expect(notificationService.notifications.length).toEqual(2);
|
expect(notificationService.notifications.length).toEqual(2);
|
||||||
activeNotification =
|
activeNotification =
|
||||||
notificationService.getActiveNotification();
|
notificationService.getActiveNotification();
|
||||||
expect(activeNotification.model).toBe(successModel);
|
expect(activeNotification.model).toBe(infoModel);
|
||||||
expect(errorModel.minimized).toEqual(true);
|
expect(errorModel.minimized).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user