-
Notifications
You must be signed in to change notification settings - Fork 0
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 #15 from wp-media/fix/11-fix-ci-after-3-17-refacto
Adapt the tests to the 3.17 refacto
- Loading branch information
Showing
4 changed files
with
119 additions
and
91 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import assert from 'assert'; | ||
import sinon from 'sinon'; | ||
import BeaconLcp from '../src/BeaconLcp.js'; | ||
import node_fetch from 'node-fetch'; | ||
global.fetch = node_fetch; | ||
|
||
describe('BeaconManager', function() { | ||
let beacon; | ||
const config = { nonce: 'test', url: 'http://example.com', is_mobile: false }; | ||
beforeEach(function() { | ||
beacon = new BeaconLcp(config); | ||
}); | ||
|
||
describe('#constructor()', function() { | ||
it('should initialize with the given config', function() { | ||
assert.deepStrictEqual(beacon.config, config); | ||
}); | ||
}); | ||
|
||
describe('#_isDuplicateImage()', function() { | ||
it('should return true for a duplicate image', function() { | ||
beacon.performanceImages = [{ src: 'http://example.com/image.jpg', nodeName:'img', type:'img' }]; | ||
const image = { src: 'http://example.com/image.jpg', nodeName:'img', type:'img' }; | ||
assert.strictEqual(beacon._isDuplicateImage(image), true); | ||
}); | ||
|
||
it('should return false for a unique image', function() { | ||
beacon.performanceImages = [{ src: 'http://example.com/image.jpg', nodeName:'img', type:'img' }]; | ||
const image = { src: 'http://example.com/unique.jpg', nodeName:'img', type:'img' }; | ||
assert.strictEqual(beacon._isDuplicateImage(image), false); | ||
}); | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import assert from 'assert'; | ||
import sinon from 'sinon'; | ||
import BeaconUtils from '../src/Utils.js'; | ||
import node_fetch from 'node-fetch'; | ||
global.fetch = node_fetch; | ||
|
||
describe('BeaconManager', function() { | ||
|
||
describe('#isIntersecting', function() { | ||
beforeEach(function () { | ||
// Mock viewport size | ||
global.window = { | ||
innerWidth: 1024, | ||
innerHeight: 768 | ||
}; | ||
}); | ||
|
||
it('should return true for a rectangle fully within the viewport', function () { | ||
const rect = {top: 100, left: 100, bottom: 200, right: 200}; | ||
assert.strictEqual(BeaconUtils.isIntersecting(rect), true); | ||
}); | ||
|
||
it('should return false for a rectangle entirely above the viewport', function () { | ||
const rect = {top: -500, left: 100, bottom: -400, right: 200}; | ||
assert.strictEqual(BeaconUtils.isIntersecting(rect), false); | ||
}); | ||
|
||
it('should return false for a rectangle entirely below the viewport', function () { | ||
const rect = {top: 800, left: 100, bottom: 900, right: 200}; | ||
assert.strictEqual(BeaconUtils.isIntersecting(rect), false); | ||
}); | ||
|
||
it('should return false for a rectangle entirely to the left of the viewport', function () { | ||
const rect = {top: 100, left: -500, bottom: 200, right: -400}; | ||
assert.strictEqual(BeaconUtils.isIntersecting(rect), false); | ||
}); | ||
|
||
it('should return false for a rectangle entirely to the right of the viewport', function () { | ||
const rect = {top: 100, left: 1100, bottom: 200, right: 1200}; | ||
assert.strictEqual(BeaconUtils.isIntersecting(rect), false); | ||
}); | ||
}); | ||
|
||
describe('#isPageCached', function() { | ||
|
||
it('should return true when the page is cached', function() { | ||
|
||
global.document ={ | ||
documentElement: { | ||
nextSibling: { | ||
data:'<!--Debug: cached-->' | ||
} | ||
} | ||
}; | ||
|
||
assert.strictEqual(BeaconUtils.isPageCached(), true); | ||
}); | ||
|
||
it('should return false when the page is not cached', function() { | ||
global.document ={ | ||
documentElement: { | ||
nextSibling: { | ||
data:'test' | ||
} | ||
} | ||
}; | ||
assert.strictEqual(BeaconUtils.isPageCached(), false); | ||
}); | ||
}); | ||
|
||
}); |