{"size": 3288, "ext": "js", "max_stars_repo_path": "src/pivotGrid/actions/configuration.action.test.js", "max_stars_repo_name": "polluxparis/zebulon-grid", "max_stars_repo_stars_event_min_datetime": "2017-10-31T09:40:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-22T08:26:22.000Z", "max_issues_repo_path": "src/pivotGrid/actions/configuration.action.test.js", "max_issues_repo_name": "polluxparis/zebulon-grid", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/pivotGrid/actions/configuration.action.test.js", "max_forks_repo_name": "polluxparis/zebulon-grid", "max_forks_repo_forks_event_min_datetime": "2018-10-31T17:02:46.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-28T07:19:27.000Z"}
{"max_stars_count": 12, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 21.7748344371, "max_line_length": 87, "alphanum_fraction": 0.4847931873}
import {
  SET_DIMENSIONS,
  SET_MEASURES,
  SET_CONFIG_PROPERTY,
  TOGGLE_MEASURE,
  MOVE_DIMENSION
} from "../constants";
import {
  setConfigurationProperty,
  toggleMeasure,
  moveDimension,
  setDimensions,
  setMeasures
} from "./configuration.action";

describe("setConfigurationProperty creates an action to set a config property", () => {
  test("when a property  value is given", () => {
    const configObject = { toto: 33 };
    expect(setConfigurationProperty(configObject, "toto", 666)).toEqual({
      type: SET_CONFIG_PROPERTY,
      property: "toto",
      value: 33
    });
  });
  test("when no property  value is given", () => {
    const configObject = {};
    expect(setConfigurationProperty(configObject, "toto", 666)).toEqual({
      type: SET_CONFIG_PROPERTY,
      property: "toto",
      value: 666
    });
  });
});

describe("toggleMeasure create correct action", () => {
  test("in normal case", () => {
    expect(toggleMeasure("toto")).toEqual({
      type: TOGGLE_MEASURE,
      id: "toto"
    });
  });
});

describe("moveDimension creates correct action", () => {
  test("in normal case", () => {
    expect(moveDimension("toto", "dimensions", "rows", 0)).toEqual({
      type: MOVE_DIMENSION,
      id: "toto",
      oldAxis: "dimensions",
      newAxis: "rows",
      position: 0
    });
  });
});

describe("setDimensions creates correct action", () => {
  test("with three dimensions", () => {
    const dimensions = [
      {
        name: "toto_lb",
        accessor: "toto",
        caption: "Toto",
        sort: {
          order: "asc"
        }
      },
      {
        accessor: "titi",
        caption: "Titi"
      },
      {
        accessor: "tutu",
        caption: "Tutu"
      }
    ];
    expect(setDimensions({ dimensions })).toMatchObject({
      type: SET_DIMENSIONS,
      dimensions: [
        {
          id: "toto",
          name: "toto_lb",
          caption: "Toto",
          sort: {
            order: "asc"
          },
          subTotal: {}
        },
        {
          id: "titi",
          name: "titi",
          caption: "Titi",
          sort: {
            order: null
          },
          subTotal: {}
        },
        {
          id: "tutu",
          name: "tutu",
          caption: "Tutu",
          sort: {
            order: null
          },
          subTotal: {}
        }
      ]
    });
  });
});

describe("setMeasures creates correct action", () => {
  test("with two measures", () => {
    const measures = [
      {
        accessor: "qty",
        caption: "Quantity",
        aggregation: "sum"
      },
      {
        accessor: "amt",
        caption: "Amount",
        aggregation: "sum",
        aggregationName: "whatever",
        render: value => {
          if (value || value === 0) {
            return `${Number(value).toFixed(0)} $`;
          }
          return "";
        }
      }
    ];
    expect(setMeasures({ measures })).toMatchObject({
      type: SET_MEASURES,
      measures: [
        {
          id: "qty",
          name: "qty",
          caption: "Quantity",
          aggregationName: "sum"
        },
        {
          id: "amt",
          name: "amt",
          caption: "Amount",
          aggregationName: "whatever"
        }
      ]
    });
  });
});
