From 228f71c4b0aa3c79a0a512e5fcd89f03fa7bd07b Mon Sep 17 00:00:00 2001 From: Robert Boghian Date: Mon, 5 Sep 2022 19:44:48 +0300 Subject: [PATCH] add tests --- README.md | 4 +++- __tests__/buildOptionsList.test.js | 34 ++++++++++++++++++++++++++++++ __tests__/getDeviceInfo.test.js | 9 ++++++++ src/getDeviceInfo.js | 3 --- 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 __tests__/buildOptionsList.test.js create mode 100644 __tests__/getDeviceInfo.test.js diff --git a/README.md b/README.md index 4b4d93f..260d9bd 100644 --- a/README.md +++ b/README.md @@ -40,13 +40,15 @@ const extraMenuOptions = [{ const reportIssue = (deviceInfo) => { // your code here -} +}; +return ( reportIssue(deviceInfo)} /> +); ``` ### Props diff --git a/__tests__/buildOptionsList.test.js b/__tests__/buildOptionsList.test.js new file mode 100644 index 0000000..15481da --- /dev/null +++ b/__tests__/buildOptionsList.test.js @@ -0,0 +1,34 @@ +import { buildOptionsList } from "../src/buildOptionsList"; +import Icon from "react-native-vector-icons/AntDesign"; + +describe("getting the list of options", () => { + + it("should return default length", () => { + const options = buildOptionsList(); + + expect(options.length).toBe(2); + }); + + it("should return correct length", () => { + const handleAction = () => { + console.log("warning"); + }; + + const items = [{ + icon: , + title: "Report a problem", + action: handleAction, + }]; + + const options = buildOptionsList(items); + + expect(options.length).toBe(3); + }); + + it("should return a list", () => { + const options = buildOptionsList(); + + expect(typeof options).toBe("array"); + }); +}); + diff --git a/__tests__/getDeviceInfo.test.js b/__tests__/getDeviceInfo.test.js new file mode 100644 index 0000000..1bb2253 --- /dev/null +++ b/__tests__/getDeviceInfo.test.js @@ -0,0 +1,9 @@ +import getDeviceInfo from "../src/getDeviceInfo"; + +describe("getting the device information", () => { + it('should return an object', () => { + const device = getDeviceInfo(); + + expect(typeof device).toBe('object'); + }) +}) diff --git a/src/getDeviceInfo.js b/src/getDeviceInfo.js index f20a0ca..47f13b4 100644 --- a/src/getDeviceInfo.js +++ b/src/getDeviceInfo.js @@ -1,10 +1,8 @@ import React from "react"; -import { useRoute } from '@react-navigation/native'; import DeviceInfo from "react-native-device-info"; const getDeviceInfo = () => { const device = {}; - const route = useRoute(); device.uniqueId = DeviceInfo.getUniqueId(); device.deviceId = DeviceInfo.getDeviceId(); @@ -15,7 +13,6 @@ const getDeviceInfo = () => { device.systemVersion = DeviceInfo.getSystemVersion(); device.isTablet = DeviceInfo.isTablet(); device.appName = DeviceInfo.getApplicationName(); - device.routeName = route.name; return device; }