@truedat/audit 4.49.6 → 4.49.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.49.8] 2022-08-11
4
+
5
+ ## Added
6
+
7
+ - [TD-5035] Get external notification body from envent payload
8
+
3
9
  ## [4.48.11] 2022-21-07
4
10
 
5
11
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/audit",
3
- "version": "4.49.6",
3
+ "version": "4.49.9",
4
4
  "description": "Truedat Web Audit Module",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -85,8 +85,8 @@
85
85
  ]
86
86
  },
87
87
  "dependencies": {
88
- "@truedat/auth": "4.49.6",
89
- "@truedat/core": "4.49.6",
88
+ "@truedat/auth": "4.49.9",
89
+ "@truedat/core": "4.49.9",
90
90
  "path-to-regexp": "^1.7.0",
91
91
  "prop-types": "^15.8.1",
92
92
  "react-color": "^2.17.3",
@@ -106,5 +106,5 @@
106
106
  "react-dom": ">= 16.8.6 < 17",
107
107
  "semantic-ui-react": ">= 0.88.2 < 2.1"
108
108
  },
109
- "gitHead": "adc74b20dfa6c1b697318991410e183ee68d3e43"
109
+ "gitHead": "45bbf362a6bc6a075d779997b373bd0935cef100"
110
110
  }
@@ -53,6 +53,8 @@ export const NotificationEvent = ({
53
53
 
54
54
  const template = TEMPLATES[event.event] || "default";
55
55
  const eventsWithStatus = ["implementation_status", "grant_approval"];
56
+ const externalNotification = event.event === "external_notification";
57
+
56
58
  return (
57
59
  <div className="notification-item unread" ref={ref}>
58
60
  <h4>
@@ -61,7 +63,11 @@ export const NotificationEvent = ({
61
63
  <FormattedMessage id={`notifications.new`} />
62
64
  </Label>
63
65
  )}
64
- <FormattedMessage id={`notifications.events.${template}`} />
66
+ {externalNotification ? (
67
+ `↗ ${event.payload.subject}`
68
+ ) : (
69
+ <FormattedMessage id={`notifications.events.${template}`} />
70
+ )}
65
71
  </h4>
66
72
  <p>{event.name}</p>
67
73
  <Label>
@@ -57,7 +57,19 @@ export const NotificationsMenu = ({
57
57
  <Dropdown.Item
58
58
  className="item"
59
59
  key={`${i}x${j}`}
60
- as={Link}
60
+ href={
61
+ event.event === "external_notification"
62
+ ? event.path
63
+ : undefined
64
+ }
65
+ target={
66
+ event.event === "external_notification"
67
+ ? "_blank"
68
+ : undefined
69
+ }
70
+ as={
71
+ event.event !== "external_notification" ? Link : undefined
72
+ }
61
73
  to={event.path || "/search"}
62
74
  >
63
75
  <NotificationEvent
@@ -19,4 +19,21 @@ describe("<NotificationEvent />", () => {
19
19
  );
20
20
  expect(container).toMatchSnapshot();
21
21
  });
22
+
23
+ it("matches the latest snapshot for external notification", () => {
24
+ const event = {
25
+ event: "external_notification",
26
+ name: "External notification message",
27
+ payload: {
28
+ subject: "Test external notification",
29
+ },
30
+ path: "https://foo.bar",
31
+ };
32
+ const date = new Date("2020-01-01");
33
+
34
+ const { container } = render(
35
+ <NotificationEvent event={event} date={date} />
36
+ );
37
+ expect(container).toMatchSnapshot();
38
+ });
22
39
  });
@@ -1,11 +1,11 @@
1
1
  import React from "react";
2
- import { intl } from "@truedat/test/intl-stub";
3
- import { shallow } from "enzyme";
2
+ import { render } from "@truedat/test/render";
4
3
  import { NotificationsMenu } from "../NotificationsMenu";
5
4
 
6
- // workaround for enzyme issue with React.useContext
7
- // see https://github.com/airbnb/enzyme/issues/2176#issuecomment-532361526
8
- jest.spyOn(React, "useContext").mockImplementation(() => intl);
5
+ jest.mock("@truedat/core/hooks", () => ({ useOnScreen: jest.fn() }));
6
+ jest
7
+ .spyOn(global.Date, "now")
8
+ .mockImplementation(() => new Date("2022-01-01T11:01:58.135Z").valueOf());
9
9
 
10
10
  describe("<NotificationsMenu />", () => {
11
11
  it("matches the latest snapshot", () => {
@@ -20,20 +20,49 @@ describe("<NotificationsMenu />", () => {
20
20
  path: "foo/1/bar",
21
21
  payload: { domain_ids: [2, 1], name: "xyz" },
22
22
  resource_id: 2,
23
- resource_type: "xyz"
24
- }
25
- ]
26
- }
23
+ resource_type: "xyz",
24
+ },
25
+ ],
26
+ },
27
27
  ];
28
28
  const notificationsLoading = false;
29
29
 
30
- const wrapper = shallow(
30
+ const { container } = render(
31
31
  <NotificationsMenu
32
32
  fetchNotifications={fetchNotifications}
33
33
  notifications={notifications}
34
34
  notificationsLoading={notificationsLoading}
35
35
  />
36
36
  );
37
- expect(wrapper).toMatchSnapshot();
37
+ expect(container).toMatchSnapshot();
38
+ });
39
+
40
+ it("matches the latest snapshot with external notification", () => {
41
+ const fetchNotifications = jest.fn();
42
+ const notifications = [
43
+ {
44
+ events: [
45
+ {
46
+ event: "external_notification",
47
+ id: 1,
48
+ name: "bar",
49
+ path: "http://foo.bar",
50
+ payload: { domain_ids: [2, 1], name: "xyz" },
51
+ resource_id: 2,
52
+ resource_type: "xyz",
53
+ },
54
+ ],
55
+ },
56
+ ];
57
+ const notificationsLoading = false;
58
+
59
+ const { container } = render(
60
+ <NotificationsMenu
61
+ fetchNotifications={fetchNotifications}
62
+ notifications={notifications}
63
+ notificationsLoading={notificationsLoading}
64
+ />
65
+ );
66
+ expect(container).toMatchSnapshot();
38
67
  });
39
68
  });
@@ -29,3 +29,33 @@ exports[`<NotificationEvent /> matches the latest snapshot 1`] = `
29
29
  </div>
30
30
  </div>
31
31
  `;
32
+
33
+ exports[`<NotificationEvent /> matches the latest snapshot for external notification 1`] = `
34
+ <div>
35
+ <div
36
+ class="notification-item unread"
37
+ >
38
+ <h4>
39
+ <div
40
+ class="ui orange mini basic label"
41
+ >
42
+ New
43
+ </div>
44
+ ↗ Test external notification
45
+ </h4>
46
+ <p>
47
+ External notification message
48
+ </p>
49
+ <div
50
+ class="ui label"
51
+ >
52
+ external_notification
53
+ </div>
54
+ <time
55
+ datetime="1577836800000"
56
+ >
57
+ 2 years ago
58
+ </time>
59
+ </div>
60
+ </div>
61
+ `;
@@ -1,77 +1,121 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`<NotificationsMenu /> matches the latest snapshot 1`] = `
4
- <Fragment>
5
- <Dropdown
6
- additionLabel="Add "
7
- additionPosition="top"
8
- closeOnBlur={true}
9
- closeOnEscape={true}
10
- deburr={false}
11
- icon="bell"
12
- item={true}
13
- minCharacters={1}
14
- noResultsMessage="No results found."
15
- onOpen={[MockFunction]}
16
- openOnFocus={true}
17
- renderLabel={[Function]}
18
- scrolling={true}
19
- searchInput="text"
20
- selectOnBlur={true}
21
- selectOnNavigation={true}
22
- wrapSelection={true}
4
+ <div>
5
+ <div
6
+ aria-expanded="false"
7
+ class="ui item scrolling dropdown"
8
+ role="listbox"
9
+ tabindex="0"
23
10
  >
24
- <DropdownMenu
25
- className="notifications-dropdown"
26
- direction="left"
11
+ <i
12
+ aria-hidden="true"
13
+ class="bell icon"
14
+ />
15
+ <div
16
+ class="left menu transition notifications-dropdown"
27
17
  >
28
- <DropdownHeader>
29
- <MemoizedFormattedMessage
30
- id="navigation.notifications"
31
- />
32
- </DropdownHeader>
33
- <DropdownDivider />
34
- <DropdownItem
35
- as={
36
- Object {
37
- "$$typeof": Symbol(react.forward_ref),
38
- "displayName": "Link",
39
- "propTypes": Object {
40
- "innerRef": [Function],
41
- "onClick": [Function],
42
- "replace": [Function],
43
- "target": [Function],
44
- "to": [Function],
45
- },
46
- "render": [Function],
47
- }
48
- }
49
- className="item"
50
- key="0x0"
51
- to="foo/1/bar"
18
+ <div
19
+ class="header"
52
20
  >
53
- <NotificationEvent
54
- event={
55
- Object {
56
- "event": "foo",
57
- "id": 1,
58
- "name": "bar",
59
- "path": "foo/1/bar",
60
- "payload": Object {
61
- "domain_ids": Array [
62
- 2,
63
- 1,
64
- ],
65
- "name": "xyz",
66
- },
67
- "resource_id": 2,
68
- "resource_type": "xyz",
69
- }
70
- }
71
- readNotification={[Function]}
72
- />
73
- </DropdownItem>
74
- </DropdownMenu>
75
- </Dropdown>
76
- </Fragment>
21
+ Notifications
22
+ </div>
23
+ <div
24
+ class="divider"
25
+ />
26
+ <a
27
+ class="item item"
28
+ href="/foo/1/bar"
29
+ role="option"
30
+ >
31
+ <div
32
+ class="notification-item unread"
33
+ >
34
+ <h4>
35
+ <div
36
+ class="ui orange mini basic label"
37
+ >
38
+ New
39
+ </div>
40
+ ⚡ Alert: New notifications
41
+ </h4>
42
+ <p>
43
+ bar
44
+ </p>
45
+ <div
46
+ class="ui label"
47
+ >
48
+ foo
49
+ </div>
50
+ <time
51
+ datetime="1641034918135"
52
+ >
53
+ a few seconds ago
54
+ </time>
55
+ </div>
56
+ </a>
57
+ </div>
58
+ </div>
59
+ </div>
60
+ `;
61
+
62
+ exports[`<NotificationsMenu /> matches the latest snapshot with external notification 1`] = `
63
+ <div>
64
+ <div
65
+ aria-expanded="false"
66
+ class="ui item scrolling dropdown"
67
+ role="listbox"
68
+ tabindex="0"
69
+ >
70
+ <i
71
+ aria-hidden="true"
72
+ class="bell icon"
73
+ />
74
+ <div
75
+ class="left menu transition notifications-dropdown"
76
+ >
77
+ <div
78
+ class="header"
79
+ >
80
+ Notifications
81
+ </div>
82
+ <div
83
+ class="divider"
84
+ />
85
+ <a
86
+ class="item item"
87
+ href="http://foo.bar"
88
+ role="option"
89
+ target="_blank"
90
+ to="http://foo.bar"
91
+ >
92
+ <div
93
+ class="notification-item unread"
94
+ >
95
+ <h4>
96
+ <div
97
+ class="ui orange mini basic label"
98
+ >
99
+ New
100
+ </div>
101
+ ↗ undefined
102
+ </h4>
103
+ <p>
104
+ bar
105
+ </p>
106
+ <div
107
+ class="ui label"
108
+ >
109
+ external_notification
110
+ </div>
111
+ <time
112
+ datetime="1641034918135"
113
+ >
114
+ a few seconds ago
115
+ </time>
116
+ </div>
117
+ </a>
118
+ </div>
119
+ </div>
120
+ </div>
77
121
  `;