Skip to content

Commit

Permalink
fixed toggle calling old function name, created test for toggleUserDi…
Browse files Browse the repository at this point in the history
…smissable
  • Loading branch information
FireLemons committed Oct 7, 2023
1 parent 8ac598c commit 7dd0b88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/javascript/__tests__/notifier.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,19 @@ describe('Notifications', () => {
test('will add a functioning dismiss button for the user if there is none', (done) => {
$(() => {
try {
const notificationMessage = 'nm8j$w*HszPHkObK._n'
notification = notifier.notify(notificationMessage, 'info', false)

expect(notificationsElement[0].innerHTML).toContain(notificationMessage)
expect(notification.notificationElement.children('button').length).toBe(0)

notification.toggleUserDismissable()

expect(notification.notificationElement.children('button').length).toBe(1)

notification.notificationElement.children('button').click()

expect($(document).find(notification.notificationElement).length).toBe(0)
done()
} catch (error) {
done(error)
Expand All @@ -562,6 +575,12 @@ describe('Notifications', () => {
test('throws an error if the notification has been dismissed', (done) => {
$(() => {
try {
notification.notificationElement.remove()
expect(notificationsElement[0].innerHTML).not.toContain(notificationDefaultMessage)

expect(() => {
notification.toggleUserDismissable()
}).toThrow(ReferenceError)
done()
} catch (error) {
done(error)
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/src/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Notification {
toggleUserDismissable () {
this.#throwErrorIfDismissed()

if (this.isDismissable()) {
if (this.isUserDismissable()) {
this.#userDismissableDisable()
} else {
this.#userDismissableEnable()
Expand Down

0 comments on commit 7dd0b88

Please sign in to comment.