Skip to content

Commit

Permalink
Merge pull request #8 from chagasaway/detox-with-ts
Browse files Browse the repository at this point in the history
Detox with ts
  • Loading branch information
newtonbeck authored Apr 24, 2019
2 parents dca6ef7 + 06705d2 commit ccdeef5
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 651 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,29 @@ Start the application
npm start
```

## :heavy_check_mark: Running tests
## :heavy_check_mark: Running unit and integration tests

```sh
npm run test:unit
npm run test:integration
npm run test:e2e
```

## :heavy_check_mark: Running E2E tests

Download the latest Expo client from https://expo.io/tools#client and extract it to a folder named `bin/Exponent.app` inside the project. Run the following commands:

```sh
brew tap wix/brew
brew install applesimutils
npm install -g detox-cli
detox test
```

Do not forget to start the mocked server running the following commands:

```sh
cd server
npm start
```

## :sparkles: Running lint
Expand Down
7 changes: 3 additions & 4 deletions e2e/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"setupFilesAfterEnv": [
"./init.js"
],
"testEnvironment": "node"
"preset": "ts-jest",
"testEnvironment": "node",
"setupTestFrameworkScriptFile": "./init.js"
}
5 changes: 5 additions & 0 deletions e2e/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'detox-expo-helpers' {

export function reloadApp(): void;

}
16 changes: 13 additions & 3 deletions e2e/page-objects/AmountInputPageObject.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { by, element, expect } from 'detox';
import { QRCodePageObject } from './QRCodePageObject';

export class AmountInputPageObject {
public async getScreen() {
return element(by.id('AmountInputScreen'));

public async assertIsVisible() {
await expect(element(by.id('AmountInputScreen'))).toBeVisible();
}

public async fillAmount(amount: number) {
await element(by.id('amountInput')).tap();
await element(by.id('amountInput')).typeText(`${amount}`);
}

public async confirm() {
public async assertHasAmountOf(amount: number) {
await expect(element(by.text(`${amount}`))).toBeVisible();
}

public async confirm(): Promise<QRCodePageObject> {
await element(by.id('confirmButton')).tap();
return new QRCodePageObject();
}
}
14 changes: 11 additions & 3 deletions e2e/page-objects/QRCodePageObject.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { by, element, expect } from 'detox';

export class QRCodePageObject {
public async getScreen() {
return element(by.id('QRCodeScreen'));

public async assertIsVisible() {
await expect(element(by.id('QRCodeScreen'))).toBeVisible();
}

public async share() {
await element(by.id('shareBtn')).tap();
await element(by.id('shareButton')).tap();
}

public async assertIsShared() {
await expect(element(by.text('OK'))).toBeVisible();
}

}
31 changes: 21 additions & 10 deletions e2e/tests/request-money/request-money.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
const { reloadApp } = require('detox-expo-helpers');
import { reloadApp } from 'detox-expo-helpers';
import { AmountInputPageObject } from '../../page-objects/AmountInputPageObject';
import { QRCodePageObject } from '../../page-objects/QRCodePageObject';

describe('Request money', () => {
beforeAll(async () => {
await reloadApp();
});

it('should show amount input screen', async () => {
await expect(element(by.id('AmountInputScreen'))).toBeVisible();
const amountInputPage = new AmountInputPageObject();
await amountInputPage.assertIsVisible();
});

it('should type request money amount', async () => {
await element(by.id('amountInput')).typeText('5');
it('should fill the requested amount', async () => {
const amountInputPage = new AmountInputPageObject();
await amountInputPage.fillAmount(5);
await amountInputPage.assertHasAmountOf(5);
});

it('should confirm request money', async () => {
await element(by.id('confirmButton')).tap();
it('should confirm the requested amount', async () => {
const amountInputPage = new AmountInputPageObject();
const qrCodePage = await amountInputPage.confirm();
await qrCodePage.assertIsVisible();
});

it('should should show qrcode screen', async () => {
await element(by.id('QRCodeScreen')).toBeVisible();
it('should share the QR code', async () => {
const qrCodePage = new QRCodePageObject();
await qrCodePage.share();
await qrCodePage.assertIsShared();
});

it('should share the qrcode', async () => {
await element(by.id('shareButton')).tap();
it('should should show amount input screen again', async () => {
const qrCodePage = new AmountInputPageObject();
await qrCodePage.assertIsVisible();
});

});
Loading

0 comments on commit ccdeef5

Please sign in to comment.