-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from conorheffron/rl6
Major release v6.0.1
- Loading branch information
Showing
31 changed files
with
5,669 additions
and
3,000 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,97 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import Home from './components/Home'; | ||
import axios from 'axios'; | ||
import App from './App'; | ||
import CoffeeCarousel from './components/CoffeeCarousel'; | ||
import CoffeeHome from './components/CoffeeHome'; | ||
import NotFound from './components/NotFound'; | ||
|
||
// Mocking axios | ||
jest.mock('axios'); | ||
|
||
test('renders learn react link', () => { | ||
render(<Home />); | ||
const element = screen.getByText(/Home/i); | ||
expect(element).toBeInTheDocument(); | ||
}); | ||
|
||
// Sample data for testing | ||
const coffeeItems = [ | ||
{ | ||
title: 'Espresso', | ||
ingredients: ['Water', 'Coffee beans'], | ||
image: 'https://example.com/espresso.jpg', | ||
}, | ||
{ | ||
title: 'Cappuccino', | ||
ingredients: ['Espresso', 'Steamed milk', 'Foam milk'], | ||
image: 'https://example.com/cappuccino.jpg', | ||
}, | ||
]; | ||
|
||
describe('CoffeeCarousel', () => { | ||
test('renders carousel with coffee items', () => { | ||
render(<CoffeeCarousel items={coffeeItems} />); | ||
|
||
// Check that the carousel items are rendered | ||
coffeeItems.forEach((item) => { | ||
expect(screen.getByText(item.title)).toBeInTheDocument(); | ||
expect(screen.getByAltText(item.title)).toBeInTheDocument(); | ||
expect(screen.getByText(item.ingredients.join(', '))).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('renders carousel with correct number of items', () => { | ||
render(<CoffeeCarousel items={coffeeItems} />); | ||
|
||
// Check that the correct number of carousel items are rendered | ||
const carouselItems = screen.getAllByRole('img'); | ||
|
||
expect(carouselItems.length).toBe(coffeeItems.length); | ||
}); | ||
}); | ||
|
||
describe('CoffeeHome', () => { | ||
beforeEach(() => { | ||
axios.get.mockResolvedValue({ data: coffeeItems }); | ||
}); | ||
|
||
test('renders AppNavbar component', () => { | ||
render(<App />); | ||
expect(screen.getByRole('banner')).toBeInTheDocument(); | ||
}); | ||
|
||
test('displays loading state initially', () => { | ||
render(<CoffeeHome />); | ||
expect(screen.getByText('Loading...')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders CoffeeCarousel component with coffee items', async () => { | ||
render(<CoffeeHome />); | ||
|
||
// Wait for the coffee items to be fetched and rendered | ||
await waitFor(() => { | ||
expect(screen.getByText('Espresso')).toBeInTheDocument(); | ||
expect(screen.getByText('Cappuccino')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('NotFound', () => { | ||
test('renders AppNavbar component', () => { | ||
render(<NotFound />); | ||
expect(screen.getByRole('banner')).toBeInTheDocument(); | ||
}); | ||
|
||
test('displays 404 error message', () => { | ||
render(<NotFound />); | ||
expect(screen.getByText('404 - Page Not Found')).toBeInTheDocument(); | ||
}); | ||
|
||
test('displays the apology message', () => { | ||
render(<NotFound />); | ||
expect(screen.getByText('Sorry, the page you are looking for could not be found.')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import { Carousel } from 'react-bootstrap'; | ||
import '.././App.css'; | ||
|
||
const CoffeeCarousel = ({ items }) => { | ||
return ( | ||
<Carousel className="App-header"> | ||
{items.map((item, index) => ( | ||
<Carousel.Item key={index}> | ||
<img src={item.image} alt={item.title}/> | ||
<Carousel.Caption> | ||
<h3>{item.title}</h3> | ||
<h5>{item.ingredients.join(', ')}</h5> | ||
</Carousel.Caption> | ||
</Carousel.Item> | ||
))} | ||
</Carousel> | ||
); | ||
}; | ||
|
||
export default CoffeeCarousel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { Button, Container, InputGroup, Table } from 'reactstrap'; | ||
import axios from 'axios'; | ||
import AppNavbar from '.././AppNavbar'; | ||
import CoffeeCarousel from './CoffeeCarousel'; | ||
import Footer from '.././Footer'; | ||
|
||
function CoffeeHome() { | ||
const [coffeeItems, setCoffeeItems] = useState([]); | ||
|
||
useEffect(() => { | ||
axios.get('/coffees') | ||
.then(response => setCoffeeItems(response.data)) | ||
.catch(error => console.error('Error fetching coffee details:', error)); | ||
}, []); | ||
|
||
return ( | ||
<div className="App"> | ||
<AppNavbar/> | ||
<Container> | ||
<h1>Coffee Carousel</h1> | ||
{coffeeItems.length > 0 ? ( | ||
<CoffeeCarousel items={coffeeItems} /> | ||
) : ( | ||
<div>Loading...</div> | ||
)} | ||
</Container> | ||
<Footer/> | ||
</div> | ||
); | ||
} | ||
|
||
export default CoffeeHome; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.