Skip to content

Commit

Permalink
test(e2e): adds test case for position:absolute containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Can Kattwinkel committed Mar 4, 2019
1 parent 506f4ea commit 8cc121f
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 2 deletions.
27 changes: 27 additions & 0 deletions e2e/src/posa.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {browser} from 'protractor';
import {PosaPage} from './posa.po';

describe('with position:absolute container', () => {
let page: PosaPage;

beforeEach(() => {
page = new PosaPage();
page.navigateToDev();
});


it('should recognize sticky ', async () => {
page.navigateToDev();
await browser.executeScript('window.scrollTo(0,501);');
const hasStickyClass = await hasClass(page.getStickyElement(), 'is-sticky');
expect(hasStickyClass).toBe(true);
});


});

// via https://stackoverflow.com/questions/20268128/how-to-test-if-an-element-has-class-using-protractor
async function hasClass(element, cls) {
const classes = await element.getAttribute('class');
return classes.split(' ').indexOf(cls) !== -1;
}
25 changes: 25 additions & 0 deletions e2e/src/posa.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {browser, by, element} from 'protractor';

export class PosaPage {


constructor() {
const width = 1200;
const height = 900;
browser.driver.manage().window().setSize(width, height);
}

navigateToDev() {
return browser.get('/posa');
}


getStickyElement() {
return element(by.css('.some-thing-sticky'));
}

getEnableButton() {
return element(by.css('#enable-btn'));
}
}

4 changes: 3 additions & 1 deletion src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import {RouterModule, Routes} from '@angular/router';

import {HomeComponent} from './home/home.component';
import {DevComponent} from './dev/dev.component';
import {PosaContainerComponent} from './test-cases/posa-container/posa-container.component';

const routes: Routes = [
{path: '', component: HomeComponent},
{path: 'dev', component: DevComponent}
{path: 'dev', component: DevComponent},
{path: 'posa', component: PosaContainerComponent},
];

@NgModule({
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {DevComponent} from './dev/dev.component';
import {HomeComponent} from './home/home.component';
import {AppRoutingModule} from './app-routing.module';
import {AngularStickyThingsModule} from '../../projects/angular-sticky-things/src/lib/angular-sticky-things.module';
import {PosaContainerComponent} from './test-cases/posa-container/posa-container.component';

@NgModule({
declarations: [
AppComponent,
InfoComponent,
DevComponent,
HomeComponent
HomeComponent,
PosaContainerComponent
],
imports: [
BrowserModule,
Expand Down
19 changes: 19 additions & 0 deletions src/app/test-cases/posa-container/posa-container.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<p>
I'm special, since the containing div scrolls and not the body.
</p>


<div class="row">
<div class="col-6">
<div #spacer></div>
<div [spacer]="spacer" class="some-thing-sticky" stickyThing="">
Scroll by!
</div>
</div>
</div>


<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
18 changes: 18 additions & 0 deletions src/app/test-cases/posa-container/posa-container.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
:host {
display: block;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
height: 100%;
overflow: auto;
background-color: red;
}


.some-thing-sticky {
background-color: #fff;
padding: 15px;
color: #000;
}
25 changes: 25 additions & 0 deletions src/app/test-cases/posa-container/posa-container.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';

import {PosaContainerComponent} from './posa-container.component';

describe('PosaContainerComponent', () => {
let component: PosaContainerComponent;
let fixture: ComponentFixture<PosaContainerComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [PosaContainerComponent]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(PosaContainerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
16 changes: 16 additions & 0 deletions src/app/test-cases/posa-container/posa-container.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Component, OnInit} from '@angular/core';

@Component({
selector: 'demo-posa-container',
templateUrl: './posa-container.component.html',
styleUrls: ['./posa-container.component.scss']
})
export class PosaContainerComponent implements OnInit {

constructor() {
}

ngOnInit() {
}

}

0 comments on commit 8cc121f

Please sign in to comment.