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 unit tests for chat window header #63

Conversation

wanglam
Copy link
Collaborator

@wanglam wanglam commented Dec 12, 2023

Description

Add unit tests for chat window header

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.

Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Copy link

codecov bot commented Dec 12, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c70bcfc) 48.75% compared to head (eea4e46) 60.69%.
Report is 4 commits behind head on feature/agent-framework.

Additional details and impacted files
@@                     Coverage Diff                      @@
##           feature/agent-framework      #63       +/-   ##
============================================================
+ Coverage                    48.75%   60.69%   +11.93%     
============================================================
  Files                           46       46               
  Lines                         1087     1089        +2     
  Branches                       250      252        +2     
============================================================
+ Hits                           530      661      +131     
+ Misses                         548      419      -129     
  Partials                         9        9               

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

setSelectedTabId: jest.fn(),
setFlyoutComponent: jest.fn(),
};
jest.spyOn(chatContextExports, 'useChatContext').mockReturnValue(useChatContextMock);
Copy link
Member

Choose a reason for hiding this comment

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

I am thinking if we should add two files: chat_context.mock.ts and use_chat_state.mock.ts, in which we can mock the output and export the mocked methods. I've seen over 3 PRs have this spyOn function to hijack useChatContext.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we can provide a general mocks for chat_context and use_chat_state. But we may still need to customized the mock in some specific PRs. Can be refactor in the next PRs.

expect(queryByText('Experimental')).not.toBeInTheDocument();
fireEvent.click(getByRole('button'));
expect(getByText('Experimental')).toBeInTheDocument();
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure snapshot match assertion is needed here, we could have one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think snapshot match would be too heavy. Match Experimental title is enough here.


await waitFor(() => {
expect(renderResult.queryByText('OpenSearch Assistant')).not.toBeInTheDocument();
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

test seems not match the description should show "OpenSearch Assistant" when sessionId is not defined

@@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
Copy link
Collaborator

Choose a reason for hiding this comment

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

useEffect seems not used in this file

Signed-off-by: Lin Wang <wonglam@amazon.com>
@wanglam wanglam merged commit 540bdb7 into opensearch-project:feature/agent-framework Dec 13, 2023
10 checks passed
joshuali925 pushed a commit to joshuali925/dashboards-assistant that referenced this pull request Dec 13, 2023
* test: add unit tests for chat window header

Signed-off-by: Lin Wang <wonglam@amazon.com>

* test: add ut for chat window header title

Signed-off-by: Lin Wang <wonglam@amazon.com>

* test: add unit tests for chat experimental badge

Signed-off-by: Lin Wang <wonglam@amazon.com>

* Address PR comments

Signed-off-by: Lin Wang <wonglam@amazon.com>

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>
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.

3 participants