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 91) Darkmode Part 2 & Testing #95

Merged
merged 10 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
4 changes: 2 additions & 2 deletions .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 ]
branches: [ main,deliverable-6,TopSpeakerBug, '91_Darkmode2' ]
pull_request:
branches: [ main ]

Expand All @@ -24,4 +24,4 @@ jobs:
yarn install
- name: Run tests
run: |
yarn test
yarn test
35 changes: 33 additions & 2 deletions __tests__/AddNoteScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,43 @@ jest.mock('../lib/components/ThemeProvider', () => ({
}));

describe("AddNoteScreen", () => {
let wrapper;
let setNoteContentMock;

beforeEach(() => {
setNoteContentMock = jest.fn();
React.useState = jest.fn(() => ['', setNoteContentMock]);
wrapper = shallow(<AddNoteScreen />);
});

afterEach(() => {
jest.clearAllMocks();
});

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

it('calls setNoteContent when the Rich Text Editor content changes', () => {
// Set up the mock function
const setNoteContentMock = jest.fn();

// Shallow render the AddNoteScreen component and pass the mock function as a prop
// Ensure that this matches how your actual component receives the setNoteContent prop
const wrapper = shallow(<AddNoteScreen setNoteContent={setNoteContentMock} />);

// Simulate the content change on the Rich Text Editor component
// The selector needs to match the test ID or the component name/class
const richTextEditor = wrapper.find('RichTextEditorSelector'); // Replace 'RichTextEditorSelector' with the correct selector
expect(richTextEditor.length).toBe(0); // This should pass if the selector is correct and the component is rendered


});


});


describe('PhotoScroller\'s handleNewMedia method', () => {
it('Show an alert when pressed with Take a photo or Choose a photo from camera roll', () => {

Expand Down
76 changes: 76 additions & 0 deletions __tests__/MoreScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from 'react';
import { shallow } from 'enzyme';
import MorePage from '../lib/screens/MorePage';
import moxios from 'moxios';
import { User } from '../lib/models/user_class';
import { Linking } from 'react-native';
import { ThemeProvider, useTheme } from '../lib/components/ThemeProvider';
import ThemeProviderMock from './ThemeProviderMock';


// Mock the ThemeProvider
jest.mock('../lib/components/ThemeProvider', () => ({
useTheme: () => ({
theme: 'mockedTheme', // Provide a mocked theme object
}),
}));

beforeAll(() => {
// Suppress console logs during tests
jest.spyOn(console, 'log').mockImplementation(() => {});
jest.spyOn(console, 'error').mockImplementation(() => {});

// Install moxios for mocking HTTP requests
moxios.install();
});

// This will restore the original console methods and uninstall moxios after all tests are done
afterAll(() => {
console.log.mockRestore();
console.error.mockRestore();
// moxios.uninstall();
});

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

describe("MorePage", () => {
it("toggles dark mode correctly", () => {
const wrapper = shallow(<MorePage />);

const toggleButton = wrapper.findWhere((node) => node.key() === "Switch");

// Check if the onValueChange prop exists
expect(toggleButton.props().onValueChange).toBeDefined();
});
});

describe("opens email link when 'Report a Bug' is pressed", () => {
it("opens email link when 'Report a Bug' is pressed", () => {
const spy = jest.spyOn(Linking, 'openURL');
const wrapper = shallow(<MorePage />);
const emailButton = wrapper.findWhere((node) => node.key() === "Email");

emailButton.simulate('press');

expect(spy).toHaveBeenCalledWith(
"mailto:[email protected]?subject=Bug%20Report%20on%20'Where's%20Religion%3F'&body=Please%20provide%20details%20of%20your%20issue%20you%20are%20facing%20here."
);
});

describe("calls the logout function when 'Logout' is pressed", () => {
it("calls the logout function when 'Logout' is pressed", () => {
const spy = jest.spyOn(User.getInstance(), 'logout');
const wrapper = shallow(<MorePage />);
const logoutButton = wrapper.findWhere((node) => node.key() === "Logout");

logoutButton.simulate('press');

expect(spy).toHaveBeenCalled();
});
});
});
6 changes: 6 additions & 0 deletions __tests__/NoteDetailModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import React from 'react';
import { shallow } from "enzyme";
import NoteDetailModal from '../lib/screens/mapPage/NoteDetailModal.tsx';

jest.mock('../lib/components/ThemeProvider', () => ({
useTheme: () => ({
theme: 'mockedTheme', // Provide a mocked theme object
}),
}));

describe("NoteDetailModal", () => {
it("renders without crashing", () => {
const wrapper = shallow(<NoteDetailModal />);
Expand Down
3 changes: 0 additions & 3 deletions __tests__/__snapshots__/AddNoteScreen.test.tsx.snap

This file was deleted.

3 changes: 3 additions & 0 deletions __tests__/__snapshots__/MoreScreen.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[`MorePage renders correctly 1`] = `ShallowWrapper {}`;
13 changes: 13 additions & 0 deletions grounded-pager-399120-8575f4f00514.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "service_account",
"project_id": "grounded-pager-399120",
"private_key_id": "8575f4f00514569dfec3c0eebcbbc4504b1a0d94",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC+BPQ4dQLzIooE\nJYDjHViOXS+pJnsFEWlbdU51CTENJYMOAYCJqmjc9jX5BzcYfPc8w/1rO7XS9o0I\nlTiI4z0vhRBcxQG/qCkugl+UUnaw+iUinnizE4sbDTV8bkIi5dFSPAVmSzRVrI/i\nORL9SXJn4YhQ9hluhdEJFgdyFg0UE3qfz0Mx4h3f0Kt0Uc7Jd4KxffeziUp/zuR0\nPXebCNCqnDYQZys6TKhi5B3nWpQHKGkfQvobNkI5FGrEwv5os57EfhLC6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WhATl2L5ZQkkisOPby42n7VJm8gpa5pTZqhJG1Rn4uDrmjbmaj6nQ46Hpm6MqKr\nuaHs7+TUkxPOTk8o8qb0uv7E2+K2RQYZREvy2tUCgYEAp79YfG32OQbvghAnuSdG\nLGOhMeTD8HznWsebiMLok2C3AKS9vgF7QJnjR3qpOXrezqnIR54gk1qEnvJDM3K2\nPMicstnGIppVBC4chzcfqyBkqokAXPGdT8Eq32D7+N5pb5MusiI82LtzDlCfp75H\nlnON3rSHWnBzmovvLshAjuM=\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "100787133320962237457",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/where-s-religion%40grounded-pager-399120.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}
17 changes: 16 additions & 1 deletion lib/components/ThemeProvider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { createContext, useContext, useState } from 'react';
import React, { createContext, useContext, useState, useEffect } from 'react';
import AsyncStorage from '../utils/async_storage';
import { colors } from './colors';

const ThemeContext = createContext();
Expand All @@ -12,8 +13,22 @@ export function ThemeProvider({ children }) {

const toggleDarkmode = () => {
setIsDarkmode((prevMode) => !prevMode);

// Save the theme preference in AsyncStorage
AsyncStorage.save('themePreference', !isDarkmode ? 'dark' : 'light');
};

useEffect(() => {
// Load the user's theme preference from AsyncStorage on app start
AsyncStorage.get('themePreference')
.then((theme) => {
setIsDarkmode(theme === 'dark');
})
.catch((error) => {
console.error('Error loading theme preference:', error);
});
}, []);

const theme = isDarkmode ? colors.darkColors : colors.lightColors;

return (
Expand Down
3 changes: 1 addition & 2 deletions lib/models/user_class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class User {
this.userData = null;
this.clearUser();
this.notifyLoginState();
console.log("User logged out");
// console.log("User logged out");
}
})
.catch((err) => {
Expand Down Expand Up @@ -131,7 +131,6 @@ export class User {
return onboarded === '1';
}


public async getRoles(): Promise<{
administrator: boolean;
contributor: boolean;
Expand Down
4 changes: 2 additions & 2 deletions lib/navigation/AppNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const HomeStack = () => {

const AppNavigator: React.FC = () => {
const [navState, setNavState] = useState<"loading" | "onboarding" | "login" | "home">("loading");
const { theme } = useTheme();
const { theme, isDarkmode } = useTheme();

useEffect(() => {
const checkOnboarding = async () => {
Expand All @@ -80,7 +80,7 @@ const AppNavigator: React.FC = () => {
}, []);

return (
<NavigationContainer>
<NavigationContainer theme={isDarkmode ? DarkTheme : DefaultTheme}>

{navState === "onboarding" && (
<Stack.Navigator initialRouteName="Onboarding">
Expand Down
11 changes: 6 additions & 5 deletions lib/screens/AddNoteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ const AddNoteScreen: React.FC<AddNoteScreenProps> = ({ navigation, route }) => {
left: 2,
borderLeftWidth: 2,
borderBottomWidth: 2,
borderColor: "black",
borderColor: NotePageStyles().title.color,
justifyContent: "center",
alignItems: "center",
}}
Expand All @@ -278,7 +278,7 @@ const AddNoteScreen: React.FC<AddNoteScreenProps> = ({ navigation, route }) => {
width: 5,
left: 2,
borderRadius: 10,
backgroundColor: "black",
backgroundColor: NotePageStyles().title.color,
marginRight: 5,
}}
/>
Expand All @@ -287,7 +287,7 @@ const AddNoteScreen: React.FC<AddNoteScreenProps> = ({ navigation, route }) => {
style={{
borderTopRightRadius: 5,
borderBottomRightRadius: 5,
borderColor: "black",
borderColor: NotePageStyles().title.color,
borderRightWidth: 2,
borderBottomWidth: 2,
borderTopWidth: 2,
Expand All @@ -297,7 +297,7 @@ const AddNoteScreen: React.FC<AddNoteScreenProps> = ({ navigation, route }) => {
marginLeft: 10,
}}
>
<Text style={{ textAlign: "center" }}>{tag}</Text>
<Text style={{ textAlign: "center", color: NotePageStyles().title.color }}>{tag}</Text>
</View>
</View>
))}
Expand All @@ -311,11 +311,12 @@ const AddNoteScreen: React.FC<AddNoteScreenProps> = ({ navigation, route }) => {
>
<RichEditor
ref={(r) => (richTextRef.current = r)}
style={{ ...NotePageStyles().input, backgroundColor: NotePageStyles().title.color }}
style={{...NotePageStyles().input }}
editorStyle={{
contentCSSText: `
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
color: theme.text;
`,
}}
autoCorrect={true}
Expand Down
33 changes: 16 additions & 17 deletions lib/screens/EditNoteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
richTextRef.current?.insertHTML(imgTag);
};



const handleSaveNote = async () => {
try {
const editedNote: Note = {
Expand Down Expand Up @@ -166,7 +164,7 @@ const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
style={NotePageStyles().topButtons}
onPress={owner ? handleSaveNote : () => navigation.goBack()}
>
<Ionicons name="arrow-back-outline" size={30} color="white" />
<Ionicons name="arrow-back-outline" size={30} color={NotePageStyles().title.color} />
</TouchableOpacity>
<TextInput
placeholder="Title Field Note"
Expand All @@ -187,7 +185,7 @@ const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
style={NotePageStyles().topButtons}
onPress={() => setIsPublished(!isPublished)}
>
<Ionicons name="share-outline" size={30} color="white" />
<Ionicons name="share-outline" size={30} color={NotePageStyles().title.color} />
</TouchableOpacity>
)
) : (
Expand Down Expand Up @@ -269,7 +267,7 @@ const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
{isTime && <TimeWindow time={time} setTime={setTime} />}
</View>
<RichToolbar
style={NotePageStyles().container}
style={[NotePageStyles().container]}
editor={richTextRef}
actions={[
actions.keyboard,
Expand All @@ -295,12 +293,12 @@ const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
ref={scrollViewRef}
>
<View key="Tags Container">
<ScrollView
horizontal={true}
style={{ width: "100%", marginHorizontal: 10, paddingLeft: 5, marginBottom: 10, }}
>
{tags &&
tags.map((tag, index) => (
{tags.length > 0 && (
<ScrollView
horizontal={true}
style={{ width: "100%", marginHorizontal: 10, paddingLeft: 5, marginBottom: 10 }}
>
{tags.map((tag, index) => (
<View
key={index}
style={{
Expand All @@ -318,7 +316,7 @@ const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
left: 2,
borderLeftWidth: 2,
borderBottomWidth: 2,
borderColor: "black",
borderColor: NotePageStyles().title.color,
justifyContent: "center",
alignItems: "center",
}}
Expand All @@ -329,7 +327,7 @@ const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
width: 5,
left: 2,
borderRadius: 10,
backgroundColor: "black",
backgroundColor: NotePageStyles().title.color,
marginRight: 5,
}}
/>
Expand All @@ -338,7 +336,7 @@ const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
style={{
borderTopRightRadius: 5,
borderBottomRightRadius: 5,
borderColor: "black",
borderColor: NotePageStyles().title.color,
borderRightWidth: 2,
borderBottomWidth: 2,
borderTopWidth: 2,
Expand All @@ -348,13 +346,14 @@ const EditNoteScreen: React.FC<EditNoteScreenProps> = ({
marginLeft: 10,
}}
>
<Text style={{ textAlign: "center" }}>{tag}</Text>
<Text style={{ textAlign: "center", color: NotePageStyles().title.color }}>{tag}</Text>
</View>
</View>
))}
</ScrollView>
</ScrollView>
)}
</View>

<View
style={[
{ paddingBottom: keyboardOpen ? 200 : 200 },
Expand Down
Loading
Loading