From a4fc8c34175e888adec5b1e68d9b21c355e6c57b Mon Sep 17 00:00:00 2001 From: Yulia Startsev Date: Wed, 7 Jun 2017 14:02:26 +0200 Subject: [PATCH 1/8] add basic tests --- src/components/Editor/tests/Editor.js | 39 ++ src/components/Editor/tests/SearchBar.js | 35 ++ .../Editor/tests/__snapshots__/Editor.js.snap | 273 +++++++++++ .../tests/__snapshots__/SearchBar.js.snap | 436 ++++++++++++++++++ 4 files changed, 783 insertions(+) create mode 100644 src/components/Editor/tests/Editor.js create mode 100644 src/components/Editor/tests/SearchBar.js create mode 100644 src/components/Editor/tests/__snapshots__/Editor.js.snap create mode 100644 src/components/Editor/tests/__snapshots__/SearchBar.js.snap diff --git a/src/components/Editor/tests/Editor.js b/src/components/Editor/tests/Editor.js new file mode 100644 index 0000000000..7517122854 --- /dev/null +++ b/src/components/Editor/tests/Editor.js @@ -0,0 +1,39 @@ +import React from "react"; +import { shallow } from "enzyme"; +import Editor from "../index"; +import * as I from "immutable"; + +const EditorComponent = React.createFactory(Editor.WrappedComponent); + +function generateDefaults(overrides) { + return { + breakpoints: I.Map(), + addBreakpoint: jest.fn(), + disableBreakpoint: jest.fn(), + enableBreakpoint: jest.fn(), + removeBreakpoint: jest.fn(), + setBreakpointCondition: jest.fn(), + getExpression: jest.fn(), + addExpression: jest.fn(), + query: "", + searchModifiers: I.Record({ + caseSensitive: false, + regexMatch: false, + wholeWord: false + })(), + clearSelection: jest.fn + }; +} + +function render(overrides = {}) { + const props = generateDefaults(overrides); + const component = shallow(new EditorComponent(props)); + return { component, props }; +} + +describe("Editor", () => { + it("should render", async () => { + const { component } = render(); + expect(component).toMatchSnapshot(); + }); +}); diff --git a/src/components/Editor/tests/SearchBar.js b/src/components/Editor/tests/SearchBar.js new file mode 100644 index 0000000000..5e230a161b --- /dev/null +++ b/src/components/Editor/tests/SearchBar.js @@ -0,0 +1,35 @@ +import { createFactory } from "react"; +import { shallow } from "enzyme"; +import SearchBar from "../SearchBar"; + +const SearchBarComponent = createFactory(SearchBar.WrappedComponent); + +function generateDefaults() { + return { + query: "", + searchOn: true, + searchResults: [], + selectedResultIndex: 0 + }; +} + +function render(overrides = {}) { + const defaults = generateDefaults(); + const props = { ...defaults, ...overrides }; + const component = shallow(new SearchBarComponent(props)); + return { component, props }; +} + +describe("SearchBar", () => { + it("should render", () => { + const { component } = render(); + expect(component).toMatchSnapshot(); + }); + + it("should have a result list with search results from the props", () => { + const searchResults = [1, 2, 3]; + const { component } = render({ searchResults }); + const resultList = component.find("ResultList"); + expect(resultList.prop("items")).toBe(searchResults); + }); +}); diff --git a/src/components/Editor/tests/__snapshots__/Editor.js.snap b/src/components/Editor/tests/__snapshots__/Editor.js.snap new file mode 100644 index 0000000000..7211f7ab07 --- /dev/null +++ b/src/components/Editor/tests/__snapshots__/Editor.js.snap @@ -0,0 +1,273 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Editor should render 1`] = ` +ShallowWrapper { + "complexSelector": ComplexSelector { + "buildPredicate": [Function], + "childrenOfNode": [Function], + "findWhereUnwrapped": [Function], + }, + "length": 1, + "node":
+ +
+ Array [] + +
, + "nodes": Array [ +
+ +
+ Array [] + +
, + ], + "options": Object {}, + "renderer": ReactShallowRenderer { + "_instance": ShallowComponentWrapper { + "_calledComponentWillUnmount": false, + "_compositeType": 1, + "_context": Object {}, + "_currentElement": , + "_debugID": 1, + "_hostContainerInfo": null, + "_hostParent": null, + "_instance": Editor { + "_reactInternalInstance": [Circular], + "cbPanel": null, + "closeConditionalPanel": [Function], + "context": Object { + "shortcuts": undefined, + }, + "editor": null, + "lastJumpLine": null, + "onEscape": [Function], + "onGutterClick": [Function], + "onGutterContextMenu": [Function], + "onScroll": [Function], + "onSearchAgain": [Function], + "onToggleBreakpoint": [Function], + "pendingJumpLine": null, + "previewSelectedToken": [Function], + "props": Object { + "addBreakpoint": [Function], + "addExpression": [Function], + "breakpoints": Immutable.Map { +}, + "clearSelection": [Function], + "disableBreakpoint": [Function], + "enableBreakpoint": [Function], + "getExpression": [Function], + "query": "", + "removeBreakpoint": [Function], + "searchModifiers": Object { + "caseSensitive": false, + "regexMatch": false, + "wholeWord": false, + }, + "setBreakpointCondition": [Function], + }, + "refs": Object {}, + "state": Object { + "highlightedLineRange": null, + "searchResults": Object { + "count": 0, + "index": -1, + }, + "selectedToken": null, + }, + "toggleBreakpoint": [Function], + "toggleBreakpointDisabledStatus": [Function], + "toggleConditionalPanel": [Function], + "updateSearchResults": [Function], + "updater": Object { + "enqueueCallback": [Function], + "enqueueCallbackInternal": [Function], + "enqueueElementInternal": [Function], + "enqueueForceUpdate": [Function], + "enqueueReplaceState": [Function], + "enqueueSetState": [Function], + "isMounted": [Function], + "validateCallback": [Function], + }, + }, + "_mountOrder": 5, + "_pendingCallbacks": null, + "_pendingElement": null, + "_pendingForceUpdate": false, + "_pendingReplaceState": false, + "_pendingStateQueue": null, + "_renderedComponent": Object { + "_currentElement":
+ +
+ Array [] + +
, + "_debugID": 2, + "_renderedOutput":
+ +
+ Array [] + +
, + }, + "_renderedNodeType": 0, + "_rootNodeID": 0, + "_topLevelWrapper": null, + "_updateBatchNumber": null, + "_warnedAboutRefsInRender": false, + }, + "getRenderOutput": [Function], + "render": [Function], + }, + "root": [Circular], + "unrendered": , +} +`; diff --git a/src/components/Editor/tests/__snapshots__/SearchBar.js.snap b/src/components/Editor/tests/__snapshots__/SearchBar.js.snap new file mode 100644 index 0000000000..2fe12e5100 --- /dev/null +++ b/src/components/Editor/tests/__snapshots__/SearchBar.js.snap @@ -0,0 +1,436 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SearchBar should render 1`] = ` +ShallowWrapper { + "complexSelector": ComplexSelector { + "buildPredicate": [Function], + "childrenOfNode": [Function], + "findWhereUnwrapped": [Function], + }, + "length": 1, + "node":
+ +
+
+

+ Search for: +

+ + +
+
+ + + +
+
+
, + "nodes": Array [ +
+ +
+
+

+ Search for: +

+ + +
+
+ + + +
+
+
, + ], + "options": Object {}, + "renderer": ReactShallowRenderer { + "_instance": ShallowComponentWrapper { + "_calledComponentWillUnmount": false, + "_compositeType": 0, + "_context": Object {}, + "_currentElement": , + "_debugID": 1, + "_hostContainerInfo": null, + "_hostParent": null, + "_instance": SearchBar { + "_reactInternalInstance": [Circular], + "buildPlaceHolder": [Function], + "buildSummaryMsg": [Function], + "clearSearch": [Function], + "closeSearch": [Function], + "context": Object { + "shortcuts": undefined, + }, + "doSearch": [Function], + "onChange": [Function], + "onEscape": [Function], + "onKeyDown": [Function], + "onKeyUp": [Function], + "onSelectResultItem": [Function], + "props": Object { + "query": "", + "searchOn": true, + "searchResults": Array [], + "selectedResultIndex": 0, + }, + "refs": Object {}, + "renderBottomBar": [Function], + "renderResults": [Function], + "renderSearchModifiers": [Function], + "renderSearchTypeToggle": [Function], + "searchContents": [Function], + "searchInput": [Function], + "selectResultItem": [Function], + "selectSearchInput": [Function], + "setSearchValue": [Function], + "state": Object { + "count": 0, + "index": -1, + "selectedResultIndex": 0, + "symbolSearchResults": Array [], + }, + "toggleSearch": [Function], + "toggleSymbolSearch": [Function], + "traverseCodeResults": [Function], + "traverseResults": [Function], + "traverseSymbolResults": [Function], + "updateSymbolSearchResults": [Function], + "updater": Object { + "enqueueCallback": [Function], + "enqueueCallbackInternal": [Function], + "enqueueElementInternal": [Function], + "enqueueForceUpdate": [Function], + "enqueueReplaceState": [Function], + "enqueueSetState": [Function], + "isMounted": [Function], + "validateCallback": [Function], + }, + }, + "_mountOrder": 1, + "_pendingCallbacks": null, + "_pendingElement": null, + "_pendingForceUpdate": false, + "_pendingReplaceState": false, + "_pendingStateQueue": null, + "_renderedComponent": Object { + "_currentElement":
+ +
+
+

+ Search for: +

+ + +
+
+ + + +
+
+
, + "_debugID": 2, + "_renderedOutput":
+ +
+
+

+ Search for: +

+ + +
+
+ + + +
+
+
, + }, + "_renderedNodeType": 0, + "_rootNodeID": 0, + "_topLevelWrapper": null, + "_updateBatchNumber": null, + "_warnedAboutRefsInRender": false, + }, + "getRenderOutput": [Function], + "render": [Function], + }, + "root": [Circular], + "unrendered": , +} +`; From 13757d9b79173d16ba34da35dc88914bf4bc95e1 Mon Sep 17 00:00:00 2001 From: Yulia Startsev Date: Wed, 7 Jun 2017 14:35:27 +0200 Subject: [PATCH 2/8] basic component implementation --- src/components/Editor/SearchBar.js | 26 ++- src/components/Editor/tests/SearchBar.js | 14 +- .../tests/__snapshots__/SearchBar.js.snap | 192 ++---------------- 3 files changed, 44 insertions(+), 188 deletions(-) diff --git a/src/components/Editor/SearchBar.js b/src/components/Editor/SearchBar.js index f544ab65d3..a3dd358df8 100644 --- a/src/components/Editor/SearchBar.js +++ b/src/components/Editor/SearchBar.js @@ -11,6 +11,7 @@ import { getFileSearchState, getFileSearchQueryState, getFileSearchModifierState, + getSymbolSearchResults, getSymbolSearchState, getSymbolSearchType, getSelectedSource, @@ -98,6 +99,7 @@ class SearchBar extends Component { props: { editor?: SourceEditor, symbols: SymbolDeclarations, + symbolSearchResults: array, selectSource: (string, ?SelectSourceOptions) => any, selectedSource?: SourceRecord, highlightLineRange: ({ start: number, end: number }) => any, @@ -113,13 +115,13 @@ class SearchBar extends Component { setSelectedSymbolType: SymbolSearchType => any, query: string, setFileSearchQuery: string => any, - updateSearchResults: ({ count: number, index?: number }) => any + updateSearchResults: ({ count: number, index?: number }) => any, + updateSymbolSearchResults: ({ count: number, index?: number }) => any }; constructor(props) { super(props); this.state = { - symbolSearchResults: [], selectedResultIndex: 0, count: 0, index: -1 @@ -360,6 +362,7 @@ class SearchBar extends Component { const { selectedSource, updateSearchResults, + updateSymbolSearchResults, selectedSymbolType, symbols } = this.props; @@ -373,7 +376,7 @@ class SearchBar extends Component { }); updateSearchResults({ count: symbolSearchResults.length }); - return this.setState({ symbolSearchResults }); + updateSymbolSearchResults(symbolSearchResults); } doSearch(query: string) { @@ -543,8 +546,7 @@ class SearchBar extends Component { } onKeyDown(e: SyntheticKeyboardEvent) { - const { symbolSearchOn } = this.props; - const { symbolSearchResults } = this.state; + const { symbolSearchOn, symbolSearchResults } = this.props; if (!symbolSearchOn || this.props.query == "") { return; } @@ -571,14 +573,15 @@ class SearchBar extends Component { // Renderers buildSummaryMsg() { - if (this.props.symbolSearchOn) { - if (this.state.symbolSearchResults.length > 1) { + const { symbolSearchOn, symbolSearchResults } = this.props; + if (symbolSearchOn) { + if (symbolSearchResults.length > 1) { return L10N.getFormatStr( "editor.searchResults", this.state.selectedResultIndex + 1, - this.state.symbolSearchResults.length + symbolSearchResults.length ); - } else if (this.state.symbolSearchResults.length === 1) { + } else if (symbolSearchResults.length === 1) { return L10N.getFormatStr("editor.singleResult"); } } @@ -698,8 +701,8 @@ class SearchBar extends Component { } renderResults() { - const { symbolSearchResults, selectedResultIndex } = this.state; - const { query, symbolSearchOn } = this.props; + const { selectedResultIndex } = this.state; + const { query, symbolSearchResults, symbolSearchOn } = this.props; if (query == "" || !symbolSearchOn || !symbolSearchResults.length) { return; } @@ -764,6 +767,7 @@ export default connect( query: getFileSearchQueryState(state), modifiers: getFileSearchModifierState(state), symbolSearchOn: getSymbolSearchState(state), + symbolSearchResults: getSymbolSearchResults(state), symbols: _getFormattedSymbols(state), selectedSymbolType: getSymbolSearchType(state) }; diff --git a/src/components/Editor/tests/SearchBar.js b/src/components/Editor/tests/SearchBar.js index 5e230a161b..8989013ae2 100644 --- a/src/components/Editor/tests/SearchBar.js +++ b/src/components/Editor/tests/SearchBar.js @@ -8,7 +8,10 @@ function generateDefaults() { return { query: "", searchOn: true, - searchResults: [], + symbolSearchOn: true, + searchResults: {}, + selectedSymbolType: "functions", + symbolSearchResults: [], selectedResultIndex: 0 }; } @@ -26,10 +29,11 @@ describe("SearchBar", () => { expect(component).toMatchSnapshot(); }); - it("should have a result list with search results from the props", () => { - const searchResults = [1, 2, 3]; - const { component } = render({ searchResults }); + it("should have a result list with symbolSearchResults", () => { + const symbolSearchResults = [1, 2, 3]; + const query = "query"; + const { component } = render({ symbolSearchResults, query }); const resultList = component.find("ResultList"); - expect(resultList.prop("items")).toBe(searchResults); + expect(resultList.prop("items")).toBe(symbolSearchResults); }); }); diff --git a/src/components/Editor/tests/__snapshots__/SearchBar.js.snap b/src/components/Editor/tests/__snapshots__/SearchBar.js.snap index 2fe12e5100..d3e9bd1e54 100644 --- a/src/components/Editor/tests/__snapshots__/SearchBar.js.snap +++ b/src/components/Editor/tests/__snapshots__/SearchBar.js.snap @@ -19,7 +19,7 @@ ShallowWrapper { onChange={[Function]} onKeyDown={[Function]} onKeyUp={[Function]} - placeholder="Search in file…" + placeholder="Search functions…" query="" size="" summaryMsg="" @@ -36,7 +36,7 @@ ShallowWrapper { Search for: -
- - - -
, "nodes": Array [ @@ -102,7 +62,7 @@ ShallowWrapper { onChange={[Function]} onKeyDown={[Function]} onKeyUp={[Function]} - placeholder="Search in file…" + placeholder="Search functions…" query="" size="" summaryMsg="" @@ -119,7 +79,7 @@ ShallowWrapper { Search for: -
- - - -
, ], @@ -183,8 +103,11 @@ ShallowWrapper { "_currentElement": , "_debugID": 1, "_hostContainerInfo": null, @@ -207,8 +130,11 @@ ShallowWrapper { "props": Object { "query": "", "searchOn": true, - "searchResults": Array [], + "searchResults": Object {}, "selectedResultIndex": 0, + "selectedSymbolType": "functions", + "symbolSearchOn": true, + "symbolSearchResults": Array [], }, "refs": Object {}, "renderBottomBar": [Function], @@ -224,7 +150,6 @@ ShallowWrapper { "count": 0, "index": -1, "selectedResultIndex": 0, - "symbolSearchResults": Array [], }, "toggleSearch": [Function], "toggleSymbolSearch": [Function], @@ -261,7 +186,7 @@ ShallowWrapper { onChange={[Function]} onKeyDown={[Function]} onKeyUp={[Function]} - placeholder="Search in file…" + placeholder="Search functions…" query="" size="" summaryMsg="" @@ -278,7 +203,7 @@ ShallowWrapper { Search for: -
- - - -
, "_debugID": 2, @@ -344,7 +229,7 @@ ShallowWrapper { onChange={[Function]} onKeyDown={[Function]} onKeyUp={[Function]} - placeholder="Search in file…" + placeholder="Search functions…" query="" size="" summaryMsg="" @@ -361,7 +246,7 @@ ShallowWrapper { Search for: -
- - - -
, }, @@ -429,8 +274,11 @@ ShallowWrapper { "unrendered": , } `; From b4c360c4bed76233dbd63c4fa7c346f791ddfadc Mon Sep 17 00:00:00 2001 From: Yulia Startsev Date: Wed, 7 Jun 2017 14:41:00 +0200 Subject: [PATCH 3/8] remove searchResults from editor index --- src/components/Editor/index.js | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/components/Editor/index.js b/src/components/Editor/index.js index 5633725fc7..108b83c76a 100644 --- a/src/components/Editor/index.js +++ b/src/components/Editor/index.js @@ -86,13 +86,7 @@ const cssVars = { footerHeight: "var(--editor-footer-height)" }; -export type SearchResults = { - index: number, - count: number -}; - type EditorState = { - searchResults: SearchResults, highlightedLineRange: ?Object, selectedToken: ?HTMLElement }; @@ -113,10 +107,6 @@ class Editor extends PureComponent { this.lastJumpLine = null; this.state = { - searchResults: { - index: -1, - count: 0 - }, highlightedLineRange: null, selectedToken: null }; @@ -139,7 +129,6 @@ class Editor extends PureComponent { this ); self.toggleConditionalPanel = this.toggleConditionalPanel.bind(this); - self.updateSearchResults = this.updateSearchResults.bind(this); } componentWillReceiveProps(nextProps) { @@ -433,10 +422,6 @@ class Editor extends PureComponent { }); } - updateSearchResults({ count, index = -1 }: { count: number, index: number }) { - this.setState({ searchResults: { count, index } }); - } - onGutterClick(cm, line, gutter, ev) { const { selectedSource } = this.props; @@ -834,8 +819,6 @@ class Editor extends PureComponent { horizontal } = this.props; - const { searchResults } = this.state; - return dom.div( { className: classnames("editor-wrapper", { "coverage-on": coverageOn }) @@ -846,9 +829,7 @@ class Editor extends PureComponent { selectedSource, highlightLineRange, clearHighlightLineRange, - sourceText, - searchResults, - updateSearchResults: this.updateSearchResults + sourceText }), dom.div({ className: "editor-mount devtools-monospace", From 509a21b8bfb3775431815fa59fcb49eecfcec88a Mon Sep 17 00:00:00 2001 From: Yulia Startsev Date: Wed, 7 Jun 2017 14:59:32 +0200 Subject: [PATCH 4/8] add searchResults and SymbolSearchResults to the ui --- src/components/Editor/SearchBar.js | 3 ++ .../Editor/tests/__snapshots__/Editor.js.snap | 33 ------------------- src/reducers/tests/ui.js | 14 +++++++- src/reducers/ui.js | 19 +++++++++++ src/selectors.js | 2 ++ 5 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/components/Editor/SearchBar.js b/src/components/Editor/SearchBar.js index a3dd358df8..22457c016e 100644 --- a/src/components/Editor/SearchBar.js +++ b/src/components/Editor/SearchBar.js @@ -11,6 +11,7 @@ import { getFileSearchState, getFileSearchQueryState, getFileSearchModifierState, + getSearchResults, getSymbolSearchResults, getSymbolSearchState, getSymbolSearchType, @@ -703,6 +704,7 @@ class SearchBar extends Component { renderResults() { const { selectedResultIndex } = this.state; const { query, symbolSearchResults, symbolSearchOn } = this.props; + console.log("hi"); if (query == "" || !symbolSearchOn || !symbolSearchResults.length) { return; } @@ -768,6 +770,7 @@ export default connect( modifiers: getFileSearchModifierState(state), symbolSearchOn: getSymbolSearchState(state), symbolSearchResults: getSymbolSearchResults(state), + searchResults: getSearchResults(state), symbols: _getFormattedSymbols(state), selectedSymbolType: getSymbolSearchType(state) }; diff --git a/src/components/Editor/tests/__snapshots__/Editor.js.snap b/src/components/Editor/tests/__snapshots__/Editor.js.snap index 7211f7ab07..343ca60ad7 100644 --- a/src/components/Editor/tests/__snapshots__/Editor.js.snap +++ b/src/components/Editor/tests/__snapshots__/Editor.js.snap @@ -15,16 +15,9 @@ ShallowWrapper { clearHighlightLineRange={undefined} editor={null} highlightLineRange={undefined} - searchResults={ - Object { - "count": 0, - "index": -1, - } - } selectSource={undefined} selectedSource={undefined} sourceText={undefined} - updateSearchResults={[Function]} />
void) => void; declare var expect: (value: any) => any; import { prefs } from "../../utils/prefs"; -import update, { State } from "../ui"; +import update, { State, getSymbolSearchResults, getSearchResults } from "../ui"; describe("ui reducer", () => { it("toggle framework grouping to false", () => { @@ -28,4 +28,16 @@ describe("ui reducer", () => { expect(updatedState.frameworkGroupingOn).toBe(value); expect(prefs.frameworkGroupingOn).toBe(value); }); + + it("gets the search results", () => { + const state = State(); + expect(getSearchResults({ ui: state })).toBe(state.searchResults); + }); + + it("gets the symbol search results", () => { + const state = State(); + expect(getSymbolSearchResults({ ui: state })).toBe( + state.symbolSearchResults + ); + }); }); diff --git a/src/reducers/ui.js b/src/reducers/ui.js index 1f854284c4..a447324348 100644 --- a/src/reducers/ui.js +++ b/src/reducers/ui.js @@ -19,6 +19,11 @@ export type FileSearchModifiers = Record<{ export type SymbolSearchType = "functions" | "variables"; +export type SearchResults = { + index: number, + count: number +}; + export type UIState = { fileSearchOn: boolean, fileSearchQuery: string, @@ -26,6 +31,7 @@ export type UIState = { projectSearchOn: boolean, symbolSearchOn: boolean, symbolSearchType: SymbolSearchType, + searchResults: SearchResults, shownSource: string, startPanelCollapsed: boolean, endPanelCollapsed: boolean, @@ -49,6 +55,11 @@ export const State = makeRecord( projectSearchOn: false, symbolSearchOn: false, symbolSearchType: "functions", + symbolSearchResults: [], + searchResults: { + index: -1, + count: 0 + }, shownSource: "", startPanelCollapsed: prefs.startPanelCollapsed, endPanelCollapsed: prefs.endPanelCollapsed, @@ -157,6 +168,14 @@ export function getFileSearchModifierState( return state.ui.get("fileSearchModifiers"); } +export function getSymbolSearchResults(state: OuterState): string { + return state.ui.get("symbolSearchResults"); +} + +export function getSearchResults(state: OuterState): string { + return state.ui.get("searchResults"); +} + export function getFrameworkGroupingState(state: OuterState): boolean { return state.ui.get("frameworkGroupingOn"); } diff --git a/src/selectors.js b/src/selectors.js index 670395eb10..dcdb4b205e 100644 --- a/src/selectors.js +++ b/src/selectors.js @@ -58,6 +58,8 @@ module.exports = { getFileSearchState: ui.getFileSearchState, getFileSearchQueryState: ui.getFileSearchQueryState, getFileSearchModifierState: ui.getFileSearchModifierState, + getSymbolSearchResults: ui.getSymbolSearchResults, + getSearchResults: ui.getSearchResults, getFrameworkGroupingState: ui.getFrameworkGroupingState, getSymbolSearchState: ui.getSymbolSearchState, getSymbolSearchType: ui.getSymbolSearchType, From 1f57ed95f89addf7941bea1d623dd67c319df99b Mon Sep 17 00:00:00 2001 From: Yulia Startsev Date: Wed, 7 Jun 2017 16:39:28 +0200 Subject: [PATCH 5/8] finish functionality --- src/actions/ui.js | 14 ++++++++++++++ src/reducers/ui.js | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/actions/ui.js b/src/actions/ui.js index 168ada5e73..4d8a463851 100644 --- a/src/actions/ui.js +++ b/src/actions/ui.js @@ -79,6 +79,20 @@ export function setFileSearchQuery(query: string) { }; } +export function updateSearchResults(results: array) { + return { + type: "UPDATE_SEARCH_RESULTS", + results + }; +} + +export function updateSymbolSearchResults(results: array) { + return { + type: "UPDATE_SYMBOL_SEARCH_RESULTS", + results + }; +} + export function toggleFileSearchModifier(modifier: string) { return { type: "TOGGLE_FILE_SEARCH_MODIFIER", modifier }; } diff --git a/src/reducers/ui.js b/src/reducers/ui.js index a447324348..eb43f4fde9 100644 --- a/src/reducers/ui.js +++ b/src/reducers/ui.js @@ -94,6 +94,14 @@ function update( return state.set("fileSearchQuery", action.query); } + case "UPDATE_SEARCH_RESULTS": { + return state.set("searchResults", action.results); + } + + case "UPDATE_SYMBOL_SEARCH_RESULTS": { + return state.set("symbolSearchResults", action.results); + } + case "TOGGLE_FILE_SEARCH_MODIFIER": { const actionVal = !state.getIn(["fileSearchModifiers", action.modifier]); From a3f5a05d78033fd0244310b012fdd657ec9bf3c4 Mon Sep 17 00:00:00 2001 From: Yulia Startsev Date: Wed, 7 Jun 2017 17:52:31 +0200 Subject: [PATCH 6/8] fix flow typing errors --- src/actions/ui.js | 4 ++-- src/components/Editor/SearchBar.js | 9 ++++----- src/reducers/ui.js | 1 + 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/actions/ui.js b/src/actions/ui.js index 4d8a463851..9f5e5ebf20 100644 --- a/src/actions/ui.js +++ b/src/actions/ui.js @@ -79,14 +79,14 @@ export function setFileSearchQuery(query: string) { }; } -export function updateSearchResults(results: array) { +export function updateSearchResults(results: Object) { return { type: "UPDATE_SEARCH_RESULTS", results }; } -export function updateSymbolSearchResults(results: array) { +export function updateSymbolSearchResults(results: Array<*>) { return { type: "UPDATE_SYMBOL_SEARCH_RESULTS", results diff --git a/src/components/Editor/SearchBar.js b/src/components/Editor/SearchBar.js index 22457c016e..e3344881af 100644 --- a/src/components/Editor/SearchBar.js +++ b/src/components/Editor/SearchBar.js @@ -36,7 +36,7 @@ import { SourceEditor } from "devtools-source-editor"; import type { SourceRecord } from "../../reducers/sources"; import type { FileSearchModifiers, SymbolSearchType } from "../../reducers/ui"; import type { SelectSourceOptions } from "../../actions/sources"; -import type { SearchResults } from "."; +import type { SearchResults } from "../../reducers/ui"; import type { SymbolDeclarations } from "../../utils/parser/getSymbols"; import type { Location as BabelLocation } from "babel-traverse"; import _SearchInput from "../shared/SearchInput"; @@ -86,7 +86,6 @@ type ToggleSymbolSearchOpts = { }; type SearchBarState = { - symbolSearchResults: Array, selectedResultIndex: number, count: number, index: number @@ -100,7 +99,7 @@ class SearchBar extends Component { props: { editor?: SourceEditor, symbols: SymbolDeclarations, - symbolSearchResults: array, + symbolSearchResults: Array<*>, selectSource: (string, ?SelectSourceOptions) => any, selectedSource?: SourceRecord, highlightLineRange: ({ start: number, end: number }) => any, @@ -427,8 +426,8 @@ class SearchBar extends Component { } traverseSymbolResults(rev: boolean) { - const { symbolSearchResults, selectedResultIndex } = this.state; - const searchResults = symbolSearchResults; + const { selectedResultIndex } = this.state; + const searchResults = this.props.symbolSearchResults; const resultCount = searchResults.length; if (rev) { diff --git a/src/reducers/ui.js b/src/reducers/ui.js index eb43f4fde9..44e7ebbbac 100644 --- a/src/reducers/ui.js +++ b/src/reducers/ui.js @@ -32,6 +32,7 @@ export type UIState = { symbolSearchOn: boolean, symbolSearchType: SymbolSearchType, searchResults: SearchResults, + symbolSearchResults: Array<*>, shownSource: string, startPanelCollapsed: boolean, endPanelCollapsed: boolean, From e092d36ef259ead9c61ad4b6c0cbfd5fdf0eb7dc Mon Sep 17 00:00:00 2001 From: Yulia Startsev Date: Wed, 7 Jun 2017 18:18:15 +0200 Subject: [PATCH 7/8] address pr comments --- src/components/Editor/SearchBar.js | 1 - src/reducers/tests/ui.js | 14 +------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/components/Editor/SearchBar.js b/src/components/Editor/SearchBar.js index e3344881af..5dde329046 100644 --- a/src/components/Editor/SearchBar.js +++ b/src/components/Editor/SearchBar.js @@ -703,7 +703,6 @@ class SearchBar extends Component { renderResults() { const { selectedResultIndex } = this.state; const { query, symbolSearchResults, symbolSearchOn } = this.props; - console.log("hi"); if (query == "" || !symbolSearchOn || !symbolSearchResults.length) { return; } diff --git a/src/reducers/tests/ui.js b/src/reducers/tests/ui.js index d71be50f01..1c18a5c6b7 100644 --- a/src/reducers/tests/ui.js +++ b/src/reducers/tests/ui.js @@ -4,7 +4,7 @@ declare var it: (desc: string, func: () => void) => void; declare var expect: (value: any) => any; import { prefs } from "../../utils/prefs"; -import update, { State, getSymbolSearchResults, getSearchResults } from "../ui"; +import update, { State } from "../ui"; describe("ui reducer", () => { it("toggle framework grouping to false", () => { @@ -28,16 +28,4 @@ describe("ui reducer", () => { expect(updatedState.frameworkGroupingOn).toBe(value); expect(prefs.frameworkGroupingOn).toBe(value); }); - - it("gets the search results", () => { - const state = State(); - expect(getSearchResults({ ui: state })).toBe(state.searchResults); - }); - - it("gets the symbol search results", () => { - const state = State(); - expect(getSymbolSearchResults({ ui: state })).toBe( - state.symbolSearchResults - ); - }); }); From 727ab03b7cae018a19f1019c9649ee7a2ddd8808 Mon Sep 17 00:00:00 2001 From: Jason Laster Date: Wed, 7 Jun 2017 18:38:15 -0400 Subject: [PATCH 8/8] add some action tests --- src/actions/tests/ui.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/actions/tests/ui.js b/src/actions/tests/ui.js index 97cd51c8f7..47ce303adb 100644 --- a/src/actions/tests/ui.js +++ b/src/actions/tests/ui.js @@ -9,7 +9,9 @@ const { getPaneCollapse, getSymbolSearchState, getSymbolSearchType, - getHighlightedLineRange + getHighlightedLineRange, + getSearchResults, + getSymbolSearchResults } = selectors; describe("ui", () => { @@ -42,6 +44,24 @@ describe("ui", () => { expect(getFrameworkGroupingState(getState())).toBe(!currentState); }); + it("should update search results", () => { + const { dispatch, getState } = createStore(); + expect(getSearchResults(getState())).toEqual({ index: -1, count: 0 }); + + const results = { count: 3, index: 2 }; + dispatch(actions.updateSearchResults(results)); + expect(getSearchResults(getState())).toEqual(results); + }); + + fit("should update symbol search results", () => { + const { dispatch, getState } = createStore(); + expect(getSymbolSearchResults(getState())).toEqual([]); + + const results = [{ foo: "foo" }]; + dispatch(actions.updateSymbolSearchResults(results)); + expect(getSymbolSearchResults(getState())).toEqual(results); + }); + it("should close file search", () => { const { dispatch, getState } = createStore(); expect(getFileSearchState(getState())).toBe(false);