diff --git a/.github/workflows/Native.yml b/.github/workflows/Native.yml index 7d90614..7fc5768 100644 --- a/.github/workflows/Native.yml +++ b/.github/workflows/Native.yml @@ -2,7 +2,7 @@ name: App test on: push: - branches: [ main,deliverable-6,TopSpeakerBug, '91_Darkmode2' ] + branches: [ main,deliverable-6,TopSpeakerBug, 91_Darkmode2, SetTimeTest ] pull_request: branches: [ main ] diff --git a/__tests__/AddTagg.test.tsx b/__tests__/AddTagg.test.tsx new file mode 100644 index 0000000..8d15e9d --- /dev/null +++ b/__tests__/AddTagg.test.tsx @@ -0,0 +1,58 @@ +import Enzyme, { shallow } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; +import React from 'react'; +import TagWindow from '../lib/components/tagging'; +import moxios from 'moxios'; + + +Enzyme.configure({ adapter: new Adapter() }); + + +beforeAll(() => { + jest.spyOn(console, 'log').mockImplementation(() => {}); + jest.spyOn(console, 'error').mockImplementation(() => {}); + moxios.install(); + }); + + afterAll(() => { + console.log.mockRestore(); + console.error.mockRestore(); + moxios.uninstall(); + }); + + jest.mock('../lib/components/ThemeProvider', () => ({ + useTheme: () => ({ + theme: 'mockedTheme', + }), + })); + +describe('TagWindowTest1', () => { + const mockTags = ['Tag1', 'Tag2', 'Tag3']; + const mockSetTags = jest.fn(); + + it('renders without crashing', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); + + it('displays input field and tags list', () => { + const wrapper = shallow(); + expect(wrapper.find('TextInput').exists()).toBe(true); + expect(wrapper.find('SwipeListView').exists()).toBe(true); + }); + +}); + + +describe('TagWindowTest2', () => { + const mockTags = ['1', '2','3']; + const mockSetTags = jest.fn(); + + it('handles tag deletion when swiping', () => { + const wrapper = shallow(); + const swipeListView = wrapper.find('SwipeListView'); + swipeListView.props().onRightAction('0', {}); + expect(mockSetTags).toHaveBeenCalledWith(['2','3']); + }); + }); + \ No newline at end of file diff --git a/__tests__/SetTime.test.tsx b/__tests__/SetTime.test.tsx new file mode 100644 index 0000000..d8e161e --- /dev/null +++ b/__tests__/SetTime.test.tsx @@ -0,0 +1,62 @@ +import Enzyme, { shallow } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; + +Enzyme.configure({ adapter: new Adapter() }); + +import React from 'react'; +import { Button } from 'react-native'; +import AddNoteScreen from '../lib/screens/AddNoteScreen'; +import moxios from 'moxios'; +import LocationWindow from "../lib/components/time"; + + +beforeAll(() => { + jest.spyOn(console, 'log').mockImplementation(() => {}); + jest.spyOn(console, 'error').mockImplementation(() => {}); + moxios.install(); + }); + + afterAll(() => { + console.log.mockRestore(); + console.error.mockRestore(); + moxios.uninstall(); + }); + + jest.mock('../lib/components/ThemeProvider', () => ({ + useTheme: () => ({ + theme: 'mockedTheme', + }), + })); + + jest.mock("@react-native-community/datetimepicker", () => { + const { View } = require("react-native"); + return (props) => ; + }); + + + describe("AddNoteScreen", () => { + it("renders without crashing", () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); + }); + + + describe('LocationWindow', () => { + it('renders without crashing', () => { + const wrapper = shallow( {}} />); + expect(wrapper).toMatchSnapshot(); + }); + + it('displays the "Select Date & Time" button when not in edit mode, and set the current time ', () => { + const wrapper = shallow( {}} />); + const selectButton = wrapper.find(Button); + expect(selectButton.prop('title')).toBe('Select Date & Time'); + }); + + it('display the "Save" button when in edit mode, and current time saved', () => { + const wrapper = shallow( {}} showPicker={true} />); + const saveButton = wrapper.find(Button); + expect(saveButton.exists()).toBe(true); + }); + }); \ No newline at end of file diff --git a/__tests__/__snapshots__/AddTagg.test.tsx.snap b/__tests__/__snapshots__/AddTagg.test.tsx.snap new file mode 100644 index 0000000..dd44b94 --- /dev/null +++ b/__tests__/__snapshots__/AddTagg.test.tsx.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TagWindowTest1 renders without crashing 1`] = `ShallowWrapper {}`; diff --git a/__tests__/__snapshots__/SetTime.test.tsx.snap b/__tests__/__snapshots__/SetTime.test.tsx.snap new file mode 100644 index 0000000..8a45973 --- /dev/null +++ b/__tests__/__snapshots__/SetTime.test.tsx.snap @@ -0,0 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AddNoteScreen renders without crashing 1`] = `ShallowWrapper {}`; + +exports[`LocationWindow renders without crashing 1`] = `ShallowWrapper {}`; diff --git a/lib/components/tagging.tsx b/lib/components/tagging.tsx index f1b1120..b529877 100644 --- a/lib/components/tagging.tsx +++ b/lib/components/tagging.tsx @@ -40,6 +40,7 @@ function TagWindow({ handleDeleteTag(data.item.key.toString(), rowMap)} + testID={`delete-action-${data.item.key}`} >