Skip to content

Commit 95de372

Browse files
committed
test: added e2e tests with docker and cypress
1 parent 4080506 commit 95de372

File tree

8 files changed

+143
-0
lines changed

8 files changed

+143
-0
lines changed

test/component/home.module.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { NgModule } from '@angular/core';
2+
import { IonicModule } from '@ionic/angular';
3+
import { IonicHeaderParallaxModule } from 'ionic-header-parallax'
4+
import { HomePage } from './home.page';
5+
6+
@NgModule({
7+
declarations: [HomePage],
8+
imports: [IonicHeaderParallaxModule, IonicModule],
9+
exports: [HomePage],
10+
})
11+
export class HomePageModule {
12+
constructor() {}
13+
}

test/component/home.page.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<ion-header
2+
[translucent]="true"
3+
parallax
4+
imageUrl="https://picsum.photos/720"
5+
>
6+
<ion-toolbar color="secondary">
7+
<ion-title> Ionic Header Parallax </ion-title>
8+
</ion-toolbar>
9+
</ion-header>
10+
11+
<ion-content [fullscreen]="true">
12+
<div id="container">
13+
<strong>Ready to create an app?</strong>
14+
<p>
15+
Start with Ionic
16+
<a
17+
target="_blank"
18+
rel="noopener noreferrer"
19+
href="https://ionicframework.com/docs/components"
20+
>UI Components</a
21+
>
22+
</p>
23+
</div>
24+
</ion-content>

test/component/home.page.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#container {
2+
text-align: center;
3+
4+
position: absolute;
5+
left: 0;
6+
right: 0;
7+
top: 50%;
8+
height: 200vh;
9+
}
10+
11+
#container strong {
12+
font-size: 20px;
13+
line-height: 26px;
14+
}
15+
16+
#container p {
17+
font-size: 16px;
18+
line-height: 22px;
19+
20+
color: #8c8c8c;
21+
22+
margin: 0;
23+
}
24+
25+
#container a {
26+
text-decoration: none;
27+
}

test/component/home.page.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Component } from '@angular/core';
2+
import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
3+
import { ParallaxDirective } from 'ionic-header-parallax'
4+
5+
@Component({
6+
selector: 'app-home',
7+
templateUrl: 'home.page.html',
8+
styleUrls: ['home.page.scss'],
9+
imports: [IonHeader, IonToolbar, IonTitle, IonContent, ParallaxDirective],
10+
})
11+
export class HomePage {
12+
constructor() {}
13+
}

test/test.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
# Use this to test the angular project with cypress
3+
4+
HOME_COMPONENT_PATH="$PWD/component"
5+
CYPRESS_CONFIG_PATH="$PWD/tests"
6+
DIST_PATH="$PWD/../dist/ionic-header-parallax"
7+
8+
docker run \
9+
--rm \
10+
-v "$HOME_COMPONENT_PATH:/app/src/app/home" \
11+
-v "$CYPRESS_CONFIG_PATH:/cypress" \
12+
-v "$DIST_PATH:/dist" \
13+
-p 4200:4200 \
14+
-ti \
15+
raschidjfr/ionic-blank:ionic8-angular19-cypress14 \
16+
sh -c "
17+
npm i && \
18+
npm i ionic-header-parallax@next cypress && \
19+
npm i -g wait-on && \
20+
cp -r /cypress/* . && \
21+
(ng serve --host 0.0.0.0 --port 4200 & \
22+
wait-on http://0.0.0.0:4200 && \
23+
npx cypress run)
24+
"

test/tests/cypress.config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { defineConfig } from 'cypress'
2+
3+
export default defineConfig({
4+
5+
e2e: {
6+
baseUrl: 'http://0.0.0.0:4200',
7+
supportFile: false
8+
},
9+
10+
11+
component: {
12+
devServer: {
13+
framework: 'angular',
14+
bundler: 'webpack',
15+
},
16+
specPattern: '**/*.cy.ts'
17+
}
18+
19+
})

test/tests/cypress/e2e/spec.cy.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
describe('Ionic Header Parallax', () => {
2+
it('Main component can load', () => {
3+
cy.visit('/');
4+
cy.contains('Start with Ionic UI Components');
5+
});
6+
7+
it('Parallax effect works', () => {
8+
cy.visit('/');
9+
cy.wait(200);
10+
11+
cy.get('ion-header').should('have.css', 'height', '300px');
12+
cy.get('ion-content').shadow().find('.inner-scroll').scrollTo('bottom');
13+
cy.get('ion-header').invoke('height').should('be.lessThan', 60);
14+
});
15+
});

test/tests/cypress/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["**/*.ts"],
4+
"compilerOptions": {
5+
"sourceMap": false,
6+
"types": ["cypress"]
7+
}
8+
}

0 commit comments

Comments
 (0)