Skip to content

Commit

Permalink
Merge branch 'main' into nikhil
Browse files Browse the repository at this point in the history
  • Loading branch information
yashb196 authored Sep 18, 2024
2 parents a04b36b + e1e3eea commit 1c0a394
Show file tree
Hide file tree
Showing 45 changed files with 5,502 additions and 2,237 deletions.
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,onboarding_change ]
branches: [ main,Home-screen-navigation-issue ]
pull_request:
branches: [ main ]

Expand All @@ -24,4 +24,4 @@ jobs:
yarn install
- name: Run tests
run: |
yarn test
yarn test -u
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ npm-debug.*
web-build/
eas.json
grounded-pager-399120-8575f4f00514.json
grounded-*

.env

# macOS
.DS_Store
yarn.lock
12 changes: 8 additions & 4 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import AppNavigator from './lib/navigation/AppNavigator';
import { LogBox } from 'react-native';
import { ThemeProvider } from './lib/components/ThemeProvider';
import Toast from 'react-native-toast-message';
import { Provider } from 'react-redux';
import { store } from './redux/store/store';

LogBox.ignoreAllLogs();

export default function App() {
return (
<ThemeProvider>
<AppNavigator/>
<Toast/>
</ThemeProvider>
<Provider store={store}>
<ThemeProvider>
<AppNavigator />
<Toast />
</ThemeProvider>
</Provider>
);
}
179 changes: 44 additions & 135 deletions __tests__/AddNoteRichEditor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,196 +1,105 @@
import Enzyme, { shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });

import React, { SetStateAction, useState } from 'react';
import { TouchableOpacity, Alert } from 'react-native';
import { render } from '@testing-library/react';

import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react-native';
import AddNoteScreen from '../lib/screens/AddNoteScreen';
import { ThemeProvider } from '../lib/components/ThemeProvider';
import PhotoScroller from "../lib/components/photoScroller";
import { Media } from '../lib/models/media_class';
import moxios from 'moxios';
import AudioContainer from '../lib/components/audio';

import { addVideoToEditor } from '../lib/screens/AddNoteScreen';
import { getThumbnail } from '../lib/utils/S3_proxy';
// Mocking external dependencies and components
jest.mock('../lib/components/ThemeProvider', () => ({
useTheme: () => ({
theme: 'mockedTheme', // Provide a mocked theme object
}),
}));

beforeEach(() => {
// Clear mocks before each test
jest.clearAllMocks();

beforeAll(() => {
jest.spyOn(console, 'log').mockImplementation(() => {});
jest.spyOn(console, 'error').mockImplementation(() => {});
jest.spyOn(console, 'warn').mockImplementation(() => {});
jest.spyOn(console, 'warn').mockImplementation((message) => {
if (!message.includes('Toolbar has no editor')) {
console.warn(message);
}
});
moxios.install();
});

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

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

/*
jest.mock('../lib/screens/AddNoteScreen', () => ({
addVideoToEditor: jest.fn(),
}));
// Ensure you also mock getThumbnail if it's from another module
jest.mock('../lib/utils/S3_proxy', () => ({
getThumbnail: jest.fn(),
}));
*/
});

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

beforeEach(() => {
setNoteContentMock = jest.fn();
React.useState = jest.fn(() => ['', setNoteContentMock]);
const routeMock = {
params: {
untitledNumber: 1
}
};
wrapper = shallow(<AddNoteScreen route={routeMock} />);
});

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

it("renders without crashing", () => {
expect(wrapper.exists()).toBeTruthy();
render(<AddNoteScreen route={{ params: { untitledNumber: 1 }}} />);
// Instead of using toBeInTheDocument (which is DOM-specific), use toBeTruthy
expect(screen.getByTestId('RichEditor')).toBeTruthy();
});

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

// 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 route={routeMock} 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('[data-testid="RichEditor"]'); // Replace 'RichTextEditorSelector' with the correct selector
expect(richTextEditor.length).toBe(1); // This should pass if the selector is correct and the component is rendered

const RichToolbar = wrapper.find('[data-testid="RichBar"]'); // Replace 'RichTextEditorSelector' with the correct selector
expect(RichToolbar.length).toBe(1); // This should pass if the selector is correct and the component is rendered
render(<AddNoteScreen route={{ params: { untitledNumber: 1 }}} />);

const richTextEditor = screen.getByTestId('RichEditor'); // Ensure the element is rendered
const newText = 'New content';


// Simulating the text change in the editor
fireEvent.changeText(richTextEditor, newText);

const richTextRef = { current: { insertText: jest.fn() } };

//mock of onChange
const addTextToEditor = (Text: string) => {
const addTextToEditor = (Text) => {
richTextRef.current?.insertText(Text);
};


addTextToEditor(newText);

expect(richTextRef.current.insertText).toHaveBeenCalledWith(newText);


});

it('Modifies the given text with the bold tag', () => {


//mock of Bold
const mockBold = (text: string) => {
return `<b>${text}</b>`;
};

const mockBold = (text) => `<b>${text}</b>`;
const newText = 'New content';
const newTextBold = mockBold(newText);

const richTextRef = { current: { insertText: jest.fn() } };

//mock of onChange
const addTextToEditor = (Text: string) => {

const addTextToEditor = (Text) => {
const boldText = mockBold(Text);
richTextRef.current?.insertText(boldText);
};

addTextToEditor(newText);

expect(richTextRef.current.insertText).toHaveBeenCalledWith(`<b>${newText}</b>`);
});

/* needs to get fixed
it('Adds a key to the rich text editor when a key is pressed', () => {
const wrapper = shallow(<AddNoteScreen />);
const richTextEditor = wrapper.find('[data-testid="RichEditor"]').find('onChange');
// Simulate a change event with the pressed key
richTextEditor.prop('onChange')('a'); // Assuming onChange prop takes the new content as argument
// Access the noteContent state
const [noteContent, setNoteContent] = wrapper.find(React.useState).first().props();
// Verify that the key is added to the rich text editor
expect(noteContent).toContain('a');
expect(richTextRef.current.insertText).toHaveBeenCalledWith(newTextBold);
});
*/

/*
it("inserts video into the rich text editor", async () => {
const mockVideoUri = 'http://example.com/video.mp4';
const mockThumbnailUri = 'http://example.com/thumbnail.jpg';
// Set up your mocks with the desired behavior
getThumbnail.mockResolvedValue(mockThumbnailUri);
addVideoToEditor.mockImplementation(() => Promise.resolve()); // Assume it's async
// Assuming mockInsertHTML is a function you have access to, perhaps via global mocks
const mockInsertHTML = jest.fn();
global.richTextRef = {
current: {
insertHTML: mockInsertHTML,
},
};
// Act: Attempt to add video to editor
addVideoToEditor(mockVideoUri);
// Assertions
expect(getThumbnail).toHaveBeenCalledWith(mockVideoUri);
expect(addVideoToEditor).toHaveBeenCalledWith(mockVideoUri);
expect(mockInsertHTML).toHaveBeenCalled(); // This assumes insertHTML is called within addVideoToEditor
}); */

it('inserts video into the rich text editor', () => {
// Example video URI
const videoUri = 'http://example.com/video.mp4';

const richTextRef = { current: { insertHTML: jest.fn() } };

const insertVideoToEditor = (videoUri: string) => {
// Example: Inserting a video might involve wrapping the URI in a video tag
const insertVideoToEditor = (videoUri) => {
const videoHtml = `<video src="${videoUri}" controls></video>`;
richTextRef.current?.insertHTML(videoHtml);
};
};

// Call the function to insert the video
insertVideoToEditor(videoUri);

// Verify insertHTML was called with the correct HTML for the video
const expectedVideoHtml = `<video src="${videoUri}" controls></video>`;
expect(richTextRef.current.insertHTML).toHaveBeenCalledWith(expectedVideoHtml);

expect(richTextRef.current.insertHTML).toHaveBeenCalledWith(`<video src="${videoUri}" controls></video>`);
});
});
});
Loading

0 comments on commit 1c0a394

Please sign in to comment.