2021-08-04 22:23:57 +02:00
|
|
|
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';
|
2021-08-04 22:23:57 +02:00
|
|
|
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', () => ({
|
2020-06-01 14:54:23 +02:00
|
|
|
getInstance: function () {
|
2019-07-21 18:40:25 +02:00
|
|
|
return {
|
|
|
|
init: jest.fn(),
|
|
|
|
logEvent: jest.fn(),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2021-08-04 22:23:57 +02:00
|
|
|
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;
|
2020-06-01 14:54:23 +02:00
|
|
|
const allTests = [];
|
2021-05-08 08:41:45 +02:00
|
|
|
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('; '));
|
|
|
|
});
|