Fix failing tests related to point group auto_sync

pull/1492/head
Rick Carlino 2019-10-07 16:09:36 -05:00
parent 961d47dbd6
commit fe52fedaf5
5 changed files with 21 additions and 18 deletions

View File

@ -3,7 +3,6 @@ class PointGroup < ApplicationRecord
%w(xy_ascending xy_descending yx_ascending yx_descending random).sort
BAD_SORT = "%{value} is not valid. Valid options are: " +
SORT_TYPES.map(&:inspect).join(", ")
DONT_BROADCAST = ApplicationRecord::DONT_BROADCAST.without("updated_at")
belongs_to :device
has_many :point_group_items, dependent: :destroy

View File

@ -73,6 +73,7 @@ module Points
# a fresh session_id, the frontend will
# think it is an "echo" and cancel it out.
# """ - Rick
x.update_attributes!(updated_at: Time.now)
x.broadcast!(SecureRandom.uuid)
end
end

View File

@ -1,5 +1,8 @@
jest.mock("../../../api/crud", () => {
return { initSave: jest.fn(() => () => Promise.resolve({})) };
return {
init: jest.fn(() => ({ payload: { uuid: "???" } })),
save: jest.fn()
};
});
jest.mock("../../../history", () => {
@ -8,8 +11,13 @@ jest.mock("../../../history", () => {
};
});
jest.mock("../../../resources/selectors", () => ({
findPointGroup: jest.fn(() => ({ body: { id: 323232332 } })),
selectAllRegimens: jest.fn()
}));
import { createGroup } from "../actions";
import { initSave } from "../../../api/crud";
import { init, save } from "../../../api/crud";
import { history } from "../../../history";
import { buildResourceIndex } from "../../../__test_support__/resource_index_builder";
import { fakePoint, fakePlant, fakeToolSlot } from "../../../__test_support__/fake_state/resources";
@ -26,12 +34,13 @@ describe("group action creators and thunks", () => {
const thunk = createGroup({ points, name: "Name123" });
await thunk(dispatch, () => fakeS as Everything);
const expected = ["PointGroup", {
expect(init).toHaveBeenCalledWith("PointGroup", {
name: "Name123",
point_ids: [0, 1].map(x => fakePoints[x].body.id)
}];
const xz = initSave;
expect(xz).toHaveBeenCalledWith(...expected);
expect(history.push).toHaveBeenCalledWith("/app/designer/groups");
point_ids: [1, 2],
sort_type: "xy_ascending"
});
expect(save).toHaveBeenCalledWith("???");
expect(history.push)
.toHaveBeenCalledWith("/app/designer/groups/323232332");
});
});

View File

@ -13,10 +13,6 @@ interface CreateGroupProps {
name?: string;
}
/** This probably won't work as a long term
* solution because it won't add points created
* during the current user session (localId of 0)
*/
export const createGroup = ({ points, name }: CreateGroupProps) => {
return function (dispatch: Function, getState: GetState) {
const { references } = getState().resources.index;
@ -24,10 +20,8 @@ export const createGroup = ({ points, name }: CreateGroupProps) => {
.map(x => references[x])
.map(x => x ? x.body.id : undefined);
const point_ids = betterCompact(possiblyNil);
const group: PointGroup = ({
name: name || UNTITLED, point_ids,
sort_type: "xy_ascending"
});
const group: PointGroup =
({ name: name || UNTITLED, point_ids, sort_type: "xy_ascending" });
const action = init("PointGroup", group);
dispatch(action);
return dispatch(save(action.payload.uuid)).then(() => {

View File

@ -36,7 +36,7 @@ describe("convertDDItoDeclaration()", () => {
kind: "parameter_application",
args: {
label: "Y",
data_value: { kind: "point_group", args: { resource_id: 23 } }
data_value: { kind: "point_group", args: { point_group_id: 23 } }
}
});
});