import { taggingMiddleware } from '../../miq-redux/middleware'; //this is your middleware
// const next = jest.fn(); // middleware needs those as parameters, usually calling next(action) at the end to proceed
// const store = jest.fn();


it('passes the intercepted action to next', () => {

  const next = jest.fn(); // middleware needs those as parameters, usually calling next(action) at the end to proceed
  const store = jest.fn();
  const spy = jest.spyOn(window.$, 'post')
  const action = { type: 'ACTION_TYPE', payload: { data: 'test' }}
  taggingMiddleware(store)(next)(action);
  expect(next.mock.calls).toEqual([[{'payload': { data: 'test'}, type: 'ACTION_TYPE'}]]);
  expect(spy.mock.calls).toEqual([]);
});


it('calls post for UI-COMPONENTS_TAGGING_TOGGLE_TAG_VALUE_CHANGE action', () => {

  const next = jest.fn(); // middleware needs those as parameters, usually calling next(action) at the end to proceed
  const spy = jest.spyOn(window.$, 'post')
  const store = {
    getState: () => ({
      tagging: {
        appState: {
          affectedItems: [{}],
          assignedTags: []
        }
      }
    })
  };
  const action = { type: 'UI-COMPONENTS_TAGGING_TOGGLE_TAG_VALUE_CHANGE', meta: { url: 'url/bla', params: jest.fn() }, tag: {tagCategory: {id: 1}, tagValue: { id:2 }}}
  taggingMiddleware(store)(next)(action);
  expect(next.mock.calls).toEqual( [[{"meta": {"url": "url/bla", "params": jest.fn()}, "tag": {"tagCategory": {"id": 1}, "tagValue": {"id": 2}}, "type": "UI-COMPONENTS_TAGGING_TOGGLE_TAG_VALUE_CHANGE"}]]);
  expect(spy).toHaveBeenCalledWith("url/bla", {"cat": 1, "check": 1, "id": {}, "tree_typ": "tags", "val": 2});
});


it('calls post for UI-COMPONENTS_TAGGING_DELETE_ASSIGNED_TAG action', () => {

  const next = jest.fn(); // middleware needs those as parameters, usually calling next(action) at the end to proceed
  const spy = jest.spyOn(window.$, 'post')
  const store = {
    getState: () => ({
      tagging: {
        appState: {
          affectedItems: [{}]
        }
      }
    })
  };
  const action = { type: 'UI-COMPONENTS_TAGGING_DELETE_ASSIGNED_TAG', meta: { url: 'url/bla' }, tag: {tagCategory: {id: 1}, tagValue: { id:2 }}};
  taggingMiddleware(store)(next)(action);
  expect(next.mock.calls).toEqual( [[{"meta": {"url": "url/bla"}, "tag": {"tagCategory": {"id": 1}, "tagValue": {"id": 2}}, "type": 'UI-COMPONENTS_TAGGING_DELETE_ASSIGNED_TAG'}]]);
  expect(spy).toHaveBeenCalledWith("url/bla", {"cat": 1, "check": 0, "id": {}, "tree_typ": "tags", "val": 2});
});

@@ -227,24 +227,337 @@
 jest.fn();%0A%0A
+const params = (type = 'default', state, tag = %7B%7D) =%3E (%7B%0A  provision: %7B%0A    id: %22new%22,%0A    ids_checked: %5B%5D,%0A    tree_typ: 'tags'%0A  %7D,%0A  default: %7B%0A    id: %5B%5D,%0A    cat: tag.tagCategory.id,%0A    val: tag.tagValue.id,%0A    check: 1,%0A    tree_typ: 'tags'%0A  %7D%0A%7D)%5Btype%5D%0A%0Aconst onDelete = (x, y, z) =%3E (%7B...y, check: 0%7D);%0A
 %0Ait('passes 
@@ -1545,25 +1545,22 @@
 params: 
-jest.fn()
+params
  %7D, tag:
@@ -1721,25 +1721,22 @@
 arams%22: 
-jest.fn()
+params
 %7D, %22tag%22
@@ -1916,34 +1916,34 @@
 heck%22: 1, %22id%22: 
-%7B%7D
+%5B%5D
 , %22tree_typ%22: %22t
@@ -2436,16 +2436,69 @@
 url/bla'
+, params: params, onDelete: onDelete, type: 'default'
  %7D, tag:
@@ -2648,16 +2648,69 @@
 url/bla%22
+, params: params, onDelete: onDelete, type: 'default'
 %7D, %22tag%22
@@ -2894,18 +2894,18 @@
 , %22id%22: 
-%7B%7D
+%5B%5D
 , %22tree_

Update midleware specs for tagging