Skip to content

Commit

Permalink
Fix platform notifications (#55)
Browse files Browse the repository at this point in the history
* feat: fix platform notifications date parsing

* chore: release v2.0.1-rc.0

* chore: update gitignore and spec description
  • Loading branch information
timrbula authored Mar 23, 2022
1 parent 644f9a8 commit 8814fb2
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ package-lock.json
.npmrc
results

.env

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@boomerang-io/carbon-addons-boomerang-react",
"description": "Carbon Addons for Boomerang apps",
"version": "2.0.0",
"version": "2.0.1-rc.0",
"author": {
"name": "Tim Bula",
"email": "timrbula@gmail.com"
Expand Down
6 changes: 3 additions & 3 deletions src/components/PlatformNotifications/PlatformNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { Close16 } from '@carbon/icons-react';
import { formatDistance, format } from 'date-fns';
import { formatDistance, format, parseISO } from 'date-fns';
import { settings } from 'carbon-components';

const { prefix } = settings;
Expand All @@ -28,7 +28,7 @@ function Notification({ readNotification, notificationInfo }) {
<p className={`${prefix}--bmrg-notification-content__desc`}>{notificationInfo.detail}</p>
<time className={`${prefix}--bmrg-notification-content__date`}>
{`${formatDistance(new Date(notificationInfo.date), new Date())} ago at ${format(
notificationInfo.date,
parseISO(notificationInfo.date),
'hh:mma'
)}`}
</time>
Expand All @@ -47,7 +47,7 @@ Notification.propTypes = {
readNotification: PropTypes.func,
notificationInfo: PropTypes.shape({
creator: PropTypes.string,
date: PropTypes.number,
date: PropTypes.string,
detail: PropTypes.string,
id: PropTypes.string,
location: PropTypes.string,
Expand Down
31 changes: 31 additions & 0 deletions src/components/PlatformNotifications/PlatformNotifications.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import PlatformNotifications from './PlatformNotifications';
import { screen, render } from '@testing-library/react';

const notificationsObj = {
creator: 'Boomerang CICD',
date: '2022-03-15T12:47:47.655+00:00',
detail: 'Outage description test for the following service(s): Boomerang Flow,Boomerang CICD',
eventId: '620b9f7e99fcb715cbc222b3',
id: '620ba0f354f1b83f5077dec6',
priority: 'highest',
read: false,
severity: 'INFO',
target: 'user',
title: 'Resolved',
type: 'notification',
userId: '61730018ae92414d2bd15b4c',
};

describe('Platform notification', () => {
test('Renders correctly', async () => {
render(
<PlatformNotifications notificationInfo={notificationsObj} readNotification={() => {}} />
);
expect(
screen.getByText(
'Outage description test for the following service(s): Boomerang Flow,Boomerang CICD'
)
).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,31 @@ import { boolean } from '@storybook/addon-knobs';
import PlatformNotificationsContainer from './index';

// const mockSocketUrl = 'http://localhost:7750/notifications/ws';
const mockSocketUrl = 'https://www.google.com/notifications/ws';

export default {
title: 'PlatformNotifications',
};

const mockSocketUrl = 'http://localhost:8080/ws';

export const Default = () => {
return (
<PlatformNotificationsContainer
initialNotifications={[
{
id: 'testId',
creator: 'launchpad',
title: 'Maintenance Scheduled for a long long long long time',
creator: 'Boomerang CICD',
date: '2022-03-15T12:47:47.655+00:00',
detail:
'Launchpad is scheduled for maintenance on January 8 from 2am-3am for a long long long time',
date: 1555079172156,
type: 'exception',
'Outage description test for the following service(s): Boomerang Flow,Boomerang CICD',
eventId: '620b9f7e99fcb715cbc222b3',
id: '620ba0f354f1b83f5077dec6',
priority: 'highest',
read: false,
severity: 'INFO',
target: 'user',
title: 'Resolved',
type: 'notification',
userId: '61730018ae92414d2bd15b4c',
},
]}
config={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';
import { shallow } from 'enzyme';
import { render } from '@testing-library/react';
import { action } from '@storybook/addon-actions';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import { Server } from 'mock-socket';
import { getTime, subDays } from 'date-fns';

import PlatformNotificationsContainer from './PlatformNotificationsContainer';

Expand All @@ -13,13 +12,18 @@ const mockServer = new Server(mockSocketUrl);
const notificationsObj = {
notifications: [
{
id: 'testID1',
location: 'Launchpad',
title: 'Maintenance Scheduled for a long long long long time',
detail:
'Launchpad is scheduled for maintenance on January 8 from 2am-3am for a long long long time',
date: '1551300716020',
type: 'exception',
creator: 'Boomerang CICD',
date: '2022-02-15T12:47:47.655+00:00',
detail: 'Outage description test for the following service(s): Boomerang Flow,Boomerang CICD',
eventId: '620b9f7e99fcb715cbc222b3',
id: '620ba0f354f1b83f5077dec6',
priority: 'highest',
read: false,
severity: 'INFO',
target: 'user',
title: 'Resolved',
type: 'notification',
userId: '61730018ae92414d2bd15b4c',
},
],
};
Expand All @@ -32,17 +36,14 @@ mockServer.on('connection', (socket) => {
socket.on('message', () => {
setInterval(() => {
notificationsObj.notifications[0].id = Math.round(Math.random() * 100000000); // Change for each one
notificationsObj.notifications[0].date = getTime(
subDays(new Date(), Math.round(Math.random() * 10))
);
socket.send(JSON.stringify(notificationsObj));
}, 10000);
});
});

describe('Default Notification Container', () => {
describe('Renders as expected', () => {
const wrapper = shallow(
const wrapper = render(
<PlatformNotificationsContainer
config={{
wsUrl: 'ws://localhost:8081/ws',
Expand Down

0 comments on commit 8814fb2

Please sign in to comment.