File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
site/src/components/GlobalSnackbar Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 4
4
isNotificationTextPrefixed ,
5
5
MsgType ,
6
6
NotificationMsg ,
7
+ NotificationTextPrefixed ,
7
8
SnackbarEventType ,
8
9
} from "./utils"
9
10
@@ -17,6 +18,29 @@ describe("Snackbar", () => {
17
18
// When
18
19
const isTextPrefixed = isNotificationTextPrefixed ( msg )
19
20
21
+ // Then
22
+ expect ( isTextPrefixed ) . toBe ( false )
23
+ } )
24
+ it ( "returns true if prefixed" , ( ) => {
25
+ // Given
26
+ const msg : NotificationTextPrefixed = {
27
+ prefix : "warning" ,
28
+ text : "careful with this workspace" ,
29
+ }
30
+
31
+ // When
32
+ const isTextPrefixed = isNotificationTextPrefixed ( msg )
33
+
34
+ // Then
35
+ expect ( isTextPrefixed ) . toBe ( true )
36
+ } )
37
+ it ( "returns false if not prefixed" , ( ) => {
38
+ // Given
39
+ const msg = "plain ol' message"
40
+
41
+ // When
42
+ const isTextPrefixed = isNotificationTextPrefixed ( msg )
43
+
20
44
// Then
21
45
expect ( isTextPrefixed ) . toBe ( false )
22
46
} )
Original file line number Diff line number Diff line change @@ -27,8 +27,10 @@ export const isNotificationText = (msg: AdditionalMessage): msg is string => {
27
27
export const isNotificationTextPrefixed = (
28
28
msg : AdditionalMessage | null ,
29
29
) : msg is NotificationTextPrefixed => {
30
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
31
- return typeof ( msg as NotificationTextPrefixed ) ?. prefix !== "undefined"
30
+ if ( msg ) {
31
+ return typeof msg !== "string" && Object . prototype . hasOwnProperty . call ( msg , "prefix" )
32
+ }
33
+ return false
32
34
}
33
35
34
36
export const isNotificationList = ( msg : AdditionalMessage ) : msg is string [ ] => {
You can’t perform that action at this time.
0 commit comments