-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54baafb
commit 88a2f73
Showing
29 changed files
with
351 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import App from './src/App'; | ||
import { App } from './src/App'; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function ensureAppFinished(duration: number = 1000) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, duration); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { PageObject } from '../page-objects/PageObject'; | ||
|
||
function toBeVisible<T extends PageObject>(received: T) { | ||
const isVisible = received.isVisible(); | ||
return { | ||
message: () => isVisible ? '' : `testID ${received.id} is not visible on the screen`, | ||
pass: isVisible, | ||
}; | ||
} | ||
|
||
declare global { | ||
namespace jest { | ||
interface Matchers<R> { | ||
toBeVisible(): R; | ||
} | ||
} | ||
} | ||
|
||
expect.extend({ | ||
toBeVisible, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import { render } from 'react-native-testing-library'; | ||
import { App } from '../../src/App'; | ||
|
||
export function renderApp() { | ||
return render( | ||
<App /> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import nock from 'nock'; | ||
import { QueryMock } from 'graphql-query-test-mock'; | ||
import { GRAPHQL_API_URL } from './fetchQuery'; | ||
|
||
export function setupQueryMock() { | ||
cleanupNock(); | ||
const queryMock = new QueryMock(); | ||
queryMock.setup(GRAPHQL_API_URL); | ||
return queryMock; | ||
} | ||
|
||
function cleanupNock() { | ||
nock.cleanAll(); | ||
nock.enableNetConnect(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const requestMoney = { | ||
id: 123, | ||
amount: 1000, | ||
qrCode: 'abcde', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { RenderAPI, fireEvent } from 'react-native-testing-library'; | ||
import { PageObject } from './PageObject'; | ||
import { QRCodePageObject } from './QRCodePageObject'; | ||
|
||
export class AmountInputPageObject extends PageObject { | ||
private static inputId = 'amountInput'; | ||
private static confirmButtonId = 'confirmButton'; | ||
|
||
constructor(app: RenderAPI) { | ||
super(app, 'AmountInputScreen'); | ||
} | ||
|
||
public isVisible() { | ||
try { | ||
const input = this.getInput(); | ||
return !!input; | ||
} catch { | ||
return false; | ||
} | ||
} | ||
|
||
public findByTestIdInPage(testID: string) { | ||
return this.page().find((node) => node.props.testID === testID); | ||
} | ||
|
||
public getInput() { | ||
return this.findByTestIdInPage(AmountInputPageObject.inputId); | ||
} | ||
|
||
public fillAmount(amount: string) { | ||
const input = this.getInput(); | ||
fireEvent.changeText(input, amount); | ||
} | ||
|
||
public getAmount() { | ||
const input = this.getInput(); | ||
return input.props.value; | ||
} | ||
|
||
public getConfirmButton() { | ||
return this.findByTestIdInPage(AmountInputPageObject.confirmButtonId); | ||
} | ||
|
||
public confirm = async () => { | ||
const confirmButton = this.getConfirmButton(); | ||
await confirmButton.props.onPress({ preventDefault: () => true }); | ||
return new QRCodePageObject(this.app); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { RenderAPI, fireEvent } from 'react-native-testing-library'; | ||
import { PageObject } from './PageObject'; | ||
import { AmountInputPageObject } from './AmountInputPageObject'; | ||
|
||
export class ErrorPageObject extends PageObject { | ||
private static closeButtonId = 'closeButton'; | ||
|
||
constructor(app: RenderAPI) { | ||
super(app, 'ErrorScreen'); | ||
} | ||
|
||
private getCloseButton() { | ||
return this.page().find((node) => node.props.testID === ErrorPageObject.closeButtonId); | ||
} | ||
|
||
public async close() { | ||
const closeButton = this.getCloseButton(); | ||
fireEvent.press(closeButton); | ||
return new AmountInputPageObject(this.app); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { RenderAPI } from 'react-native-testing-library'; | ||
import { ReactTestInstance } from 'react-test-renderer'; | ||
|
||
export abstract class PageObject { | ||
public id: string; | ||
protected app: RenderAPI; | ||
|
||
constructor(app: RenderAPI, id: string) { | ||
this.app = app; | ||
this.id = id; | ||
} | ||
|
||
public isVisible(): boolean { | ||
const page = this.app.queryByTestId(this.id); | ||
return !!page; | ||
} | ||
|
||
protected page(): ReactTestInstance { | ||
return this.app.getByTestId(this.id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { RenderAPI, fireEvent } from 'react-native-testing-library'; | ||
import { PageObject } from './PageObject'; | ||
import { AmountInputPageObject } from './AmountInputPageObject'; | ||
|
||
export class QRCodePageObject extends PageObject { | ||
private static shareButtonId = 'shareButton'; | ||
|
||
constructor(app: RenderAPI) { | ||
super(app, 'QRCodeScreen'); | ||
} | ||
|
||
private getCloseButton() { | ||
return this.page().find((node) => node.props.testID === QRCodePageObject.shareButtonId); | ||
} | ||
|
||
public async share() { | ||
const shareButton = this.getCloseButton(); | ||
fireEvent.press(shareButton); | ||
return new AmountInputPageObject(this.app); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.