Skip to content

Commit

Permalink
chore: add elastic-sticky.cy.ts (#6666)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Feb 5, 2024
1 parent 543f8fa commit 55bf1b2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 69 deletions.

This file was deleted.

64 changes: 64 additions & 0 deletions projects/demo-cypress/src/tests/elastic-sticky.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {Component} from '@angular/core';
import {TuiElasticStickyModule} from '@taiga-ui/addon-mobile';
import {TuiRootModule, TuiScrollbarModule} from '@taiga-ui/core';

describe('ElasticSticky', () => {
let component: TestComponent;

@Component({
template: `
<tui-root>
<div
id="scroll"
style="position: relative; height: 100px; overflow: auto"
tuiScrollRef
>
<div style="height: 50px">I'm header</div>
<div
style="position: sticky; height: 50px; top: 0"
(tuiElasticSticky)="onElastic($event)"
>
I'm sticky
</div>
<div style="height: 100px">I'm footer</div>
</div>
</tui-root>
`,
})
class TestComponent {
activeItemIndex = 0;
offset = NaN;

onElastic(value: number): void {
this.offset = value;
}
}

beforeEach(() =>
cy
.mount(TestComponent, {
imports: [TuiRootModule, TuiScrollbarModule, TuiElasticStickyModule],
})
.then(wrapper => {
component = wrapper.component;
}),
);

it('callback is not triggered initially', () => {
void expect(Number.isNaN(component.offset)).to.true;
});

it('callback is triggered with 0.5 when half of sticky would be hidden', () => {
cy.get('#scroll')
.then(query => query.get(0).scrollTo({top: 75}))
.then(() => cy.wait(100))
.then(() => expect(Number(component.offset.toFixed(1))).to.equal(0.5));
});

it('callback is triggered with 0 when sticky is fully hidden', () => {
cy.get('#scroll')
.then(query => query.get(0).scrollTo({top: 100}))
.then(() => cy.wait(100))
.then(() => expect(Number(component.offset.toFixed(1))).to.equal(0));
});
});

0 comments on commit 55bf1b2

Please sign in to comment.