Skip to content

Commit bddde00

Browse files
committed
update tests
1 parent b8771be commit bddde00

File tree

6 files changed

+62
-48
lines changed

6 files changed

+62
-48
lines changed

__tests__/Snapshottest/UIOutputComparisonTests.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ describe("LibraryContainer", function () {
1919
let data = createLibraryItem(ItemData);
2020

2121
// Create "LibraryContainer" to pass as an argument for creation of "LibraryItem"
22-
const libContainer = LibraryEntryPoint.CreateLibraryController();
22+
let libcontroller = LibraryEntryPoint.CreateLibraryController()
23+
let libContainer = mount(libcontroller.createLibraryContainer())
2324

2425
// Creation of LibraryItem component
2526
const libraryItemComponent = <LibraryItem libraryContainer={libContainer as any} data={data} showItemSummary={false} />;

__tests__/Snapshottest/__snapshots__/UIOutputComparisonTests.tsx.snap

+46-31
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ exports[`LibraryContainer Test UI rendering of Library Item and child components
1313
"description": "",
1414
"expanded": false,
1515
"fullyQualifiedName": "",
16+
"hiddenInWorkspaceContext": false,
1617
"iconUrl": "",
1718
"itemType": "category",
1819
"keywords": [
@@ -31,6 +32,7 @@ exports[`LibraryContainer Test UI rendering of Library Item and child components
3132
"description": "",
3233
"expanded": false,
3334
"fullyQualifiedName": "",
35+
"hiddenInWorkspaceContext": false,
3436
"iconUrl": "",
3537
"itemType": "category",
3638
"keywords": [
@@ -48,6 +50,7 @@ exports[`LibraryContainer Test UI rendering of Library Item and child components
4850
"description": "",
4951
"expanded": false,
5052
"fullyQualifiedName": "",
53+
"hiddenInWorkspaceContext": false,
5154
"iconUrl": "",
5255
"itemType": "none",
5356
"keywords": [
@@ -62,37 +65,49 @@ exports[`LibraryContainer Test UI rendering of Library Item and child components
6265
}
6366
}
6467
libraryContainer={
65-
LibraryController {
66-
"DefaultSectionName": "default",
67-
"FilterCategoryEventName": "filterCategoryChange",
68-
"ItemClickedEventName": "itemClicked",
69-
"ItemMouseEnterEventName": "itemMouseEnter",
70-
"ItemMouseLeaveEventName": "itemMouseLeave",
71-
"ItemSummaryExpandedEventName": "itemSummaryExpanded",
72-
"MiscSectionName": "Miscellaneous",
73-
"RefreshLibraryViewRequestName": "refreshLibraryView",
74-
"SearchTextUpdatedEventName": "searchTextUpdated",
75-
"SectionIconClickedEventName": "sectionIconClicked",
76-
"createLibraryByElementId": [Function],
77-
"createLibraryContainer": [Function],
78-
"modifyItemHandler": null,
79-
"modifyLibraryItemData": [Function],
80-
"on": [Function],
81-
"raiseEvent": [Function],
82-
"reactor": Reactor {
83-
"events": [],
84-
},
85-
"refreshLibraryView": [Function],
86-
"refreshLibraryViewHandler": null,
87-
"registerRequestHandler": [Function],
88-
"request": [Function],
89-
"requestHandler": {},
90-
"searchLibraryItemsHandler": null,
91-
"setLayoutSpecsJson": [Function],
92-
"setLayoutSpecsJsonHandler": null,
93-
"setLoadedTypesJson": [Function],
94-
"setLoadedTypesJsonHandler": null,
95-
}
68+
<LibraryContainer
69+
defaultSectionString="default"
70+
libraryController={
71+
LibraryController {
72+
"DefaultSectionName": "default",
73+
"FilterCategoryEventName": "filterCategoryChange",
74+
"ItemClickedEventName": "itemClicked",
75+
"ItemMouseEnterEventName": "itemMouseEnter",
76+
"ItemMouseLeaveEventName": "itemMouseLeave",
77+
"ItemSummaryExpandedEventName": "itemSummaryExpanded",
78+
"MiscSectionName": "Miscellaneous",
79+
"RefreshLibraryViewRequestName": "refreshLibraryView",
80+
"SearchTextUpdatedEventName": "searchTextUpdated",
81+
"SectionIconClickedEventName": "sectionIconClicked",
82+
"createLibraryByElementId": [Function],
83+
"createLibraryContainer": [Function],
84+
"modifyItemHandler": null,
85+
"modifyLibraryItemData": [Function],
86+
"on": [Function],
87+
"raiseEvent": [Function],
88+
"reactor": Reactor {
89+
"events": [],
90+
},
91+
"refreshLibraryView": [Function],
92+
"refreshLibraryViewHandler": [Function],
93+
"registerRequestHandler": [Function],
94+
"request": [Function],
95+
"requestHandler": {},
96+
"searchLibraryItemsHandler": null,
97+
"setHostContext": [Function],
98+
"setHostContextHandler": [Function],
99+
"setLayoutSpecsJson": [Function],
100+
"setLayoutSpecsJsonHandler": [Function],
101+
"setLoadedTypesJson": [Function],
102+
"setLoadedTypesJsonHandler": [Function],
103+
}
104+
}
105+
miscSectionString="Miscellaneous"
106+
>
107+
<div>
108+
This is LibraryContainer
109+
</div>
110+
</LibraryContainer>
96111
}
97112
showItemSummary={false}
98113
>

__tests__/UITests.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ describe("LibraryContainer UI", function () {
106106
};
107107

108108
libController = LibraryEntryPoint.CreateLibraryController();
109+
libContainer = mount(libController.createLibraryContainer())
109110
});
110111

111112
it("should recognize mouse click event and change expand state", function () {
@@ -117,7 +118,7 @@ describe("LibraryContainer UI", function () {
117118
// If you are testing full React components,
118119
// mount is used to do rendering and test actions are simulated on mounted html
119120

120-
let libraryItem = mount(<LibraryItem libraryContainer={libController as any} data={data} showItemSummary={false} />);
121+
let libraryItem = mount(<LibraryItem libraryContainer={libContainer as any} data={data} showItemSummary={false} />);
121122

122123
expect(libraryItem).to.have.lengthOf(1);
123124
expect(libraryItem.props().data.childItems).to.have.lengthOf(2);
@@ -137,7 +138,7 @@ describe("LibraryContainer UI", function () {
137138
let data = createLibraryItem(ItemData);
138139

139140
//pass a callback which if called will end the test
140-
let libraryItem = mount(<LibraryItem libraryContainer={libController as any} data={data} showItemSummary={false} onItemWillExpand={() => { done() }} />);
141+
let libraryItem = mount(<LibraryItem libraryContainer={libContainer} data={data} showItemSummary={false} onItemWillExpand={() => { done() }} />);
141142

142143
let header = libraryItem.find(('div.LibraryItemHeader')).at(0);// the state of LibraryItem is changed when clicking on header
143144
expect(header).to.have.lengthOf(1); // verify that there is a header

src/components/LibraryContainer.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ export class LibraryContainer extends React.Component<LibraryContainerProps, Lib
7575
this.handleKeyDown = this.handleKeyDown.bind(this);
7676
this.scrollToExpandedItem = this.scrollToExpandedItem.bind(this);
7777
this.setTooltipText = this.setTooltipText.bind(this);
78-
this.setContext = this.setContext.bind(this);
78+
this.setHostContext = this.setHostContext.bind(this);
7979

8080
// Set handlers after methods are bound.
8181
this.props.libraryController.setLoadedTypesJsonHandler = this.setLoadedTypesJson;
8282
this.props.libraryController.setLayoutSpecsJsonHandler = this.setLayoutSpecsJson;
8383
this.props.libraryController.refreshLibraryViewHandler = this.refreshLibraryView;
84-
this.props.libraryController.setContextHandler = this.setContext;
84+
this.props.libraryController.setHostContextHandler = this.setHostContext;
8585

8686
// Initialize the search utilities with empty data
8787
this.searcher = new Searcher();
@@ -208,7 +208,7 @@ export class LibraryContainer extends React.Component<LibraryContainerProps, Lib
208208
this.updateSections(this.generatedSections);
209209
}
210210

211-
setContext(context:HostingContextType){
211+
setHostContext(context:HostingContextType){
212212
this.setState({shouldOverideExpandedState:false, hostingContext:context})
213213
}
214214

src/components/LibraryItem.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import * as LibraryUtilities from "../LibraryUtilities";
2323
import { ArrowIcon } from "./icons";
2424
import { LibraryContainer } from "./LibraryContainer";
2525
import { HostingContextType } from "../sharedTypes";
26-
import { setItemStateRecursive } from "../LibraryUtilities";
2726

2827
export interface LibraryItemProps {
2928
libraryContainer: LibraryContainer,
@@ -101,7 +100,7 @@ export class LibraryItem extends React.Component<LibraryItemProps, LibraryItemSt
101100
}
102101

103102
render() {
104-
if ((this.props.libraryContainer.state.hostingContext == "home" as HostingContextType)
103+
if ((this.props.libraryContainer.state?.hostingContext == "home" as HostingContextType)
105104
&& this.props.data.hiddenInWorkspaceContext){
106105
return null;
107106
}
@@ -427,11 +426,9 @@ export class LibraryItem extends React.Component<LibraryItemProps, LibraryItemSt
427426
event.stopPropagation(); // Prevent the onClick event of its parent item from being called.
428427
}
429428

430-
// Collapse all child items when one of the child items is expanded
431429
onSingleChildItemWillExpand() {
432-
for (let item of this.props.data.childItems) {
433-
item.expanded = false;
434-
}
430+
//"this" here refers to the parent library item, and will expand it and kick off a render cycle
431+
//for all children below it.
435432
this.setState({ expanded: true }); // Make the current item (parent) expanded.
436433
}
437434
onLibraryItemMouseLeave() {

src/entry-point.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class LibraryController {
4646
setLayoutSpecsJsonHandler: SetLayoutSpecsJsonFunc | null = null;
4747
refreshLibraryViewHandler: RefreshLibraryViewFunc | null = null;
4848
modifyItemHandler:((contextDataToMatch:any, dataToModify:ItemData)=> boolean) | null = null;
49-
setContextHandler:((context:HostingContextType)=> void) | null = null;
49+
setHostContextHandler:((context:HostingContextType)=> void) | null = null;
5050

5151
// This is to make it possible to set an external search handler.
5252
// Given a search text, it will call the callback function with search result.
@@ -64,7 +64,7 @@ export class LibraryController {
6464
this.setLayoutSpecsJson = this.setLayoutSpecsJson.bind(this);
6565
this.refreshLibraryView = this.refreshLibraryView.bind(this);
6666
this.modifyLibraryItemData = this.modifyLibraryItemData.bind(this);
67-
this.setContext = this.setContext.bind(this);
67+
this.setHostContext = this.setHostContext.bind(this);
6868

6969
this.reactor = new Reactor();
7070
}
@@ -179,11 +179,11 @@ export class LibraryController {
179179
return false;
180180
}
181181
//TODO summary
182-
setContext(context:HostingContextType):void{
182+
setHostContext(context:HostingContextType):void{
183183
console.log("I AM HERE")
184-
if(this.setContextHandler){
184+
if(this.setHostContextHandler){
185185
console.log("set context to",context)
186-
return this.setContextHandler(context);
186+
return this.setHostContextHandler(context);
187187
}
188188
}
189189
}

0 commit comments

Comments
 (0)