-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from WSU-4110/Jesse_developMagic
Jesse develop magic
- Loading branch information
Showing
7 changed files
with
235 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
const VideoModal = require('../scripts/videopage'); | ||
|
||
describe('VideoModal - attachCloseButtonEvent', () => { | ||
beforeEach(() => { | ||
// Mocking the DOM elements needed | ||
const closeButton = { onclick: null }; | ||
beforeEach(() => { | ||
// Mocking the DOM elements needed | ||
const closeButton = { | ||
onclick: null | ||
}; | ||
|
||
document.getElementsByClassName = jest.fn().mockReturnValue([closeButton]); | ||
document.querySelectorAll = jest.fn().mockReturnValue([]); // Not used in this specific test. | ||
document.getElementsByClassName = jest.fn().mockReturnValue([closeButton]); | ||
document.querySelectorAll = jest.fn().mockReturnValue([]); // Not used in this specific test. | ||
|
||
// Additional mocking to ensure no unintended executions | ||
document.getElementById = jest.fn().mockReturnValue({style: {}}); | ||
global.fetch = jest.fn(); // Mock fetch as it might be called in class constructor or methods | ||
}); | ||
// Additional mocking to ensure no unintended executions | ||
document.getElementById = jest.fn().mockReturnValue({ | ||
style: {} | ||
}); | ||
global.fetch = jest.fn(); // Mock fetch as it might be called in class constructor or methods | ||
}); | ||
|
||
it('sets onclick event on closeButton', () => { | ||
const videoModal = new VideoModal('modal', 'videoFrame', 'close', '.video-card'); | ||
videoModal.attachCloseButtonEvent(); | ||
it('sets onclick event on closeButton', () => { | ||
const videoModal = new VideoModal('modal', 'videoFrame', 'close', '.video-card'); | ||
videoModal.attachCloseButtonEvent(); | ||
|
||
expect(typeof videoModal.closeButton.onclick).toBe('function'); | ||
}); | ||
expect(typeof videoModal.closeButton.onclick).toBe('function'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,59 @@ | ||
const VideoModal = require('../scripts/videopage'); | ||
|
||
describe('VideoModal - init', () => { | ||
beforeEach(() => { | ||
// Mocking DOM elements and fetch | ||
document.getElementById = jest.fn((id) => { | ||
if (id === 'modal') return { style: {} }; | ||
if (id === 'videoFrame') return { src: '' }; | ||
return null; | ||
}); | ||
beforeEach(() => { | ||
// Mocking DOM elements and fetch | ||
document.getElementById = jest.fn((id) => { | ||
if (id === 'modal') return { | ||
style: {} | ||
}; | ||
if (id === 'videoFrame') return { | ||
src: '' | ||
}; | ||
return null; | ||
}); | ||
|
||
document.getElementsByClassName = jest.fn().mockReturnValue([{ | ||
onclick: jest.fn() | ||
}]); | ||
document.getElementsByClassName = jest.fn().mockReturnValue([{ | ||
onclick: jest.fn() | ||
}]); | ||
|
||
document.querySelectorAll = jest.fn().mockReturnValue([{ | ||
addEventListener: jest.fn(), | ||
getAttribute: jest.fn().mockReturnValue('123'), | ||
querySelector: jest.fn().mockReturnValue({ | ||
classList: { toggle: jest.fn() }, | ||
innerHTML: '', | ||
textContent: '' | ||
}) | ||
}]); | ||
document.querySelectorAll = jest.fn().mockReturnValue([{ | ||
addEventListener: jest.fn(), | ||
getAttribute: jest.fn().mockReturnValue('123'), | ||
querySelector: jest.fn().mockReturnValue({ | ||
classList: { | ||
toggle: jest.fn() | ||
}, | ||
innerHTML: '', | ||
textContent: '' | ||
}) | ||
}]); | ||
|
||
// Mock fetch call used in updateAllLikeStates | ||
global.fetch = jest.fn(() => Promise.resolve({ | ||
ok: true, | ||
json: () => Promise.resolve({ likes: 42, liked: false }) | ||
})); | ||
}); | ||
// Mock fetch call used in updateAllLikeStates | ||
global.fetch = jest.fn(() => Promise.resolve({ | ||
ok: true, | ||
json: () => Promise.resolve({ | ||
likes: 42, | ||
liked: false | ||
}) | ||
})); | ||
}); | ||
|
||
it('calls methods to attach event listeners and updates like states', async () => { | ||
// Setup | ||
const videoModal = new VideoModal('modal', 'videoFrame', 'close', '.video-card'); | ||
videoModal.attachVideoCardsEvents = jest.fn(); | ||
videoModal.attachCloseButtonEvent = jest.fn(); | ||
videoModal.attachWindowClickEvent = jest.fn(); | ||
videoModal.updateAllLikeStates = jest.fn(); | ||
it('calls methods to attach event listeners and updates like states', async () => { | ||
// Setup | ||
const videoModal = new VideoModal('modal', 'videoFrame', 'close', '.video-card'); | ||
videoModal.attachVideoCardsEvents = jest.fn(); | ||
videoModal.attachCloseButtonEvent = jest.fn(); | ||
videoModal.attachWindowClickEvent = jest.fn(); | ||
videoModal.updateAllLikeStates = jest.fn(); | ||
|
||
// Act | ||
await videoModal.init(); | ||
// Act | ||
await videoModal.init(); | ||
|
||
// Assert | ||
expect(videoModal.attachVideoCardsEvents).toHaveBeenCalled(); | ||
expect(videoModal.attachCloseButtonEvent).toHaveBeenCalled(); | ||
expect(videoModal.attachWindowClickEvent).toHaveBeenCalled(); | ||
expect(videoModal.updateAllLikeStates).toHaveBeenCalled(); | ||
}); | ||
// Assert | ||
expect(videoModal.attachVideoCardsEvents).toHaveBeenCalled(); | ||
expect(videoModal.attachCloseButtonEvent).toHaveBeenCalled(); | ||
expect(videoModal.attachWindowClickEvent).toHaveBeenCalled(); | ||
expect(videoModal.updateAllLikeStates).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.