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

Add tests for ChatPageContent component #54

Conversation

ruanyl
Copy link
Member

@ruanyl ruanyl commented Dec 8, 2023

add MessageBubble unit tests
add MessageContent unit tests
remove MessageFooter which is not needed anymore

Description

Describe what this change achieves.

Issues Resolved

List any issues this PR will resolve, e.g. Closes [...].

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

add MessageBubble unit tests
add MessageContent unit tests
remove MessageFooter which is not needed anymore

Signed-off-by: Yulong Ruan <[email protected]>
Copy link

codecov bot commented Dec 8, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9663fb1) 27.40% compared to head (ef16dc4) 39.33%.

Additional details and impacted files
@@                     Coverage Diff                      @@
##           feature/agent-framework      #54       +/-   ##
============================================================
+ Coverage                    27.40%   39.33%   +11.93%     
============================================================
  Files                           40       40               
  Lines                          905      905               
  Branches                       223      223               
============================================================
+ Hits                           248      356      +108     
+ Misses                         650      541      -109     
- Partials                         7        8        +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Yulong Ruan <[email protected]>

jest.mock('./messages/message_content', () => {
return { MessageContent: () => <div /> };
});
Copy link
Member

Choose a reason for hiding this comment

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

just curious why are child components mocked?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good question! There has been lots of discussions around this. For unit test, I tend to mock child components in RTL which are smart components, for example, the components that:

  1. Access data via API call
  2. Have side effects such as read/write local storage
  3. Access context
  4. Access global state

By mocking such components, I think it makes the tests concise and less fragile. And ofc, the child component should be covered by its own unit tests.

@ruanyl ruanyl merged commit 3d46971 into opensearch-project:feature/agent-framework Dec 11, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants