Skip to content

Commit 4032688

Browse files
DYN 6968 some tests are skipped in librarie js (#247)
* fix(SearchBar): onDetailedModeChange didn't get the last detailed state * fix: skipped tests * fix: remove unnecessary Chai assert import --------- Co-authored-by: enzo707 <enzo.batista@autodesk.com>
1 parent 891e65f commit 4032688

File tree

3 files changed

+21
-50
lines changed

3 files changed

+21
-50
lines changed

__tests__/UITests.tsx

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@ import { LibraryItem } from '../src/components/LibraryItem';
99
import { ItemData } from "../src/LibraryUtilities";
1010
import { createLibraryItem } from "../src/utils";
1111
import * as Adapter from 'enzyme-adapter-react-16';
12-
import { expect, assert } from 'chai';
12+
import { expect } from 'chai';
1313
import { LibraryContainer } from '../src/components/LibraryContainer';
1414

1515
configure({adapter: new Adapter()});
1616

17-
describe("sample test", function () {
18-
it("should add two numbers", function () {
19-
expect(1 + 2).to.equal(3);
20-
});
21-
});
22-
2317
describe("LibraryContainer UI", function () {
2418
let loadedTypesJson: any;
2519
let layoutSpecsJson: any;
@@ -156,27 +150,25 @@ describe("LibraryContainer UI", function () {
156150
libController.setLoadedTypesJson(loadedTypesJson, false);
157151
libController.setLayoutSpecsJson(layoutSpecsJson, false);
158152
libController.refreshLibraryView();
153+
libContainer.update();
159154

160155
})
161156

162-
xit("scrollToElement should be called when libraryItem is expanded only", function () {
157+
it("scrollToElement should be called when libraryItem is expanded only", function () {
163158

159+
let scrolled = false;
164160
let header = libContainer.find('div.LibraryItemHeader').at(0);
165161
expect(header).to.have.lengthOf(1);
166-
let count = 0;
167162

168163
//replace the scroll method with a method which ends the test.
169-
(libContainer.getNode() as unknown as LibraryContainer).scrollToExpandedItem = () => { count = count + 1; }
170-
header.simulate('click');
164+
(libContainer.instance() as unknown as LibraryContainer).scrollToExpandedItem = () => { scrolled = !scrolled;}
171165
header.simulate('click');
172-
assert.equal(count, 1);
166+
expect(scrolled).to.be.true;
173167

174168
});
175169

176170

177-
// Test uses timeout function and testframework knows
178-
// when to complete the test bases on calling funciton 'done()'
179-
xit("search a string in library and verify change of state and results", function (done) {
171+
it("search a string in library and verify change of state and results", function () {
180172

181173
// find is used to find a rendered component by css selectors,
182174
// component constructors, display name or property selector.
@@ -187,23 +179,18 @@ describe("LibraryContainer UI", function () {
187179

188180
// Search is triggered after a timeout of 300 milli seconds
189181
// So wait before verifying the results
190-
191182
setTimeout(function () {
192183
// Verify the state 'inSearchMode' is changed
193184
expect(libContainer.state('inSearchMode')).to.be.true;
194-
//let result = libContainer.find('div.LibraryItemContainer');
195185
// Verify the search results are correct
196186
let value = libContainer.find('SearchResultItem');
197187
expect(value).to.have.lengthOf(2);
198188
expect((value.at(0).props() as any).data.text).to.equal("Child1");
199189
expect((value.at(1).props() as any).data.text).to.equal("Child2");
200-
done();// For testframework to figure out when to complete this test
201190
}, 500);
202191
});
203192

204-
// Test uses timeout function and testframework knows
205-
// when to complete the test bases on calling funciton 'done()'
206-
xit("search a negative scenario for search", function (done) {
193+
it("search a negative scenario for search", function () {
207194

208195
// find is used to find a rendered component by css selectors,
209196
// component constructors, display name or property selector.
@@ -221,11 +208,10 @@ describe("LibraryContainer UI", function () {
221208
// Verify the search does not return any nodes
222209
let value = libContainer.find('SearchResultItem');
223210
expect(value).to.have.lengthOf(0);
224-
done();// For testframework to figure out when to complete this test
225211
}, 500);
226212
});
227213

228-
xit("change state of searchbar to detail view and verify the search results display item description", function (done) {
214+
it("change state of searchbar to detail view and verify the search results display item description", function () {
229215

230216
// Trigger the search so the option for detail view is enabled
231217
let text = () => libContainer.find('input.SearchInputText');
@@ -251,11 +237,10 @@ describe("LibraryContainer UI", function () {
251237
expect(describe).to.have.lengthOf(2);
252238
expect(describe.at(0).text()).to.equal('First item');
253239
expect(describe.at(1).text()).to.equal('Second item');
254-
done(); // For testframework to know when to terminate execution
255240
}, 500);
256241
});
257242

258-
xit("search bar should not contain structured view button", function () {
243+
it("search bar should not contain structured view button", function () {
259244

260245
let buttons = libContainer.find('button');
261246
//detail view, filter.
@@ -273,7 +258,7 @@ describe("LibraryContainer UI", function () {
273258

274259
});
275260

276-
xit("click item text on search should return to the library item", function (done) {
261+
it("click item text on search should return to the library item", function () {
277262

278263
// Trigger the search so the option for detail view is enabled
279264
let text = () => libContainer.find('input.SearchInputText');
@@ -301,31 +286,18 @@ describe("LibraryContainer UI", function () {
301286
//click the item text
302287
detials.at(0).simulate('click');
303288
expect((value.at(0).props() as any).data.pathToItem[0].expanded).to.be.true;
304-
done();
305289
}, 500);
306290
});
307291

308-
xit("coregroup items should auto expand", function () {
309-
310-
let header = libContainer.find('div.LibraryItemHeader').at(0);
311-
expect(header).to.have.lengthOf(1);
312-
313-
header.simulate('click');
314-
315-
let libraryItem = libContainer.find('LibraryItem') as any;
316-
expect(libraryItem.nodes[2].props.data.expanded).to.be.true;
317-
318-
});
319-
320-
it("add-ons should auto expand", function () {
292+
it("add-ons should auto expand", function () {
321293

322-
let generatedSections = libContainer.instance().generatedSections;
323-
expect(generatedSections).to.have.lengthOf(2);
324-
if(!generatedSections) return;
325-
expect(generatedSections[1].text).to.equal("Add-ons");
326-
expect(generatedSections[1].expanded).to.be.true;
327-
328-
});
294+
let generatedSections = libContainer.instance().generatedSections;
295+
expect(generatedSections).to.have.lengthOf(2);
296+
if(!generatedSections) return;
297+
expect(generatedSections[1].text).to.equal("Add-ons");
298+
expect(generatedSections[1].expanded).to.be.true;
299+
300+
});
329301
})
330302

331303
});

__tests__/mochatest/libraryUtilitiesTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ describe("findAndExpandItemByPath function", function () {
14411441
//If the item is defined in RawDataType and not in layoutspec, it will be in miscallenous section.
14421442
//Searching for 113 in this test should not show data in the searchview. So, expanding an item is not possible
14431443
//in this case.
1444-
xit("should return false if an item is not found", function () {
1444+
it("should return false if an item is not found", function () {
14451445
let itemData113 = new LibraryUtilities.ItemData("113");
14461446
let pathToItem = [itemData1, itemData11, itemData113];
14471447
expect(LibraryUtilities.findAndExpandItemByPath(pathToItem, allItems)).to.equal(false);

src/components/SearchBar.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export class SearchBar extends React.Component<SearchBarProps, SearchBarState> {
226226

227227
onDetailedModeChanged(event: any) {
228228
this.setState(prevState => ({detailed: !prevState.detailed}));
229-
this.props.onDetailedModeChanged(this.state.detailed);
229+
this.props.onDetailedModeChanged(!this.state.detailed);
230230
}
231231

232232
getSelectedCategories(): string[]{
@@ -290,7 +290,6 @@ export class SearchBar extends React.Component<SearchBarProps, SearchBarState> {
290290
createFilterPanel(){
291291
let binIcon: string = require("../resources/ui/bin.svg");
292292

293-
console.log(this.state.selectedCategories)
294293
let checkboxes: React.ReactNode[] = ObjectExtensions.values(this.categoryData)
295294
.map(cat => cat.getCheckbox(this.state.selectedCategories.includes(cat.name)))
296295

0 commit comments

Comments
 (0)