Skip to content

Commit

Permalink
chore: fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
whitedogg13 committed Feb 6, 2021
1 parent a4b4a0d commit 4c94b15
Show file tree
Hide file tree
Showing 22 changed files with 1,204 additions and 873 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ coverage/
dist/
lib/
example/
index.d.ts
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = {
extends: ['@react-native-community'],
rules: {
'no-bitwise': 0,
},
};
9 changes: 4 additions & 5 deletions __mocks__/react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ const Platform = {
return _os;
},

setOS: os => {
setOS: (os) => {
_os = os;
}
}
},
};

ReactNative.Platform = Platform;

module.exports = ReactNative;

module.exports = ReactNative;
150 changes: 140 additions & 10 deletions __tests__/ByteParser.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,149 @@
import ByteParser from '../src/ByteParser';

test('parse byteToHexString', () => {
let payload = [104, 116, 116, 112, 115, 58, 47, 47, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 119, 104, 105, 116, 101, 100, 111, 103, 103, 49, 51, 47, 114, 101, 97, 99, 116, 45, 110, 97, 116, 105, 118, 101, 45, 110, 102, 99, 45, 109, 97, 110, 97, 103, 101, 114, 35, 114, 101, 97, 100, 109, 101];
expect(ByteParser.byteToHexString(payload)).toBe("68747470733a2f2f6769746875622e636f6d2f7768697465646f676731332f72656163742d6e61746976652d6e66632d6d616e6167657223726561646d65");
test('parse byteToHexString', () => {
let payload = [
104,
116,
116,
112,
115,
58,
47,
47,
103,
105,
116,
104,
117,
98,
46,
99,
111,
109,
47,
119,
104,
105,
116,
101,
100,
111,
103,
103,
49,
51,
47,
114,
101,
97,
99,
116,
45,
110,
97,
116,
105,
118,
101,
45,
110,
102,
99,
45,
109,
97,
110,
97,
103,
101,
114,
35,
114,
101,
97,
100,
109,
101,
];
expect(ByteParser.byteToHexString(payload)).toBe(
'68747470733a2f2f6769746875622e636f6d2f7768697465646f676731332f72656163742d6e61746976652d6e66632d6d616e6167657223726561646d65',
);
});

test('parse byteToHexString should return empty', () => {
expect(ByteParser.byteToHexString({something: "wrong"})).toBe("");
test('parse byteToHexString should return empty', () => {
expect(ByteParser.byteToHexString({something: 'wrong'})).toBe('');
});

test('parse byteToString', () => {
let payload = [104, 116, 116, 112, 115, 58, 47, 47, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 119, 104, 105, 116, 101, 100, 111, 103, 103, 49, 51, 47, 114, 101, 97, 99, 116, 45, 110, 97, 116, 105, 118, 101, 45, 110, 102, 99, 45, 109, 97, 110, 97, 103, 101, 114, 35, 114, 101, 97, 100, 109, 101];
expect(ByteParser.byteToString(payload)).toBe("https://github.com/whitedogg13/react-native-nfc-manager#readme");
test('parse byteToString', () => {
let payload = [
104,
116,
116,
112,
115,
58,
47,
47,
103,
105,
116,
104,
117,
98,
46,
99,
111,
109,
47,
119,
104,
105,
116,
101,
100,
111,
103,
103,
49,
51,
47,
114,
101,
97,
99,
116,
45,
110,
97,
116,
105,
118,
101,
45,
110,
102,
99,
45,
109,
97,
110,
97,
103,
101,
114,
35,
114,
101,
97,
100,
109,
101,
];
expect(ByteParser.byteToString(payload)).toBe(
'https://github.com/whitedogg13/react-native-nfc-manager#readme',
);
});

test('parse byteToString should return empty', () => {
expect(ByteParser.byteToString({something: "wrong"})).toBe("");
test('parse byteToString should return empty', () => {
expect(ByteParser.byteToString({something: 'wrong'})).toBe('');
});
29 changes: 20 additions & 9 deletions __tests__/NdefParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@ test('parse RTD_TEXT', () => {
tnf: 1,
type: RTD_TEXT_TYPE,
payload: [
0x02, 0x65, 0x6e, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
]
0x02,
0x65,
0x6e,
0x68,
0x65,
0x6c,
0x6c,
0x6f,
0x2c,
0x20,
0x77,
0x6f,
0x72,
0x6c,
0x64,
0x21,
],
};

let result = NdefParser.parseText(record);
let answer = "hello, world!";
let answer = 'hello, world!';

expect(result).toBe(answer);
});
Expand All @@ -22,14 +36,11 @@ test('parse RTD_URI', () => {
let record = {
tnf: 1,
type: RTD_URI_TYPE,
payload: [
0x01, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
0x63, 0x6f, 0x6d,
]
payload: [0x01, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d],
};

let {uri: result} = NdefParser.parseUri(record);
let answer = "http://www.google.com";
let answer = 'http://www.google.com';

expect(result).toBe(answer);
});
18 changes: 8 additions & 10 deletions __tests__/NfcManager.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
jest.mock('../src/NativeNfcManager');

import {
Platform
} from 'react-native'
import {NativeNfcManager, NfcManagerEmitter, callNative} from '../src/NativeNfcManager'
import {Platform} from 'react-native';
import {NfcManagerEmitter, callNative} from '../src/NativeNfcManager';

describe('NfcManager (ios)', () => {
Platform.setOS('ios');
const NfcManagerModule = require('../src/index.js');
const NfcManager = NfcManagerModule.default;
const {NfcEvents} = NfcManagerModule;
const lastNativeCall = () => callNative.mock.calls[callNative.mock.calls.length - 1];
const lastNativeCall = () =>
callNative.mock.calls[callNative.mock.calls.length - 1];

test('constructor', () => {
expect(Platform.OS).toBe('ios');
Expand All @@ -30,7 +29,7 @@ describe('NfcManager (ios)', () => {

if (!hit) {
// this native event is not registered, treat as error
exect(true).toBe(false);
expect(true).toBe(false);
}
}
});
Expand Down Expand Up @@ -66,16 +65,16 @@ describe('NfcManager (ios)', () => {
expect(true).toBe(true);
}

// can receive DiscoverTag event
// can receive DiscoverTag event
const tag1 = {id: '3939889'};
let tag2 = null;
NfcManager.setEventListener(NfcEvents.DiscoverTag, tag => {
NfcManager.setEventListener(NfcEvents.DiscoverTag, (tag) => {
tag2 = tag;
});
NfcManagerEmitter._testTriggerCallback(NfcEvents.DiscoverTag, tag1);
expect(tag2).toEqual(tag1);

// can receive SessionClosed event
// can receive SessionClosed event
let sessionClosed = false;
NfcManager.setEventListener(NfcEvents.SessionClosed, () => {
sessionClosed = true;
Expand All @@ -92,5 +91,4 @@ describe('NfcManager (ios)', () => {
expect(options.alertMessage).toEqual('Please tap NFC tags');
expect(options.invalidateAfterFirstRead).toBe(false);
});

});
Loading

0 comments on commit 4c94b15

Please sign in to comment.