Skip to content

Commit 5e59c36

Browse files
committed
Update 1
Signed-off-by: Parship Chowdhury <[email protected]>
1 parent 9314eee commit 5e59c36

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

packages/jaeger-ui/src/components/common/UiFindInput.test.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,19 @@ describe('UiFind', () => {
6969
expect(screen.getByPlaceholderText('Find...')).toHaveValue(uiFind);
7070
});
7171

72-
it('renders state.ownInputValue when it is not `undefined` regardless of props.uiFind', async () => {
72+
it('prioritizes state.ownInputValue over props.uiFind when ownInputValue is set', async () => {
73+
// Test the initial state
7374
const { rerender } = render(<UnconnectedUiFindInput {...props} uiFind={uiFind} />);
75+
expect(screen.getByPlaceholderText('Find...')).toHaveValue(uiFind);
76+
77+
// Test setting ownInputValue through user interaction
7478
await userEvent.clear(screen.getByPlaceholderText('Find...'));
7579
await userEvent.type(screen.getByPlaceholderText('Find...'), ownInputValue);
80+
81+
// Verify the state change affected the value
82+
expect(screen.getByPlaceholderText('Find...')).toHaveValue(ownInputValue);
83+
84+
// Verify the precedence is maintained after re-render
7685
rerender(<UnconnectedUiFindInput {...props} uiFind={uiFind} />);
7786
expect(screen.getByPlaceholderText('Find...')).toHaveValue(ownInputValue);
7887
});
@@ -120,29 +129,30 @@ describe('UiFind', () => {
120129
});
121130

122131
it('no-ops if value is unchanged', async () => {
123-
// First render
124-
const { unmount } = render(<UnconnectedUiFindInput {...props} />);
125-
await userEvent.clear(screen.getByPlaceholderText('Find...'));
126-
expect(updateUiFindSpy).not.toHaveBeenCalled();
127-
unmount();
128-
129-
// Second render
130132
render(<UnconnectedUiFindInput {...props} uiFind={uiFind} />);
131-
await userEvent.clear(screen.getByPlaceholderText('Find...'));
132-
await userEvent.type(screen.getByPlaceholderText('Find...'), uiFind);
133+
const input = screen.getByPlaceholderText('Find...');
134+
await userEvent.clear(input);
135+
await userEvent.type(input, uiFind);
133136
const calls = updateUiFindSpy.mock.calls;
134137
const calledWithUnchanged = calls.some(([args]) => args && args.uiFind === uiFind);
135138
expect(calledWithUnchanged).toBe(false);
136139
});
137140
});
138141

139142
describe('blurring input', () => {
140-
it('clears state.ownInputValue', async () => {
141-
render(<UnconnectedUiFindInput {...props} />);
142-
await userEvent.type(screen.getByPlaceholderText('Find...'), 'abc');
143-
expect(screen.getByPlaceholderText('Find...')).toHaveValue('abc');
144-
screen.getByPlaceholderText('Find...').blur();
145-
expect(screen.getByPlaceholderText('Find...')).toHaveValue(props.uiFind || undefined);
143+
it('clears state.ownInputValue and resets to props.uiFind', async () => {
144+
render(<UnconnectedUiFindInput {...props} uiFind={uiFind} />);
145+
const input = screen.getByPlaceholderText('Find...');
146+
await userEvent.clear(input);
147+
await userEvent.type(input, 'abc');
148+
expect(input).toHaveValue('abc');
149+
await userEvent.tab();
150+
expect(input).toHaveValue(uiFind);
151+
152+
// Verify that typing after blur starts from props.uiFind
153+
await userEvent.clear(input);
154+
await userEvent.type(input, 'xyz');
155+
expect(input).toHaveValue('xyz');
146156
});
147157

148158
it('triggers pending queryParameter updates', async () => {
@@ -172,10 +182,10 @@ describe('UiFind', () => {
172182
expect(screen.queryByTestId('clear-icon')).not.toBeInTheDocument();
173183
});
174184

175-
it('clears value immediately when clicked', () => {
185+
it('clears value immediately when clicked', async () => {
176186
render(<UnconnectedUiFindInput {...props} allowClear uiFind={uiFind} />);
177187
const clearIcon = screen.getByTestId('clear-icon');
178-
clearIcon.dispatchEvent(new MouseEvent('click', { bubbles: true }));
188+
await userEvent.click(clearIcon);
179189
expect(updateUiFindSpy).toHaveBeenLastCalledWith({
180190
history: props.history,
181191
location: props.location,

packages/jaeger-ui/src/components/common/__snapshots__/UiFindInput.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
exports[`UiFind rendering renders as expected 1`] = `
44
<div>
55
<span
6-
class="ant-input-affix-wrapper css-dev-only-do-not-override-18afz5u ant-input-outlined"
6+
class="ant-input-affix-wrapper css-dev-only-do-not-override-ut69n1 ant-input-outlined"
77
>
88
<input
9-
class="ant-input css-dev-only-do-not-override-18afz5u"
9+
class="ant-input css-dev-only-do-not-override-ut69n1"
1010
placeholder="Find..."
1111
type="text"
1212
value=""

0 commit comments

Comments
 (0)