import {stackToHash, hashToStack} from "./helpers";

describe('panel helpers', () => {
  test('stackToHash', () => {
    const stack = [
      { type: 'a', payload: { a: 1 }, isCollapsed: false },
      { type: 'b', payload: { b: 2 }, isCollapsed: true },
      { type: 'c', payload: { c: 3 }, isCollapsed: false }
    ];
    expect(stackToHash(stack)).toBe('a!={"a":1}&b={"b":2}&c!={"c":3}');
  });
  test('hashToStack', () => {
    const stack = [
      { type: 'a', payload: { a: 1 }, isCollapsed: false },
      { type: 'b', payload: { b: 2 }, isCollapsed: true },
      { type: 'c', payload: { c: 3 }, isCollapsed: false }
    ];
    expect(hashToStack('a!={"a":1}&b={"b":2}&c!={"c":3}')).toEqual(stack);
    expect(hashToStack('a!={"a')).toEqual([
      {
        "isCollapsed": false,
        "payload": {},
        "type": "a"
      }
    ]);
  });
});
