Skip to content

Commit

Permalink
Add test coverage for userReducer
Browse files Browse the repository at this point in the history
  • Loading branch information
testower committed Dec 18, 2024
1 parent 92c7a0d commit f6219a5
Showing 1 changed file with 248 additions and 0 deletions.
248 changes: 248 additions & 0 deletions src/test/reducers/user.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,37 @@ describe("user reducer", () => {
expect(userReducer(initialState, action)).toEqual(expectedState);
});

test("Should handle APOLLO_QUERY_RESULT for getLocationPermissions", () => {
const action = {
type: types.APOLLO_QUERY_RESULT,
operationName: "getLocationPermissions",
result: {
data: {
locationPermissions: {
allowedStopPlaceTypes: ["busStation", "railStation"],
allowedSubmodes: ["localBus", "railReplacementBus"],
bannedStopPlaceTypes: ["ferryStop"],
bannedSubmodes: ["touristRailway"],
canDelete: true,
canEdit: true,
},
},
},
};
const expectedState = {
...initialState,
locationPermissions: {
allowedStopPlaceTypes: ["busStation", "railStation"],
allowedSubmodes: ["localBus", "railReplacementBus"],
bannedStopPlaceTypes: ["ferryStop"],
bannedSubmodes: ["touristRailway"],
canDelete: true,
canEdit: true,
},
};
expect(userReducer(initialState, action)).toEqual(expectedState);
});

test("Should handle UPDATED_AUTH", () => {
const authData = {
token: "test-token",
Expand Down Expand Up @@ -259,5 +290,222 @@ describe("user reducer", () => {
};
expect(userReducer(stateWithQuayEdit, action)).toEqual(expectedState);
});

test("Should handle SHOW_EDIT_STOP_ADDITIONAL", () => {
const action = {
type: types.SHOW_EDIT_STOP_ADDITIONAL,
};
const expectedState = {
...initialState,
showEditStopAdditional: true,
};
expect(userReducer(initialState, action)).toEqual(expectedState);
});

test("Should handle HID_EDIT_STOP_ADDITIONAL", () => {
const stateWithStopEdit = {
...initialState,
showEditStopAdditional: true,
};
const action = {
type: types.HID_EDIT_STOP_ADDITIONAL,
};
const expectedState = {
...stateWithStopEdit,
showEditStopAdditional: false,
};
expect(userReducer(stateWithStopEdit, action)).toEqual(expectedState);
});

test("Should handle SET_FOCUS_ON_ELEMENT with positive index", () => {
const action = {
type: types.SET_FOCUS_ON_ELEMENT,
payload: { index: 1 },
};
const stateWithStopEdit = {
...initialState,
showEditStopAdditional: true,
};
const expectedState = {
...stateWithStopEdit,
showEditStopAdditional: false,
};
expect(userReducer(stateWithStopEdit, action)).toEqual(expectedState);
});

test("Should handle SET_FOCUS_ON_ELEMENT with negative index", () => {
const action = {
type: types.SET_FOCUS_ON_ELEMENT,
payload: { index: -1 },
};
const stateWithStopEdit = {
...initialState,
showEditStopAdditional: true,
};
expect(userReducer(stateWithStopEdit, action)).toEqual(stateWithStopEdit);
});

test("Should handle CHANGED_QUAY_ADDITIONAL_TAB", () => {
const action = {
type: types.CHANGED_QUAY_ADDITIONAL_TAB,
payload: 1,
};
const expectedState = {
...initialState,
activeQuayAdditionalTab: 1,
};
expect(userReducer(initialState, action)).toEqual(expectedState);
});
});

describe("key values dialog", () => {
test("Should handle OPENED_KEY_VALUES_DIALOG", () => {
const action = {
type: types.OPENED_KEY_VALUES_DIALOG,
payload: {
type: "quay",
index: 0,
},
};
const expectedState = {
...initialState,
keyValuesDialogOpen: true,
keyValuesOrigin: {
type: "quay",
index: 0,
},
};
expect(userReducer(initialState, action)).toEqual(expectedState);
});

test("Should handle CLOSED_KEY_VALUES_DIALOG", () => {
const stateWithDialog = {
...initialState,
keyValuesDialogOpen: true,
keyValuesOrigin: {
type: "quay",
index: 0,
},
};
const action = {
type: types.CLOSED_KEY_VALUES_DIALOG,
};
const expectedState = {
...stateWithDialog,
keyValuesDialogOpen: false,
};
expect(userReducer(stateWithDialog, action)).toEqual(expectedState);
});
});

describe("stop place management", () => {
test("Should handle SET_MISSING_COORDINATES", () => {
const action = {
type: types.SET_MISSING_COORDINATES,
payload: {
stopPlaceId: "NSR:StopPlace:1",
position: { lat: 60.1234, lng: 10.1234 },
},
};
const expectedState = {
...initialState,
missingCoordsMap: {
"NSR:StopPlace:1": { lat: 60.1234, lng: 10.1234 },
},
};
expect(userReducer(initialState, action)).toEqual(expectedState);
});

test("Should handle SHOW_CREATED_NEW_STOP_INFO", () => {
const action = {
type: types.SHOW_CREATED_NEW_STOP_INFO,
payload: "NSR:StopPlace:1",
};
const expectedState = {
...initialState,
newStopCreated: {
open: true,
stopPlaceId: "NSR:StopPlace:1",
},
};
expect(userReducer(initialState, action)).toEqual(expectedState);
});

test("Should handle HIDE_CREATED_NEW_STOP_INFO", () => {
const stateWithNewStop = {
...initialState,
newStopCreated: {
open: true,
stopPlaceId: "NSR:StopPlace:1",
},
};
const action = {
type: types.HIDE_CREATED_NEW_STOP_INFO,
};
const expectedState = {
...stateWithNewStop,
newStopCreated: {
open: false,
stopPlaceId: null,
},
};
expect(userReducer(stateWithNewStop, action)).toEqual(expectedState);
});

test("Should handle TERMINATE_DELETE_STOP_DIALOG_WARNING", () => {
const action = {
type: types.TERMINATE_DELETE_STOP_DIALOG_WARNING,
payload: {
warning: true,
stopPlaceId: "NSR:StopPlace:1",
},
};
const expectedState = {
...initialState,
deleteStopDialogWarning: {
warning: true,
stopPlaceId: "NSR:StopPlace:1",
},
};
expect(userReducer(initialState, action)).toEqual(expectedState);
});
});

describe("element management", () => {
test("Should handle ADDED_STOP_PLACE_ELEMENT for quay", () => {
const action = {
type: types.ADDED_STOP_PLACE_ELEMENT,
payload: { type: "quay" },
};
const expectedState = {
...initialState,
activeElementTab: 0,
};
expect(userReducer(initialState, action)).toEqual(expectedState);
});

test("Should handle ADDED_STOP_PLACE_ELEMENT for parkAndRide", () => {
const action = {
type: types.ADDED_STOP_PLACE_ELEMENT,
payload: { type: "parkAndRide" },
};
const expectedState = {
...initialState,
activeElementTab: 1,
};
expect(userReducer(initialState, action)).toEqual(expectedState);
});

test("Should handle CHANGED_ELEMENT_TYPE_TAB", () => {
const action = {
type: types.CHANGED_ELEMENT_TYPE_TAB,
payload: 1,
};
const expectedState = {
...initialState,
activeElementTab: 1,
};
expect(userReducer(initialState, action)).toEqual(expectedState);
});
});
});

0 comments on commit f6219a5

Please sign in to comment.