From cb057145ee18f4cf808d2d4a3d3b9083a55a35e0 Mon Sep 17 00:00:00 2001 From: Beatrice Peng Date: Wed, 4 Feb 2015 14:56:29 -0500 Subject: [PATCH] feat(react-notifications): add alert notifications to react [Finishes #87635924] Signed-off-by: Nicole Sullivan --- src/pivotal-ui/components/dropdowns.scss | 32 ++++++++++++ src/pivotal-ui/javascripts/components.js | 1 + src/pivotal-ui/javascripts/notifications.js | 32 ++++++++++++ test/javascripts/notification_spec.js | 54 +++++++++++++++++++++ 4 files changed, 119 insertions(+) diff --git a/src/pivotal-ui/components/dropdowns.scss b/src/pivotal-ui/components/dropdowns.scss index 1b108a321..8118906fe 100644 --- a/src/pivotal-ui/components/dropdowns.scss +++ b/src/pivotal-ui/components/dropdowns.scss @@ -367,6 +367,38 @@ var newLabel = New; ``` +*/ + +/*doc +--- +title: Alerts +name: alert_notifications_react +parent: notifications_react +--- + +Here's an example if there are no alerts: + +```react_example_table + +``` + +Here's an example if there are alerts: + +```jsx_example +var alertImage = ; +``` + +```react_example_table + + + + WARNING +

Click for Cute Gif

+
+
+
+``` + */ diff --git a/src/pivotal-ui/javascripts/components.js b/src/pivotal-ui/javascripts/components.js index a7fd302b7..eebcc36ce 100644 --- a/src/pivotal-ui/javascripts/components.js +++ b/src/pivotal-ui/javascripts/components.js @@ -97,6 +97,7 @@ module.exports = { LowlightDropdown: require('./dropdowns.jsx').LowlightDropdown, Notifications: require('./notifications.js').Notifications, + AlertNotifications: require('./notifications.js').AlertNotifications, NotificationItem: require('./notifications.js').NotificationItem, Label: require('./labels.jsx').Label, diff --git a/src/pivotal-ui/javascripts/notifications.js b/src/pivotal-ui/javascripts/notifications.js index 4d15571d3..f5293e93b 100644 --- a/src/pivotal-ui/javascripts/notifications.js +++ b/src/pivotal-ui/javascripts/notifications.js @@ -37,6 +37,37 @@ var Notifications = React.createClass({ } }); +var AlertNotifications = React.createClass({ + render: function () { + var children = this.props.children; + + if(!this.props.children){ + children = ( + +
+ +

no alerts

+
+
+ ); + } + var badge = this.props.children ? () : null; + + var dropdownTitle = ( +
+ + {badge} +
+ ); + + return ( + + {children} + + ); + } +}); + var NotificationItem = React.createClass({ render: function () { return ( @@ -49,5 +80,6 @@ var NotificationItem = React.createClass({ module.exports = { Notifications, + AlertNotifications, NotificationItem }; diff --git a/test/javascripts/notification_spec.js b/test/javascripts/notification_spec.js index 8fd117d01..19ec992e9 100644 --- a/test/javascripts/notification_spec.js +++ b/test/javascripts/notification_spec.js @@ -4,6 +4,7 @@ var $ = require('jquery'); var React = require('react/addons'); var Notifications = require('../../src/pivotal-ui/javascripts/notifications').Notifications; +var AlertNotifications = require('../../src/pivotal-ui/javascripts/notifications').AlertNotifications; var NotificationItem = require('../../src/pivotal-ui/javascripts/notifications').NotificationItem; describe('Notification', function() { @@ -58,3 +59,56 @@ describe('Notification', function() { }); }); }); + +describe('Alert Notifications', function() { + beforeEach(function() { + this.node = $('
').appendTo('body').get(0); + }); + + afterEach(function() { + React.unmountComponentAtNode(this.node); + document.body.removeChild(this.node); + }); + + describe("when there are children", function() { + beforeEach(function() { + React.render( + + fee + fi + fo + fum + , + this.node); + }); + + it("renders a notification alert icon", function() { + expect($('#container .dropdown-notifications-title .dropdown-notifications-alert')).toHaveClass('fa-exclamation-triangle'); + }); + + it("renders the children in a dropdown menu", function() { + expect($('#container .dropdown-menu a').first()).toContainText('fee'); + expect($('#container .dropdown-menu a').first().attr('href')).toEqual('my-fee-link'); + + expect($('#container .dropdown-menu')).toContainText('fi'); + expect($('#container .dropdown-menu')).toContainText('fo'); + expect($('#container .dropdown-menu')).toContainText('fum'); + }); + }); + + describe("when there are no children", function() { + beforeEach(function() { + React.render( + , + this.node); + }); + + it("does not render an alert icon", function () { + expect($('#container .dropdown-notifications-title')).not.toContainElement('.dropdown-notifications-alert'); + }); + + it("renders the no notification message", function() { + expect($('#container .dropdown-menu .dropdown-notifications-none')).toContainText('no alerts'); + }); + }); +});