Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP 93)Test Case of Time function #94

Merged
merged 4 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]

Expand Down
58 changes: 58 additions & 0 deletions __tests__/AddTagg.test.tsx
Original file line number Diff line number Diff line change
@@ -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(<TagWindow tags={mockTags} setTags={mockSetTags} />);
expect(wrapper).toMatchSnapshot();
});

it('displays input field and tags list', () => {
const wrapper = shallow(<TagWindow tags={mockTags} setTags={mockSetTags} />);
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(<TagWindow tags={mockTags} setTags={mockSetTags} />);
const swipeListView = wrapper.find('SwipeListView');
swipeListView.props().onRightAction('0', {});
expect(mockSetTags).toHaveBeenCalledWith(['2','3']);
});
});

62 changes: 62 additions & 0 deletions __tests__/SetTime.test.tsx
Original file line number Diff line number Diff line change
@@ -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) => <View testID={props.testID} />;
});


describe("AddNoteScreen", () => {
it("renders without crashing", () => {
const wrapper = shallow(<AddNoteScreen />);
expect(wrapper).toMatchSnapshot();
});
});


describe('LocationWindow', () => {
it('renders without crashing', () => {
const wrapper = shallow(<LocationWindow time={new Date()} setTime={() => {}} />);
expect(wrapper).toMatchSnapshot();
});

it('displays the "Select Date & Time" button when not in edit mode, and set the current time ', () => {
const wrapper = shallow(<LocationWindow time={new Date()} setTime={() => {}} />);
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(<LocationWindow time={new Date()} setTime={() => {}} showPicker={true} />);
const saveButton = wrapper.find(Button);
expect(saveButton.exists()).toBe(true);
});
});
3 changes: 3 additions & 0 deletions __tests__/__snapshots__/AddTagg.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TagWindowTest1 renders without crashing 1`] = `ShallowWrapper {}`;
5 changes: 5 additions & 0 deletions __tests__/__snapshots__/SetTime.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -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 {}`;
1 change: 1 addition & 0 deletions lib/components/tagging.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function TagWindow({
<View key={data.item.key} style={styles.rowBack}>
<TouchableOpacity
onPress={() => handleDeleteTag(data.item.key.toString(), rowMap)}
testID={`delete-action-${data.item.key}`}
>
<Ionicons
name="trash-outline"
Expand Down
Loading