Browse Source

[frontend] Prevent showing alerts without a message

Johan Åhlén 2 years ago
parent
commit
84e8e42318

+ 9 - 0
desktop/core/src/desktop/js/reactComponents/AlertComponent/AlertComponent.test.tsx

@@ -47,6 +47,15 @@ describe('AlertComponent', () => {
     expect(alerts[1]).toHaveTextContent('Error 2');
   });
 
+  test("it shouldn't show empty error messages", async () => {
+    render(<AlertComponent />);
+    expect(screen.queryAllByRole('alert')).toHaveLength(0);
+
+    act(() => huePubSub.publish('hue.global.error', { message: '' }));
+
+    expect(screen.queryAllByRole('alert')).toHaveLength(0);
+  });
+
   test('it should show unique error messages', async () => {
     render(<AlertComponent />);
     expect(screen.queryAllByRole('alert')).toHaveLength(0);

+ 4 - 0
desktop/core/src/desktop/js/reactComponents/AlertComponent/AlertComponent.tsx

@@ -29,6 +29,10 @@ const AlertComponent: React.FC = () => {
 
   useEffect(() => {
     const hueSub = huePubSub.subscribe('hue.global.error', (newError: ErrorAlert) => {
+      if (!newError.message) {
+        return;
+      }
+
       setErrors(activeErrors => {
         // Prevent showing the same message multiple times.
         // TODO: Consider showing a count in the error notification when the same message is reported multiple times.