BlueWallet/tests/integration/App.test.js

66 lines
1.8 KiB
JavaScript
Raw Normal View History

import assert from 'assert';
2018-03-18 16:15:10 +01:00
import React from 'react';
2018-09-16 01:52:58 +02:00
import TestRenderer from 'react-test-renderer';
2019-06-08 14:57:44 +02:00
import Settings from '../../screen/settings/settings';
import Selftest from '../../screen/selftest';
import { BlueHeader } from '../../BlueComponents';
import * as BlueElectrum from '../../blue_modules/BlueElectrum';
2019-02-14 06:15:56 +01:00
jest.mock('react-native-qrcode-svg', () => 'Video');
2019-07-21 18:40:25 +02:00
jest.mock('amplitude-js', () => ({
getInstance: function () {
2019-07-21 18:40:25 +02:00
return {
init: jest.fn(),
logEvent: jest.fn(),
};
},
}));
beforeAll(async () => {
// awaiting for Electrum to be connected. For RN Electrum would naturally connect
// while app starts up, but for tests we need to wait for it
await BlueElectrum.waitTillConnected();
jest.useFakeTimers();
});
afterAll(() => {
jest.useRealTimers();
// after all tests we close socket so the test suite can actually terminate
BlueElectrum.forceDisconnect();
});
2018-03-18 16:15:10 +01:00
it('BlueHeader works', () => {
2018-09-16 01:52:58 +02:00
const rendered = TestRenderer.create(<BlueHeader />).toJSON();
2018-03-18 16:15:10 +01:00
expect(rendered).toBeTruthy();
});
2019-03-31 03:15:02 +02:00
it.skip('Settings work', () => {
2018-09-16 01:52:58 +02:00
const rendered = TestRenderer.create(<Settings />).toJSON();
2018-03-18 16:15:10 +01:00
expect(rendered).toBeTruthy();
});
2018-03-24 21:12:59 +01:00
it('Selftest work', () => {
2018-09-16 01:52:58 +02:00
const component = TestRenderer.create(<Selftest />);
2018-03-24 21:12:59 +01:00
const root = component.root;
const rendered = component.toJSON();
expect(rendered).toBeTruthy();
// console.log((root.findAllByType('Text')[0].props));
let okFound = false;
const allTests = [];
for (const v of root.findAllByType('Text')) {
2018-03-24 21:12:59 +01:00
let text = v.props.children;
if (text.join) {
text = text.join('');
}
if (text === 'OK') {
okFound = true;
}
allTests.push(text);
// console.log(text);
}
assert.ok(okFound, 'OK not found. Got: ' + allTests.join('; '));
});