From f7f76bba2ee8f9494753403d017f1a43da7ee523 Mon Sep 17 00:00:00 2001 From: Tianhao Wang Date: Mon, 30 Oct 2023 13:04:45 -0500 Subject: [PATCH 1/3] TimeTestAdd --- __tests__/SetTime.test.tsx | 62 +++++++++++++++++++ __tests__/__snapshots__/SetTime.test.tsx.snap | 5 ++ 2 files changed, 67 insertions(+) create mode 100644 __tests__/SetTime.test.tsx create mode 100644 __tests__/__snapshots__/SetTime.test.tsx.snap diff --git a/__tests__/SetTime.test.tsx b/__tests__/SetTime.test.tsx new file mode 100644 index 0000000..ab5e092 --- /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', () => { + const wrapper = shallow( {}} />); + const selectButton = wrapper.find(Button); + expect(selectButton.prop('title')).toBe('Select Date & Time'); + }); + + it('does not display the "Save" button when in edit mode', () => { + 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__/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 {}`; From f2eee308e423405b50257b319ccdcded7c11d468 Mon Sep 17 00:00:00 2001 From: Tianhao Wang Date: Sun, 5 Nov 2023 23:59:45 -0600 Subject: [PATCH 2/3] display check --- .github/workflows/Native.yml | 2 +- __tests__/AddTagg.test.tsx | 63 +++++++++++++++++++ __tests__/SetTime.test.tsx | 4 +- __tests__/__snapshots__/AddTagg.test.tsx.snap | 11 ++++ lib/components/tagging.tsx | 1 + 5 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 __tests__/AddTagg.test.tsx create mode 100644 __tests__/__snapshots__/AddTagg.test.tsx.snap diff --git a/.github/workflows/Native.yml b/.github/workflows/Native.yml index 3777fe2..c482f3e 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 ] + branches: [ main,SetTimeTest ] pull_request: branches: [ main ] diff --git a/__tests__/AddTagg.test.tsx b/__tests__/AddTagg.test.tsx new file mode 100644 index 0000000..d009551 --- /dev/null +++ b/__tests__/AddTagg.test.tsx @@ -0,0 +1,63 @@ +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('renders without crashing', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); + + 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 index ab5e092..d8e161e 100644 --- a/__tests__/SetTime.test.tsx +++ b/__tests__/SetTime.test.tsx @@ -48,13 +48,13 @@ beforeAll(() => { expect(wrapper).toMatchSnapshot(); }); - it('displays the "Select Date & Time" button when not in edit mode', () => { + 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('does not display the "Save" button when in edit mode', () => { + 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); diff --git a/__tests__/__snapshots__/AddTagg.test.tsx.snap b/__tests__/__snapshots__/AddTagg.test.tsx.snap new file mode 100644 index 0000000..e797233 --- /dev/null +++ b/__tests__/__snapshots__/AddTagg.test.tsx.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AddNoteScreen renders without crashing 1`] = `ShallowWrapper {}`; + +exports[`LocationWindow renders without crashing 1`] = `ShallowWrapper {}`; + +exports[`TagWindow renders without crashing 1`] = `ShallowWrapper {}`; + +exports[`TagWindowTest1 renders without crashing 1`] = `ShallowWrapper {}`; + +exports[`TagWindowTest2 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}`} > Date: Mon, 6 Nov 2023 00:08:10 -0600 Subject: [PATCH 3/3] delate index check --- __tests__/AddTagg.test.tsx | 5 ----- __tests__/__snapshots__/AddTagg.test.tsx.snap | 8 -------- 2 files changed, 13 deletions(-) diff --git a/__tests__/AddTagg.test.tsx b/__tests__/AddTagg.test.tsx index d009551..8d15e9d 100644 --- a/__tests__/AddTagg.test.tsx +++ b/__tests__/AddTagg.test.tsx @@ -47,11 +47,6 @@ describe('TagWindowTest1', () => { describe('TagWindowTest2', () => { const mockTags = ['1', '2','3']; const mockSetTags = jest.fn(); - - it('renders without crashing', () => { - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - }); it('handles tag deletion when swiping', () => { const wrapper = shallow(); diff --git a/__tests__/__snapshots__/AddTagg.test.tsx.snap b/__tests__/__snapshots__/AddTagg.test.tsx.snap index e797233..dd44b94 100644 --- a/__tests__/__snapshots__/AddTagg.test.tsx.snap +++ b/__tests__/__snapshots__/AddTagg.test.tsx.snap @@ -1,11 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AddNoteScreen renders without crashing 1`] = `ShallowWrapper {}`; - -exports[`LocationWindow renders without crashing 1`] = `ShallowWrapper {}`; - -exports[`TagWindow renders without crashing 1`] = `ShallowWrapper {}`; - exports[`TagWindowTest1 renders without crashing 1`] = `ShallowWrapper {}`; - -exports[`TagWindowTest2 renders without crashing 1`] = `ShallowWrapper {}`;