Skip to content

Commit

Permalink
test(angular): add test for dynamic slides (ionic-team#17167)
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat authored Jan 18, 2019
1 parent 5cb7f68 commit b01c869
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
12 changes: 11 additions & 1 deletion angular/test/test-app/e2e/src/slides.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ describe('slides', () => {
});

it('should change index on slide change', async () => {
expect(await element.all(by.css('ion-slide')).count()).toEqual(0);
await addSlides();
expect(await element.all(by.css('ion-slide')).count()).toEqual(3);

await checkIndex('0');

await nextSlide();
Expand All @@ -29,6 +33,12 @@ async function checkIndex(index: string) {
expect(await element(by.css('#slide-index-2')).getText()).toEqual(index);
}

async function addSlides() {
await element(by.css('#add-slides')).click();
await waitTime(800);
}


async function nextSlide() {
await element(by.css('#btn-next')).click();
await waitTime(800);
Expand All @@ -37,4 +47,4 @@ async function nextSlide() {
async function prevSlide() {
await element(by.css('#btn-prev')).click();
await waitTime(800);
}
}
14 changes: 5 additions & 9 deletions angular/test/test-app/src/app/slides/slides.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@
<ion-content>
<ion-slides pager="true" (ionSlideDidChange)="checkIndex()">

<ion-slide>
<h1>Slide 1</h1>
<ion-slide *ngFor="let text of slidesData">
<h1>{{text}}</h1>
</ion-slide>

<ion-slide>
<h1>Slide 2</h1>
</ion-slide>

<ion-slide>
<h1>Slide 3</h1>
</ion-slide>
</ion-slides>

<p>
index: <span id="slide-index">{{slideIndex}}</span>
index2: <span id="slide-index-2">{{slideIndex2}}</span>
</p>

<ion-button id="add-slides" (click)="addSlides()">
Add Slides
</ion-button>
<ion-button id="btn-prev" (click)="prevSlide()">
Prev Slide
</ion-button>
Expand Down
6 changes: 6 additions & 0 deletions angular/test/test-app/src/app/slides/slides.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class SlidesComponent implements AfterViewInit {

slideIndex = 0;
slideIndex2 = 0;
slidesData = [];

constructor() { }

Expand All @@ -19,6 +20,11 @@ export class SlidesComponent implements AfterViewInit {
});
}

addSlides() {
const start = this.slidesData.length + 1;
this.slidesData.push(`Slide ${start}`, `Slide ${start + 1}`, `Slide ${start + 2}`);
}

prevSlide() {
this.slides.slidePrev();
}
Expand Down

0 comments on commit b01c869

Please sign in to comment.