Skip to content

Commit

Permalink
stubbed tests, shortened wording on some tests, comments for jQuery c…
Browse files Browse the repository at this point in the history
…allback
  • Loading branch information
FireLemons committed Oct 4, 2023
1 parent dedccda commit 7ad6a20
Showing 1 changed file with 141 additions and 31 deletions.
172 changes: 141 additions & 31 deletions app/javascript/__tests__/notifier.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ beforeEach(() => {

describe('Notifier', () => {
describe('notify', () => {
test("notify should display a green notification when passed a message and level='info'", (done) => {
test("displays a green notification when passed a message and level='info'", (done) => {
const notificationMessage = "'Y$deH[|%ROii]jy"

$(document).ready(() => {
$(() => { // JQuery's callback for the DOM loading
try {
notifier.notify(notificationMessage, 'info')

Expand All @@ -43,10 +43,10 @@ describe('Notifier', () => {
})
})

test("notify should display a red notification when passed a message and level='error'", (done) => {
test("displays a red notification when passed a message and level='error'", (done) => {
const notificationMessage = '\\+!h0bbH"yN7dx9.'

$(document).ready(() => {
$(() => { // JQuery's callback for the DOM loading
try {
notifier.notify(notificationMessage, 'error')

Expand All @@ -61,8 +61,8 @@ describe('Notifier', () => {
})
})

test('notify should append a dismissable message to the notifications widget', (done) => {
$(document).ready(() => {
test('appends a dismissable message to the notifications widget', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
notifier.notify('', 'error')
notifier.notify('', 'info')
Expand Down Expand Up @@ -90,8 +90,8 @@ describe('Notifier', () => {
})
})

test('notify should append a non dismissable message to the notifications widget when message dismissable is turned off', (done) => {
$(document).ready(() => {
test('appends a non dismissable message to the notifications widget when message dismissable is turned off', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
notifier.notify('', 'error', false)

Expand All @@ -111,8 +111,8 @@ describe('Notifier', () => {
})
})

test('notify should throw a RangeError when passed an unsupported message level', (done) => {
$(document).ready(() => {
test('throws a RangeError when passed an unsupported message level', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
expect(() => {
notifier.notify('message', 'unsupported level')
Expand All @@ -125,8 +125,8 @@ describe('Notifier', () => {
})
})

test('notify should throw a TypeError when param message is not a string', (done) => {
$(document).ready(() => {
test('throws a TypeError when param message is not a string', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
expect(() => {
notifier.notify(6, 'info')
Expand All @@ -139,8 +139,8 @@ describe('Notifier', () => {
})
})

test('notify should return a Notification object representing the new notification', (done) => {
$(document).ready(() => {
test('returns a Notification object representing the new notification', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
const notification = notifier.notify('test', 'info')
const onlyNotification = notificationsElement.children('.success-indicator')
Expand All @@ -155,8 +155,8 @@ describe('Notifier', () => {
})

describe('waitForAsyncOperation', () => {
test('waitForAsyncOperation should display the loading indicator', (done) => {
$(document).ready(() => {
test('displays the loading indicator', (done) => {
$(() => { // JQuery's callback for the DOM loading
const loadingToast = $('#async-waiting-indicator')

try {
Expand All @@ -174,8 +174,8 @@ describe('Notifier', () => {
})

describe('resolveAsyncOperation', () => {
test('resolveAsyncOperation should display the saved toast for 2 seconds when not passed an error', (done) => {
$(document).ready(() => {
test('displays the saved toast for 2 seconds when not passed an error', (done) => {
$(() => { // JQuery's callback for the DOM loading
const savedToast = $('#async-success-indicator')

try {
Expand All @@ -195,8 +195,8 @@ describe('Notifier', () => {
})
})

test('resolveAsyncOperation should display the saved toast for 2 seconds after the last call in a quick succession of calls when not passed an error', (done) => {
$(document).ready(() => {
test('displays the saved toast for 2 seconds after the last call in a quick succession of calls when not passed an error', (done) => {
$(() => { // JQuery's callback for the DOM loading
const savedToast = $('#async-success-indicator')

try {
Expand Down Expand Up @@ -227,10 +227,10 @@ describe('Notifier', () => {
})
})

test('resolveAsyncOperation should display a red notification when passed an error', (done) => {
test('displays a red notification when passed an error', (done) => {
const errorMessage = 'hxDEe@no$~Bl%m^]'

$(document).ready(() => {
$(() => { // JQuery's callback for the DOM loading
try {
notifier.waitForAsyncOperation()
notifier.resolveAsyncOperation(errorMessage)
Expand All @@ -246,8 +246,8 @@ describe('Notifier', () => {
})
})

test('resolveAsyncOperation should hide the loading toast when there are no more async operations to wait on', (done) => {
$(document).ready(() => {
test('hides the loading toast when there are no more async operations to wait on', (done) => {
$(() => { // JQuery's callback for the DOM loading
const loadingToast = $('#async-waiting-indicator')

try {
Expand All @@ -267,8 +267,8 @@ describe('Notifier', () => {
})
})

test('resolveAsyncOperation should throw an error and display it in a red notification when trying to stop an async operation when it\'s sexpecting to resolve none', (done) => {
$(document).ready(() => {
test('throws an error and display it in a red notification when trying to stop an async operation when it\'s sexpecting to resolve none', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
expect(() => {
notifier.resolveAsyncOperation()
Expand All @@ -288,13 +288,13 @@ describe('Notifications', () => {
const notificationDefaultMessage = 'm*GV}.n?@D\\~]jW=JD$d'

beforeEach(() => {
$(() => {
$(() => { // JQuery's callback for the DOM loading
notification = notifier.notify(notificationDefaultMessage, 'warn')
})
})

describe('dismiss', () => {
test('dismiss should remove the notification elements', (done) => {
test('removes the notification elements', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
expect(notificationsElement[0].innerHTML).toContain(notificationDefaultMessage)
Expand All @@ -308,7 +308,7 @@ describe('Notifications', () => {
})
})

test('dismiss should throw an error if the notification has already been dismissed', (done) => {
test('should throw an error if the notification has already been dismissed', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
expect(notificationsElement[0].innerHTML).toContain(notificationDefaultMessage)
Expand All @@ -329,7 +329,7 @@ describe('Notifications', () => {
})

describe('getText', () => {
test('getText should return the text of the notification', (done) => {
test('should return the text of the notification', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
expect(notificationsElement[0].innerHTML).toContain(notificationDefaultMessage)
Expand All @@ -343,23 +343,133 @@ describe('Notifications', () => {
})
})

describe('isDismissable', () => {
describe('isUserDismissable', () => {
test('returns true if there is a dismiss button', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
done()
} catch (error) {
done(error)
}
})
})

test('returns false if there is not a dismiss button', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
done()
} catch (error) {
done(error)
}
})
})
})

describe('isDismissed', () => {
test('returns true if the notification could be found as a child of the notificatons component', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
done()
} catch (error) {
done(error)
}
})
})

test('returns false if the notification could not be found as a child of the notificatons component', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
done()
} catch (error) {
done(error)
}
})
})
})

describe('setUserDismissable', () => {
test('adds a dismiss button that removes the notification element when clicked if one is not present', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
done()
} catch (error) {
done(error)
}
})
})

test('removes the dismiss button that removes the notification element when clicked if the button is present', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
done()
} catch (error) {
done(error)
}
})
})

test('throws an error if the notification is dismissed', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
done()
} catch (error) {
done(error)
}
})
})
})

describe('setText', () => {
test('changes the text of the notification', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
done()
} catch (error) {
done(error)
}
})
})

test('throws an error if the notification has been dismissed', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
done()
} catch (error) {
done(error)
}
})
})
})

describe('toggleUserDismissable', () => {
test('will add a functioning dismiss button for the user if there is none', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
done()
} catch (error) {
done(error)
}
})
})

test('will remove the dismiss button for the user if is present', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
done()
} catch (error) {
done(error)
}
})
})

test('throws an error if the notification has been dismissed', (done) => {
$(() => { // JQuery's callback for the DOM loading
try {
done()
} catch (error) {
done(error)
}
})
})
})
})

0 comments on commit 7ad6a20

Please sign in to comment.