forked from DockYard/ember-in-viewport
/
is-in-viewport-test.js
57 lines (48 loc) · 1.41 KB
/
is-in-viewport-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import isInViewport from 'ember-in-viewport/utils/is-in-viewport';
import { module, test } from 'qunit';
let fakeRectNotInViewport, fakeRectInViewport, fakeWindow, fakeNoTolerance, fakeTolerance;
module('isInViewport', {
beforeEach() {
fakeRectNotInViewport = {
top: 450,
left: 150,
bottom: 550,
right: 1130
};
fakeRectInViewport = {
top: 300,
left: 150,
bottom: 400,
right: 1130
};
fakeWindow = {
innerHeight: 400,
innerWidth: 1280
};
fakeNoTolerance = {
top: 0,
left: 0,
bottom: 0,
right: 0
};
fakeTolerance = {
top: 200,
bottom: 200
};
}
});
test('returns true if dimensions are within viewport', function(assert) {
const { innerHeight, innerWidth } = fakeWindow;
const result = isInViewport(fakeRectInViewport, innerHeight, innerWidth, fakeNoTolerance);
assert.ok(result);
});
test('returns false if dimensions not within viewport', function(assert) {
const { innerHeight, innerWidth } = fakeWindow;
const result = isInViewport(fakeRectNotInViewport, innerHeight, innerWidth, fakeNoTolerance);
assert.ok(!result);
});
test('returns true if dimensions not within viewport but within tolerance', function(assert) {
const { innerHeight, innerWidth } = fakeWindow;
const result = isInViewport(fakeRectNotInViewport, innerHeight, innerWidth, fakeTolerance);
assert.ok(result);
});