From de8c5df3deb884e6d55e8f72f92313fd28ff1250 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Sat, 24 Feb 2018 09:24:30 +0100 Subject: [PATCH 1/5] feat(fn): OpsFilter as a filter function plugin --- src/core/components/operations.jsx | 10 +++++----- src/core/plugins/filter/OpsFilter.js | 3 +++ src/core/plugins/filter/index.js | 9 +++++++++ src/core/presets/base.js | 4 +++- 4 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 src/core/plugins/filter/OpsFilter.js create mode 100644 src/core/plugins/filter/index.js diff --git a/src/core/components/operations.jsx b/src/core/components/operations.jsx index 660542e56e3..4a886abc104 100644 --- a/src/core/components/operations.jsx +++ b/src/core/components/operations.jsx @@ -21,7 +21,8 @@ export default class Operations extends React.Component { layoutActions: PropTypes.object.isRequired, authActions: PropTypes.object.isRequired, authSelectors: PropTypes.object.isRequired, - getConfigs: PropTypes.func.isRequired + getConfigs: PropTypes.func.isRequired, + fn: PropTypes.func.isRequired }; render() { @@ -30,7 +31,8 @@ export default class Operations extends React.Component { getComponent, layoutSelectors, layoutActions, - getConfigs + getConfigs, + fn } = this.props let taggedOps = specSelectors.taggedOperations() @@ -52,9 +54,7 @@ export default class Operations extends React.Component { if (filter) { if (filter !== true) { - taggedOps = taggedOps.filter((tagObj, tag) => { - return tag.indexOf(filter) !== -1 - }) + taggedOps = fn.OpsFilter(taggedOps, filter); } } diff --git a/src/core/plugins/filter/OpsFilter.js b/src/core/plugins/filter/OpsFilter.js new file mode 100644 index 00000000000..fecf262f40d --- /dev/null +++ b/src/core/plugins/filter/OpsFilter.js @@ -0,0 +1,3 @@ +export default function(taggedOps, phrase) { + return taggedOps.filter((tagObj, tag) => tag.indexOf(phrase) !== -1) +} diff --git a/src/core/plugins/filter/index.js b/src/core/plugins/filter/index.js new file mode 100644 index 00000000000..da4e064731f --- /dev/null +++ b/src/core/plugins/filter/index.js @@ -0,0 +1,9 @@ +import OpsFilter from "./OpsFilter" + +export default function() { + return { + fn: { + OpsFilter + } + } +} diff --git a/src/core/presets/base.js b/src/core/presets/base.js index 65bf891e8f2..de5a34da750 100644 --- a/src/core/presets/base.js +++ b/src/core/presets/base.js @@ -12,6 +12,7 @@ import SplitPaneModePlugin from "core/plugins/split-pane-mode" import downloadUrlPlugin from "core/plugins/download-url" import configsPlugin from "core/plugins/configs" import deepLinkingPlugin from "core/plugins/deep-linking" +import filter from "core/plugins/filter" import OperationContainer from "core/containers/OperationContainer" @@ -152,6 +153,7 @@ export default function() { ast, SplitPaneModePlugin, downloadUrlPlugin, - deepLinkingPlugin + deepLinkingPlugin, + filter ] } From da4042f8dc8ac59174004b1ebe304de5053bf0e2 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Sat, 24 Feb 2018 09:42:27 +0100 Subject: [PATCH 2/5] fix(unitTest): OpsFilter unit test, also lint fix for extra semicolon --- src/core/components/operations.jsx | 2 +- test/core/plugins/filter/OpsFilter.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/core/plugins/filter/OpsFilter.js diff --git a/src/core/components/operations.jsx b/src/core/components/operations.jsx index 4a886abc104..c9add367a14 100644 --- a/src/core/components/operations.jsx +++ b/src/core/components/operations.jsx @@ -54,7 +54,7 @@ export default class Operations extends React.Component { if (filter) { if (filter !== true) { - taggedOps = fn.OpsFilter(taggedOps, filter); + taggedOps = fn.OpsFilter(taggedOps, filter) } } diff --git a/test/core/plugins/filter/OpsFilter.js b/test/core/plugins/filter/OpsFilter.js new file mode 100644 index 00000000000..16910904336 --- /dev/null +++ b/test/core/plugins/filter/OpsFilter.js @@ -0,0 +1,13 @@ +import { Map } from "immutable" +import OpsFilter from "corePlugins/filter/OpsFilter" +import expect from "expect" + +describe("OpsFilter", function() { + it("should filter taggedOps by tag name", function () { + const taggedOps = Map([["pet"], ["store"], ["user"]]) + + const filtered = OpsFilter(taggedOps, "sto") + + expect(filtered.size).toEqual(1) + }) +}) From 1263b2ed83bcbfa67f31c5bb5e4561f79199ea3c Mon Sep 17 00:00:00 2001 From: davidvujic Date: Sat, 24 Feb 2018 15:40:11 +0100 Subject: [PATCH 3/5] fix(edgeCases): added unit tests after PR feedback --- test/core/plugins/filter/OpsFilter.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/core/plugins/filter/OpsFilter.js b/test/core/plugins/filter/OpsFilter.js index 16910904336..b959495b0e1 100644 --- a/test/core/plugins/filter/OpsFilter.js +++ b/test/core/plugins/filter/OpsFilter.js @@ -3,11 +3,23 @@ import OpsFilter from "corePlugins/filter/OpsFilter" import expect from "expect" describe("OpsFilter", function() { - it("should filter taggedOps by tag name", function () { - const taggedOps = Map([["pet"], ["store"], ["user"]]) + const taggedOps = Map([["pet"], ["store"], ["user"]]) + it("should filter taggedOps by tag name", function () { const filtered = OpsFilter(taggedOps, "sto") expect(filtered.size).toEqual(1) }) + + it("should return all taggedOps when search phrase is empty", function () { + const filtered = OpsFilter(taggedOps, "") + + expect(filtered.size).toEqual(taggedOps.size) + }) + + it("should return empty result when there is no match", function () { + const filtered = OpsFilter(taggedOps, "NoMatch") + + expect(filtered.size).toEqual(0) + }) }) From b65921fd223e70956f8f53c0bf65f8df175bf89c Mon Sep 17 00:00:00 2001 From: davidvujic Date: Tue, 27 Feb 2018 20:31:08 +0100 Subject: [PATCH 4/5] fix(naming): camelCase --- src/core/components/operations.jsx | 2 +- src/core/plugins/filter/index.js | 4 ++-- src/core/plugins/filter/{OpsFilter.js => opsFilter.js} | 0 .../core/plugins/filter/{OpsFilter.js => opsFilter.js} | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) rename src/core/plugins/filter/{OpsFilter.js => opsFilter.js} (100%) rename test/core/plugins/filter/{OpsFilter.js => opsFilter.js} (66%) diff --git a/src/core/components/operations.jsx b/src/core/components/operations.jsx index c9add367a14..6bc4030e101 100644 --- a/src/core/components/operations.jsx +++ b/src/core/components/operations.jsx @@ -54,7 +54,7 @@ export default class Operations extends React.Component { if (filter) { if (filter !== true) { - taggedOps = fn.OpsFilter(taggedOps, filter) + taggedOps = fn.opsFilter(taggedOps, filter) } } diff --git a/src/core/plugins/filter/index.js b/src/core/plugins/filter/index.js index da4e064731f..e7f37c92b83 100644 --- a/src/core/plugins/filter/index.js +++ b/src/core/plugins/filter/index.js @@ -1,9 +1,9 @@ -import OpsFilter from "./OpsFilter" +import opsFilter from "./opsFilter" export default function() { return { fn: { - OpsFilter + opsFilter } } } diff --git a/src/core/plugins/filter/OpsFilter.js b/src/core/plugins/filter/opsFilter.js similarity index 100% rename from src/core/plugins/filter/OpsFilter.js rename to src/core/plugins/filter/opsFilter.js diff --git a/test/core/plugins/filter/OpsFilter.js b/test/core/plugins/filter/opsFilter.js similarity index 66% rename from test/core/plugins/filter/OpsFilter.js rename to test/core/plugins/filter/opsFilter.js index b959495b0e1..ef15468c367 100644 --- a/test/core/plugins/filter/OpsFilter.js +++ b/test/core/plugins/filter/opsFilter.js @@ -1,24 +1,24 @@ import { Map } from "immutable" -import OpsFilter from "corePlugins/filter/OpsFilter" +import opsFilter from "corePlugins/filter/opsFilter" import expect from "expect" -describe("OpsFilter", function() { +describe("opsFilter", function() { const taggedOps = Map([["pet"], ["store"], ["user"]]) it("should filter taggedOps by tag name", function () { - const filtered = OpsFilter(taggedOps, "sto") + const filtered = opsFilter(taggedOps, "sto") expect(filtered.size).toEqual(1) }) it("should return all taggedOps when search phrase is empty", function () { - const filtered = OpsFilter(taggedOps, "") + const filtered = opsFilter(taggedOps, "") expect(filtered.size).toEqual(taggedOps.size) }) it("should return empty result when there is no match", function () { - const filtered = OpsFilter(taggedOps, "NoMatch") + const filtered = opsFilter(taggedOps, "NoMatch") expect(filtered.size).toEqual(0) }) From 7edb0313e4c9fe5a09cdaedaec15df78136c8fc7 Mon Sep 17 00:00:00 2001 From: davidvujic Date: Tue, 27 Feb 2018 21:12:07 +0100 Subject: [PATCH 5/5] fix(unitTest): pass fn to system and use opsFilter by system reference --- test/core/system/system.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/core/system/system.js b/test/core/system/system.js index 24bfbf8ad48..69e184885af 100644 --- a/test/core/system/system.js +++ b/test/core/system/system.js @@ -5,6 +5,7 @@ import System from "core/system" import { fromJS } from "immutable" import { render } from "enzyme" import ViewPlugin from "core/plugins/view/index.js" +import filterPlugin from "core/plugins/filter/index.js" import { connect, Provider } from "react-redux" describe("bound system", function(){ @@ -264,6 +265,22 @@ describe("bound system", function(){ }) + describe("fn", function() { + + it("should return helper functions", function () { + // Given + const system = new System({ + plugins: [ + filterPlugin + ] + }) + + // When + const fn = system.getSystem().fn.opsFilter + expect(typeof fn).toEqual("function") + }) + }) + describe("selectors", function(){ it("should have the first arg be the nested state, and all other args to follow", function(){