Skip to content

Commit e6a5499

Browse files
committed
fix: update isNotificationTextPrefixed
This removes an eslint-disable rule and adds two new tests to ensure isNotificationTextPrefixed is working as expected.
1 parent b23f35f commit e6a5499

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

site/src/components/GlobalSnackbar/utils.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
isNotificationTextPrefixed,
55
MsgType,
66
NotificationMsg,
7+
NotificationTextPrefixed,
78
SnackbarEventType,
89
} from "./utils"
910

@@ -17,6 +18,29 @@ describe("Snackbar", () => {
1718
// When
1819
const isTextPrefixed = isNotificationTextPrefixed(msg)
1920

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+
2044
// Then
2145
expect(isTextPrefixed).toBe(false)
2246
})

site/src/components/GlobalSnackbar/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ export const isNotificationText = (msg: AdditionalMessage): msg is string => {
2727
export const isNotificationTextPrefixed = (
2828
msg: AdditionalMessage | null,
2929
): 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
3234
}
3335

3436
export const isNotificationList = (msg: AdditionalMessage): msg is string[] => {

0 commit comments

Comments
 (0)