Skip to content

Commit fac3c3c

Browse files
chuckcarpenterRobbieTheWagner
authored andcommitted
test: Add test for fixed anchoring on scroll (#330)
1 parent 9f8963a commit fac3c3c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
describe('Scroll', () => {
2+
beforeEach(() => {
3+
cy.visit('/examples/scroll/', {});
4+
});
5+
6+
describe('tether stays near scrollbar', () => {
7+
it('appears on scroll and stays in fixed position', () => {
8+
let tetherFixed;
9+
let tetherOffsetTop;
10+
11+
cy.get('.tether-target').and(el => {
12+
// set the initial position coords
13+
tetherFixed = el.find('.pointer');
14+
// starting point is 9px from top of document
15+
tetherOffsetTop = tetherFixed[0].getBoundingClientRect().top - 9;
16+
17+
expect(el).to.contain('.pointer');
18+
});
19+
cy.get('.pointer').should('have.css', 'opacity', '0');
20+
21+
cy.scrollTo(0, 1500);
22+
23+
cy.get('.pointer').should('have.css', 'opacity', '1');
24+
cy.get('.pointer').and(el => {
25+
const vpOffset = el[0].getBoundingClientRect();
26+
// we measure from top minus scrolled coords
27+
expect(vpOffset.top + window.pageYOffset).to.equal(tetherOffsetTop);
28+
});
29+
});
30+
});
31+
});

0 commit comments

Comments
 (0)