Skip to content

Commit

Permalink
fix tests attempt 1
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan committed Sep 9, 2024
1 parent 9004d72 commit 8bfde19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/BeaconLrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class BeaconLrc {
_getElementDistance(element) {
const rect = element.getBoundingClientRect();
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
console.log( rect, scrollTop );
return Math.max(0, rect.top + scrollTop - BeaconUtils.getScreenHeight());
}

Expand Down
15 changes: 8 additions & 7 deletions test/BeaconLrc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('BeaconLrc', function() {
{
getBoundingClientRect: () => {
return {
top : 0,
top : 800,
};
},
getAttribute: () => 'hash2',
Expand All @@ -31,7 +31,7 @@ describe('BeaconLrc', function() {
{
getBoundingClientRect: () => {
return {
top : 200,
top : 1000,
};
},
getAttribute: () => 'hash3',
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('BeaconLrc', function() {
beaconLrc = new BeaconLrc(config, logger);

// Mocking window.pageYOffset
global.window = { pageYOffset: 100 };
global.window = { pageYOffset: 100, innerHeight: 500 };
});

afterEach(function() {
Expand Down Expand Up @@ -104,14 +104,15 @@ describe('BeaconLrc', function() {
assert(Array.isArray(elements));
assert.strictEqual(elements.length, 2);

console.log(elements[0].hash);
assert.strictEqual(elements[0].hash, 'hash1');
assert.strictEqual(elements[0].depth, 1);
console.log( elements );
assert.strictEqual(elements[0].distance, 100);
assert.strictEqual(elements[0].distance, 0);

console.log(elements[1].hash);
assert.strictEqual(elements[1].hash, 'hash2');
assert.strictEqual(elements[1].depth, 1);
assert.strictEqual(elements[1].distance, 100);
assert.strictEqual(elements[1].distance, 400);

_getElementDepthStub.restore();
_skipElementStub.restore();
Expand All @@ -135,7 +136,7 @@ describe('BeaconLrc', function() {

it('should return correct distance', () => {
const distance = beaconLrc._getElementDistance(mockElements[2]);
assert.strictEqual(distance, 300);
assert.strictEqual(distance, 600);
});

it('should return 0 if distance is negative', () => {
Expand Down

0 comments on commit 8bfde19

Please sign in to comment.