Skip to content

Commit

Permalink
Merge pull request #648 from enshkn/development
Browse files Browse the repository at this point in the history
Main update from Development (react fixes)
  • Loading branch information
hdenizdogan authored Jan 3, 2024
2 parents 161e1ce + fa04ac4 commit b59aab9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
52 changes: 42 additions & 10 deletions dutluk/dutluk_frontend/src/Test_Frontend/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,38 @@ import Profile from '../components/Profile';
jest.mock('axios');

describe('Profile Component', () => {
it('renders the profile component correctly', async () => {
const mockUser = {
username: 'testuser',
biography: 'Test biography',
};
beforeEach(() => {
axios.get.mockReset();

axios.get.mockImplementation((url) => {
if (url.includes('/api/user/isFollowing/')) {
return Promise.resolve({ data: true });
}


if (url.includes('/api/user/')) {
return Promise.resolve({
data: {
username: 'testuser',
biography: 'Test biography',
profilePhoto: 'test_photo_url'
}
});
}

// Mock the Axios requests
axios.get.mockResolvedValueOnce({ data: mockUser }); // Mock user data
axios.get.mockResolvedValueOnce({ data: { message: 'Registered successfully!' } }); // Mock user profile data
if (url.includes('/api/story/fromUserId/')) {
return Promise.resolve({
data: [

]
});
}

return Promise.reject(new Error('not found'));
});
});

it('renders the profile component correctly', async () => {
render(
<MemoryRouter initialEntries={['/profile/123']}>
<Routes>
Expand All @@ -25,7 +47,17 @@ describe('Profile Component', () => {
</MemoryRouter>
);

// Wait for elements to appear in the DOM

await waitFor(() => {
// Verify user information is displayed
expect(screen.getByText('Username: testuser')).toBeInTheDocument();
expect(screen.getByText('Biography: Test biography')).toBeInTheDocument();
expect(screen.getByRole('img', { name: /testuser/i })).toHaveAttribute('src', 'test_photo_url');

// Verify follow/unfollow button text based on follow status
expect(screen.getByText('Unfollow')).toBeInTheDocument();


});
});

});
2 changes: 1 addition & 1 deletion dutluk/dutluk_frontend/src/components/StoryDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function StoryDetails() {
</div>
</div>
<button className="like-button" onClick={handleLikeStory} style={{ backgroundColor: "#ff5500ca", color: "white", border: "none" }} type="submit">
Like
{isLiked ? 'Unlike' : 'Like!'}
</button>
</div>

Expand Down
1 change: 1 addition & 0 deletions dutluk/dutluk_frontend/src/components/TimelineSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ const TimelineSearch = () => {
<button
type="button"
className="btn btn-primary"
style={{ backgroundColor: "#ff5500ca", color: "white", border: "none", margin: "5px" }}
onClick={handleSearch}
>
Search
Expand Down

0 comments on commit b59aab9

Please sign in to comment.