Skip to content

Commit

Permalink
test: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
a-asad committed Dec 12, 2024
1 parent 2762cfc commit fdb1b9a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
20 changes: 20 additions & 0 deletions xmodule/js/spec/video/video_control_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,26 @@
});

describe('constructor with end-time', function() {
it('displays the correct time when startTime and endTime are specified', function(done) {
state = jasmine.initializePlayer({
start: 10,
end: 20
});
spyOn(state.videoPlayer, 'duration').and.returnValue(60);

state.videoControl.updateVcrVidTime({
time: 15,
duration: 60
});

jasmine.waitUntil(function() {
var expectedValue = $('.video-controls').find('.vidtime');
return expectedValue.text().indexOf('0:05 / 0:20') !== -1; // Expecting 15 seconds - 10 seconds = 5 seconds
}).then(function() {
expect($('.video-controls').find('.vidtime')).toHaveText('0:05 / 0:20');
}).always(done);
});

it(
'saved position is 0, timer slider and VCR set to 0:00 '
+ 'and ending at specified end-time',
Expand Down
49 changes: 49 additions & 0 deletions xmodule/js/spec/video/video_events_plugin_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,55 @@ import '../helper.js';
destroy: plugin.destroy
});
});

describe('getCurrentTime method', function() {
it('returns current time adjusted by startTime if video starts from a subsection', function() {
spyOn(state.videoPlayer, 'currentTime', 'get').and.returnValue(120);
state.config.startTime = 30;
expect(state.videoEventsPlugin.getCurrentTime()).toBe(90); // 120 - 30 = 90
});

it('returns 0 if currentTime is undefined', function() {
spyOn(state.videoPlayer, 'currentTime', 'get').and.returnValue(undefined);
state.config.startTime = 30; // Start time is irrelevant since current time is undefined
expect(state.videoEventsPlugin.getCurrentTime()).toBe(0);
});

it('returns unadjusted current time if startTime is not defined', function() {
spyOn(state.videoPlayer, 'currentTime', 'get').and.returnValue(60);
expect(state.videoEventsPlugin.getCurrentTime()).toBe(60); // Returns current time as is
});
});

describe('log method', function() {
it('logs event with adjusted duration when startTime and endTime are defined', function() {
state.config.startTime = 30;
state.config.endTime = 150;
state.duration = 200;

state.videoEventsPlugin.log('test_event', {});

expect(Logger.log).toHaveBeenCalledWith('test_event', {
id: 'id',
code: this.code,
duration: 120, // 150 - 30 = 120
});
});

it('logs event with full duration when startTime and endTime are not defined', function() {
state.config.startTime = undefined;
state.config.endTime = undefined;
state.duration = 200;

state.videoEventsPlugin.log('test_event', {});

expect(Logger.log).toHaveBeenCalledWith('test_event', {
id: 'id',
code: this.code,
duration: 200 // Full duration as no start/end time adjustment is needed
});
});
});
});

describe('VideoPlayer Events plugin', function() {
Expand Down

0 comments on commit fdb1b9a

Please sign in to comment.