Skip to content

Commit b3e1232

Browse files
authored
Merge pull request #137 from cladams0203/Example-Test-Object
Example Episode Test Object
2 parents 50c8359 + 330288c commit b3e1232

File tree

2 files changed

+62
-33
lines changed

2 files changed

+62
-33
lines changed

README.md

+37-26
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,77 @@
33
This module explored passing props into test components, rerendering components and using mocks to both monitor functional props and override the functionality of external modules. In this project, you will practice each of these practices in the testing of an application that displays TV show data.
44

55
## Objectives
6+
67
- Understand how to test the effects of passing specific props into a component
78
- Understand how to monitor the behavior of functional mock props.
89
- Understand how and when to test using the rerender method
910
- Learn how to mock the use an external module
1011

1112
## Introduction
13+
1214
As a developer, you will often be asked to write tests for the feature you are building and even on features other developers have built. In this project, we will mimic a situation where you are asked to test someone else's code.
1315

1416
Get the project fired up and start using it as a user would. Try to go through the user sequences for this feature that you think users would go through. Once you have those in mind, you will have an idea of what to test in your application.
1517

1618
![Stranger Example](project_example.gif)
1719

18-
***Make sure to complete your tasks one at a time and complete test each task before proceeding forward.***
20+
**_Make sure to complete your tasks one at a time and complete test each task before proceeding forward._**
1921

2022
## Instructions
23+
2124
### Task 1: Project Set Up
22-
* [ ] Create a forked copy of this project.
23-
* [ ] Clone your OWN version of the repository in your terminal
24-
* [ ] cd into the project base directory `cd web-module-project-reducer-pattern`
25-
* [ ] Download project dependencies by running `npm install`
26-
* [ ] Start up the app using `npm start`
27-
- [ ] With each saved change in your editor, the test runner will re-run all the tests
28-
- [ ] **IMPORTANT** If a test fails, use the test runner's error messages to find out why it is failing
25+
26+
- [ ] Create a forked copy of this project.
27+
- [ ] Clone your OWN version of the repository in your terminal
28+
- [ ] cd into the project base directory `cd web-module-project-testing-react`
29+
- [ ] Download project dependencies by running `npm install`
30+
- [ ] Start up the app using `npm start`
31+
32+
* [ ] With each saved change in your editor, the test runner will re-run all the tests
33+
* [ ] **IMPORTANT** If a test fails, use the test runner's error messages to find out why it is failing
2934

3035
### Task 2: Project Requirements
36+
3137
#### The Episode Component
32-
> *This component displays a single episode worth of data. To test it, let's try our some different varieties on what we should pass into our component's props.*
3338

34-
* [ ] Complete a test that shows the Episode component renders. Pass in the provided example episode data as a test prop.
35-
* [ ] Modify the test data to display a specific summary statement. Complete a test that shows that the summary value passed in to the Episode component displays as expected. **Use at least then 3 different types of expect statements to test the the existence of the summary value.**
36-
* [ ] The episode component displays a default value ('https://i.ibb.co/2FsfXqM/stranger-things.png') when a image url is not provided. Create a new piece of test data with the image property set to `null`. Test that the alt tag of the image displayed is set to './stranger_things.png'.
39+
> _This component displays a single episode worth of data. To test it, let's try our some different varieties on what we should pass into our component's props._
40+
41+
- [ ] Complete a test that shows the Episode component renders. Pass in the provided example episode data as a test prop.
42+
- [ ] Modify the test data to display a specific summary statement. Complete a test that shows that the summary value passed in to the Episode component displays as expected. **Use at least then 3 different types of expect statements to test the the existence of the summary value.**
43+
- [ ] The episode component displays a default value ('https://i.ibb.co/2FsfXqM/stranger-things.png') when a image url is not provided. Create a new piece of test data with the image property set to `null`. Test that the alt tag of the image displayed is set to './stranger_things.png'.
3744

3845
### The Show Component
39-
> *This component holds all general information on our featured show. Here we will once again work with data props, mock a function for testing and rerender our component for a change in data.*
4046

41-
* [ ] Build an example data structure that contains the show data in the correct format. A show should contain a name, a summary and an array of seasons, each with a id, name and an (empty) list of episodes within them. Use console.logs within the client code if you need to to verify the structure of show data.
42-
* [ ] Test that the Show component renders when your test data is passed in through show prop and "none" is passed in through selectedSeason prop.
43-
* [ ] Test that the Loading component displays when null is passed into the show prop (look at the Loading component to see how to test for it's existence)
44-
* [ ] Test that when your test data is passed through the show prop, the same number of season select options appear as there are seasons within your test data.
45-
* [ ] Test that when an item is selected, the handleSelect function is called. Look at your code to see how to get access to the select DOM element and [userEvent reference materials](https://testing-library.com/docs/ecosystem-user-event/) to see how to trigger a selection.
46-
* [ ] Test that the episode component DOES NOT render when the selectedSeason props is "none" and DOES render the episode component when the selectedSeason prop has a valid season index.
47+
> _This component holds all general information on our featured show. Here we will once again work with data props, mock a function for testing and rerender our component for a change in data._
48+
49+
- [ ] Build an example data structure that contains the show data in the correct format. A show should contain a name, a summary and an array of seasons, each with a id, name and an (empty) list of episodes within them. Use console.logs within the client code if you need to to verify the structure of show data.
50+
- [ ] Test that the Show component renders when your test data is passed in through show prop and "none" is passed in through selectedSeason prop.
51+
- [ ] Test that the Loading component displays when null is passed into the show prop (look at the Loading component to see how to test for it's existence)
52+
- [ ] Test that when your test data is passed through the show prop, the same number of season select options appear as there are seasons within your test data.
53+
- [ ] Test that when an item is selected, the handleSelect function is called. Look at your code to see how to get access to the select DOM element and [userEvent reference materials](https://testing-library.com/docs/ecosystem-user-event/) to see how to trigger a selection.
54+
- [ ] Test that the episode component DOES NOT render when the selectedSeason props is "none" and DOES render the episode component when the selectedSeason prop has a valid season index.
4755

4856
### The Display Component
49-
> *This component holds the state values of the application and handles api calls. In this component's tests, you work with mocking external modules and working with async / await / waitFor*
50-
* [ ] Test that the Display component renders without any passed in props.
51-
* [ ] Rebuild or copy the show test data element as used in the previous set of tests.
52-
* [ ] Test that when the fetch button is pressed, the show component will display. Make sure to account for the api call and change of state in building your test.
53-
* [ ] Test that when the fetch button is pressed, the amount of select options rendered is equal to the amount of seasons in your test data.
54-
* [ ] Notice the optional functional prop passed in to the Display component client code. Test that when the fetch button is pressed, this function is called.
57+
58+
> _This component holds the state values of the application and handles api calls. In this component's tests, you work with mocking external modules and working with async / await / waitFor_
59+
60+
- [ ] Test that the Display component renders without any passed in props.
61+
- [ ] Rebuild or copy the show test data element as used in the previous set of tests.
62+
- [ ] Test that when the fetch button is pressed, the show component will display. Make sure to account for the api call and change of state in building your test.
63+
- [ ] Test that when the fetch button is pressed, the amount of select options rendered is equal to the amount of seasons in your test data.
64+
- [ ] Notice the optional functional prop passed in to the Display component client code. Test that when the fetch button is pressed, this function is called.
5565

5666
### Stretch goals
67+
5768
- Add in a testing suite for the episodes component.
5869

5970
- Look up the `TVMaze` API. Add a dropdown with the titles of some other popular shows. Add the user sequence of choosing a different show to fetch data for different shows.
6071

6172
- Add React Router, and add the functionality to click an episode and navigate to an episode page.
6273

6374
### Submission Format
75+
6476
- [ ] If this is your first time connecting a submission, authorize your github account within the codegrade assignment.
6577
- [ ] Connect your fork to Codegrade using the "Connect Git" button.
6678
- [ ] Find your newly created fork from the list and push your work to main.
6779
- [ ] Check this video for details: www.youtube.com/watch?v=fC2BO7dI6IQ
68-

src/components/tests/Episode.test.js

+25-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1-
import React from 'react';
2-
import { render, fireEvent, screen } from '@testing-library/react';
3-
import '@testing-library/jest-dom/extend-expect';
4-
import Episode from './../Episode';
1+
import React from "react";
2+
import { render, fireEvent, screen } from "@testing-library/react";
3+
import "@testing-library/jest-dom/extend-expect";
4+
import Episode from "./../Episode";
55

6-
test("renders without error", () => { });
6+
test("renders without error", () => {});
77

8-
test("renders the summary test passed as prop", () => { });
8+
test("renders the summary test passed as prop", () => {});
99

10-
test("renders default image when image is not defined", () => { });
10+
test("renders default image when image is not defined", () => {});
11+
12+
// ----- EXAMPLE EPISODE TEST OBJECT -----
13+
// const exampleEpisodeData = {
14+
// airdate: "2016-07-15",
15+
// airstamp: "2016-07-15T12:00:00+00:00",
16+
// airtime: "",
17+
// id: 553946,
18+
// image: "https://static.tvmaze.com/uploads/images/medium_landscape/342/855786.jpg",
19+
// name: "Chapter One: The Vanishing of Will Byers",
20+
// number: 1,
21+
// rating: { average: 8.2 },
22+
// runtime: 49,
23+
// season: 1,
24+
// summary:
25+
// "A young boy mysteriously disappears, and his panicked mother demands that the police find him. Meanwhile, the boy's friends conduct their own search, and meet a mysterious girl in the forest.",
26+
// type: "regular",
27+
// url: "https://www.tvmaze.com/episodes/553946/stranger-things-1x01-chapter-one-the-vanishing-of-will-byers",
28+
// };

0 commit comments

Comments
 (0)