aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/js')
-rw-r--r--web/src/js/__tests__/ducks/utils/storeSpec.js86
-rw-r--r--web/src/js/ducks/ui/flow.js8
-rw-r--r--web/src/js/filt/filt.peg2
3 files changed, 91 insertions, 5 deletions
diff --git a/web/src/js/__tests__/ducks/utils/storeSpec.js b/web/src/js/__tests__/ducks/utils/storeSpec.js
new file mode 100644
index 00000000..6bfea2c7
--- /dev/null
+++ b/web/src/js/__tests__/ducks/utils/storeSpec.js
@@ -0,0 +1,86 @@
+jest.unmock('../../../ducks/utils/store')
+
+import reduceStore, * as storeActions from '../../../ducks/utils/store'
+
+describe('store reducer', () => {
+ it('should return initial state', () => {
+ expect(reduceStore(undefined, {})).toEqual({
+ byId: {},
+ list: [],
+ listIndex: {},
+ view: [],
+ viewIndex: {},
+ })
+ })
+
+ it('should handle add action', () => {
+ let a = {id: 1},
+ b = {id: 9},
+ state = reduceStore(undefined, {})
+ expect(state = reduceStore(state, storeActions.add(a))).toEqual({
+ byId: { 1: a },
+ listIndex: { 1: 0 },
+ list: [ a ],
+ view: [ a ],
+ viewIndex: { 1: 0 },
+ })
+
+ expect(reduceStore(state, storeActions.add(b))).toEqual({
+ byId: { 1: a, 9: b },
+ listIndex: { 1: 0, 9: 1 },
+ list: [ a, b ],
+ view: [ a, b ],
+ viewIndex: { 1: 0, 9: 1 },
+ })
+ })
+
+ it('should not add the item with duplicated id', () => {
+ let a = {id: 1},
+ state = reduceStore(undefined, storeActions.add(a))
+ expect(reduceStore(state, storeActions.add(a))).toEqual(state)
+ })
+
+ it('should handle update action', () => {
+ let a = {id: 1, foo: "foo"},
+ updated = {...a, foo: "bar"},
+ state = reduceStore(undefined, storeActions.add(a))
+ expect(reduceStore(state, storeActions.update(updated))).toEqual({
+ byId: { 1: updated },
+ list: [ updated ],
+ listIndex: { 1: 0 },
+ view: [ updated ],
+ viewIndex: { 1: 0 },
+ })
+ })
+
+ it('should handle update action with filter', () => {
+ let a = {id: 0},
+ b = {id: 1},
+ state = reduceStore(undefined, storeActions.add(a))
+ state = reduceStore(state, storeActions.add(b))
+ expect(reduceStore(state, storeActions.update(b,
+ item => {return item.id < 1}))).toEqual({
+ byId: { 0: a, 1: b },
+ list: [ a, b ],
+ listIndex: { 0: 0, 1: 1 },
+ view: [ a ],
+ viewIndex: { 0: 0 }
+ })
+ })
+
+ it('should handle update action with sort', () => {
+ let a = {id: 2},
+ b = {id: 3},
+ state = reduceStore(undefined, storeActions.add(a))
+ state = reduceStore(state, storeActions.add(b))
+ expect(reduceStore(state, storeActions.update(a, undefined,
+ (a, b) => {return b.id - a.id}))).toEqual({
+ // sort by id in descending order
+ byId: { 2: a, 3: b },
+ list: [ a, b ],
+ listIndex: {2: 0, 3: 1},
+ view: [ b, a ],
+ viewIndex: { 2: 1, 3: 0 },
+ })
+ })
+})
diff --git a/web/src/js/ducks/ui/flow.js b/web/src/js/ducks/ui/flow.js
index 8cb6e170..ba604ea2 100644
--- a/web/src/js/ducks/ui/flow.js
+++ b/web/src/js/ducks/ui/flow.js
@@ -60,7 +60,7 @@ export default function reducer(state = defaultState, action) {
// There is no explicit "stop edit" event.
// We stop editing when we receive an update for
// the currently edited flow from the server
- if (action.flow.id === state.modifiedFlow.id) {
+ if (action.data.id === state.modifiedFlow.id) {
return {
...state,
modifiedFlow: false,
@@ -148,7 +148,7 @@ export function setContent(content){
return { type: SET_CONTENT, content }
}
-export function stopEdit(flow, modifiedFlow) {
- let diff = getDiff(flow, modifiedFlow)
- return {type: flowsActions.UPDATE, flow, diff }
+export function stopEdit(data, modifiedFlow) {
+ let diff = getDiff(data, modifiedFlow)
+ return {type: flowsActions.UPDATE, data, diff }
}
diff --git a/web/src/js/filt/filt.peg b/web/src/js/filt/filt.peg
index b2576661..12959474 100644
--- a/web/src/js/filt/filt.peg
+++ b/web/src/js/filt/filt.peg
@@ -96,7 +96,7 @@ function responseBody(regex){
function domain(regex){
regex = new RegExp(regex, "i");
function domainFilter(flow){
- return flow.request && regex.test(flow.request.host);
+ return flow.request && (regex.test(flow.request.host) || regex.test(flow.request.pretty_host));
}
domainFilter.desc = "domain matches " + regex;
return domainFilter;