@@ -3,7 +3,11 @@ import { render, screen, userEvent } from '@mongodb-js/testing-library-compass';
33import { expect } from 'chai' ;
44import sinon from 'sinon' ;
55import HadronDocument from 'hadron-document' ;
6- import { HadronElement , getNestedKeyPathForElement } from './element' ;
6+ import {
7+ HadronElement ,
8+ type QueryBarController ,
9+ getNestedKeyPathForElement ,
10+ } from './element' ;
711import type { Element } from 'hadron-document' ;
812
913describe ( 'HadronElement' , function ( ) {
@@ -32,21 +36,18 @@ describe('HadronElement', function () {
3236
3337 // Mock queryBar controller
3438 const mockQueryBar = {
35- isInQuery : sinon . stub ( ) ,
39+ isInQuery : sinon . stub ( ) . returns ( false ) ,
3640 toggleQueryFilter : sinon . spy ( ) ,
3741 } ;
3842
39- // Initially not in query
40- mockQueryBar . isInQuery . returns ( false ) ;
41-
4243 const { rerender } = render (
4344 < HadronElement
4445 value = { nestedElement }
4546 editable = { true }
4647 editingEnabled = { true }
4748 lineNumberSize = { 1 }
4849 onAddElement = { ( ) => { } }
49- queryBar = { mockQueryBar }
50+ queryBar = { mockQueryBar as unknown as QueryBarController }
5051 />
5152 ) ;
5253
@@ -57,12 +58,10 @@ describe('HadronElement', function () {
5758 expect ( screen . getByText ( 'Add to query' ) ) . to . exist ;
5859 expect ( screen . queryByText ( 'Remove from query' ) ) . to . not . exist ;
5960
60- // Click "Add to query"
6161 userEvent . click ( screen . getByText ( 'Add to query' ) , undefined , {
6262 skipPointerEventsCheck : true ,
6363 } ) ;
6464
65- // Verify toggleQueryFilter was called with correct parameters
6665 expect ( mockQueryBar . toggleQueryFilter ) . to . have . been . calledWith (
6766 'user.name' ,
6867 nestedElement . generateObject ( )
@@ -79,7 +78,10 @@ describe('HadronElement', function () {
7978 editingEnabled = { true }
8079 lineNumberSize = { 1 }
8180 onAddElement = { ( ) => { } }
82- queryBar = { mockQueryBar }
81+ queryBar = { {
82+ ...mockQueryBar ,
83+ isInQuery : sinon . stub ( ) . returns ( true ) ,
84+ } }
8385 />
8486 ) ;
8587
@@ -89,12 +91,10 @@ describe('HadronElement', function () {
8991 expect ( screen . getByText ( 'Remove from query' ) ) . to . exist ;
9092 expect ( screen . queryByText ( 'Add to query' ) ) . to . not . exist ;
9193
92- // Click "Remove from query"
9394 userEvent . click ( screen . getByText ( 'Remove from query' ) , undefined , {
9495 skipPointerEventsCheck : true ,
9596 } ) ;
9697
97- // Verify toggleQueryFilter was called again
9898 expect ( mockQueryBar . toggleQueryFilter ) . to . have . been . calledTwice ;
9999 expect ( mockQueryBar . toggleQueryFilter . secondCall ) . to . have . been . calledWith (
100100 'user.name' ,
0 commit comments