Skip to content

chore: update cSpell, fix isNotificationTextPrefixed, and refactor e2e tests #4076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: update isNotificationTextPrefixed
This removes an eslint-disable rule and adds two new tests to ensure
isNotificationTextPrefixed is working as expected.
  • Loading branch information
jsjoeio committed Sep 15, 2022
commit e6a5499cef22060ed2ad75e9ba49f817decb0cd7
24 changes: 24 additions & 0 deletions site/src/components/GlobalSnackbar/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
isNotificationTextPrefixed,
MsgType,
NotificationMsg,
NotificationTextPrefixed,
SnackbarEventType,
} from "./utils"

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

// Then
expect(isTextPrefixed).toBe(false)
})
it("returns true if prefixed", () => {
// Given
const msg: NotificationTextPrefixed = {
prefix: "warning",
text: "careful with this workspace",
}

// When
const isTextPrefixed = isNotificationTextPrefixed(msg)

// Then
expect(isTextPrefixed).toBe(true)
})
it("returns false if not prefixed", () => {
// Given
const msg = "plain ol' message"

// When
const isTextPrefixed = isNotificationTextPrefixed(msg)

// Then
expect(isTextPrefixed).toBe(false)
})
Expand Down
6 changes: 4 additions & 2 deletions site/src/components/GlobalSnackbar/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export const isNotificationText = (msg: AdditionalMessage): msg is string => {
export const isNotificationTextPrefixed = (
msg: AdditionalMessage | null,
): msg is NotificationTextPrefixed => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return typeof (msg as NotificationTextPrefixed)?.prefix !== "undefined"
if (msg) {
return typeof msg !== "string" && Object.prototype.hasOwnProperty.call(msg, "prefix")
}
return false
}

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