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

minichallenge4 solved #85

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

oscarfiend
Copy link

Screenshot_304

"hooks": {}
},
"jest": {
"coveragePathIgnorePatterns": [
Copy link

@ghost ghost Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should remove the next files for this config:

"/src/providers",
"/src/providers",
"/src/config",
"/src/helpers/",
"/src/utils/",
"/src/index.js",
"/src/components/Fortune",
"/pages/NotFound",
"/components/App/"

They are part of the current app, so they should be included on the code coverage testing.

Please remove and update the code coverage report.

Any question or comment let me know.

@ghost
Copy link

ghost commented Aug 13, 2021

Acceptance Criteria

  • The search term is stored and retrieved from the Global Context correctly.
  • The appearance theme is stored on the Global Context and applied correctly to the App UI.
  • useReducer hook is implemented correctly to manage the Global State.

Bonus Points

  • Testing coverage is above 70%. (Please include a screenshot of the code coverage report in your PR description).

General comments

  • Make sure that you are adding the package-lock.json on git.
  • When I run the tests on my local machine, I have:
 TestingLibraryElementError: Unable to find an element by: [data-testid="/list_videos/i"]

    <body>
      <div>
        <h2>
          Error fetching data, try later
        </h2>
      </div>
    </body>

    <body>
      <div>
        <h2>
          Error fetching data, try later
        </h2>
      </div>
    </body>Error: Unable to find an element by: [data-testid="/list_videos/i"]

    <body>
      <div>
        <h2>
          Error fetching data, try later
        </h2>
      </div>
    </body>
Test Suites: 2 failed, 4 passed, 6 total
Tests:       3 failed, 21 passed, 24 total
Snapshots:   0 total
Time:        7.877s

I think is because the tests are fetching to the real youtube api.

});

test('should containt a video description', () => {
// const titleVideo = screen.findByText(/una librería para crear interfaces web/i);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remember to remove commented code

const list = screen.findAllByTestId(/list_videos/i);
expect((await list).length).toBe(24)
});
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This are good test cases, but remember to mock the api call.https://jestjs.io/docs/mock-functions

@ghost
Copy link

ghost commented Aug 13, 2021

Good idea to separate the React context, one for Theme and another one for Video api logic, good work :D

const menu = screen.getByTestId(/hamburguerMenu/i);
expect(menu).toHaveAttribute('type', 'checkbox');
});
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great test, I see that you are mocking the Api, good work!


test('Toggle button should be checkbox type', () => {
const toggle = screen.getByRole('checkbox');
expect(toggle).toHaveAttribute('type', 'checkbox');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are doing the query getByRole('checkbox'), there is explicitly that the element is a checkbox, so you could do the expect using toBeInTheDocument(), makes sense?

const title = screen.getByText(/Youtube challenge/i);
expect(title).toBeInTheDocument();
});
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this Home component actually fetching the API?

const videoCreation = screen.queryByText(video.publishedAt);
expect(videoCreation).toBeInTheDocument();
});
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work :D

test('should containt a video iframe', () => {
waitFor(() => expect(screen.findByRole(/iframe/i)).toBeInTheDocument());
});
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good test,

You can refactor this kind of expects:

waitFor(() => expect(screen.findByText(/Qué es React/i)).toBeInTheDocument());

to only

expect(await screen.findByText(/Qué es React/i)).toBeInTheDocument()

because findBy is a combination of getBy and waitFor: https://testing-library.com/docs/dom-testing-library/api-async/#findby-queries

baseURL: 'https://content-youtube.googleapis.com/youtube/v3/',
});

export default axiosClient;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of axios instance.

Go one more step ahead and try to put the baseURL value as Env variable, in order to get this more easy to change on the time.

UPDATE_QUERY_VIDEO,
} from '../../utils/constants';

export default (state = {}, { type, payload }) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a good idea to have the initial state with the default properties values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant