Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHI-2223: Unsaved confirm dialog on close POC #1758

Merged
merged 8 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ const hrmState: Partial<RootState[typeof namespace]> = {
},
},
[contactFormsBase]: {
editingContact: false,
isCallTypeCaller: false,
contactDetails: { contactSearch: { detailsExpanded: {} }, caseDetails: { detailsExpanded: {} } },
existingContacts: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ describe('View Contact', () => {
},
},
activeContacts: {
editingContact: false,
isCallTypeCaller: false,
existingContacts: {
TEST_ID: {
Expand Down
307 changes: 307 additions & 0 deletions plugin-hrm-form/src/___tests__/states/routing/getRoute.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,307 @@
/**
* Copyright (C) 2021-2023 Technology Matters
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

import each from 'jest-each';

import { AppRoutes, CaseItemAction, RoutingState } from '../../../states/routing/types';
import { standaloneTaskSid } from '../../../types/types';
import { initialState } from '../../../states/routing/reducer';
import {
getCurrentBaseRoute,
getCurrentTopmostRouteForTask,
getCurrentTopmostRouteStackForTask,
} from '../../../states/routing/getRoute';

type TestCase<T extends AppRoutes | AppRoutes[]> = {
state: RoutingState;
expected: T;
description: string;
};

const stateWithRouteStack = (baseRoutes: AppRoutes[]): RoutingState => ({
tasks: {
1: baseRoutes,
[standaloneTaskSid]: initialState.tasks[standaloneTaskSid],
},
isAddingOfflineContact: false,
});

describe('getCurrentTopmostRouteStackForTask', () => {
const testCases: TestCase<AppRoutes[]>[] = [
{
description: 'No modals open - should return the base route a task',
state: stateWithRouteStack([
{ route: 'case-list', subroute: 'case-list' },
{ route: 'case', subroute: 'home' },
]),
expected: [
{ route: 'case-list', subroute: 'case-list' },
{ route: 'case', subroute: 'home' },
],
},
{
description: 'Modal open - should return the modal route',
state: stateWithRouteStack([
{
route: 'case-list',
subroute: 'case-list',
activeModal: [
{ route: 'case', subroute: 'home' },
{ route: 'case', subroute: 'caseSummary', action: CaseItemAction.View, id: '' },
],
},
]),
expected: [
{ route: 'case', subroute: 'home' },
{ route: 'case', subroute: 'caseSummary', action: CaseItemAction.View, id: '' },
],
},
{
description: 'Stacked modal open - should return the top modal route',
state: stateWithRouteStack([
{
route: 'case-list',
subroute: 'case-list',
activeModal: [
{
route: 'case',
subroute: 'home',
activeModal: [
{ route: 'case', subroute: 'household', action: CaseItemAction.View, id: 'x' },
{ route: 'case', subroute: 'household', action: CaseItemAction.Edit, id: 'x' },
],
},
],
},
]),
expected: [
{ route: 'case', subroute: 'household', action: CaseItemAction.View, id: 'x' },
{ route: 'case', subroute: 'household', action: CaseItemAction.Edit, id: 'x' },
],
},
{
description: "Modal open in history - shouldn't really happen, ignore it",
state: stateWithRouteStack([
{
route: 'case-list',
subroute: 'case-list',
activeModal: [
{
route: 'case',
subroute: 'home',
},
],
},
{ route: 'search', subroute: 'form' },
]),
expected: [
{
route: 'case-list',
subroute: 'case-list',
activeModal: [
{
route: 'case',
subroute: 'home',
},
],
},
{ route: 'search', subroute: 'form' },
],
},
];

each(testCases).test('$description', ({ state, expected }) => {
expect(getCurrentTopmostRouteStackForTask(state, '1')).toEqual(expected);
});
});

describe('getCurrentTopmostRouteForTask', () => {
const testCases: TestCase<AppRoutes>[] = [
{
description: 'No modals open - should return the current base route a task',
state: stateWithRouteStack([
{ route: 'case-list', subroute: 'case-list' },
{ route: 'case', subroute: 'home' },
]),
expected: { route: 'case', subroute: 'home' },
},
{
description: 'Modal open - should return the modal route',
state: stateWithRouteStack([
{
route: 'case-list',
subroute: 'case-list',
activeModal: [
{ route: 'case', subroute: 'home' },
{ route: 'case', subroute: 'caseSummary', action: CaseItemAction.View, id: '' },
],
},
]),
expected: { route: 'case', subroute: 'caseSummary', action: CaseItemAction.View, id: '' },
},
{
description: 'Stacked modal open - should return the top modal route',
state: stateWithRouteStack([
{
route: 'case-list',
subroute: 'case-list',
activeModal: [
{
route: 'case',
subroute: 'home',
activeModal: [
{ route: 'case', subroute: 'household', action: CaseItemAction.View, id: 'x' },
{ route: 'case', subroute: 'household', action: CaseItemAction.Edit, id: 'x' },
],
},
],
},
]),
expected: { route: 'case', subroute: 'household', action: CaseItemAction.Edit, id: 'x' },
},
{
description: "Modal open in history - shouldn't really happen, ignore it",
state: stateWithRouteStack([
{
route: 'case-list',
subroute: 'case-list',
activeModal: [
{
route: 'case',
subroute: 'home',
},
],
},
{ route: 'search', subroute: 'form' },
]),
expected: { route: 'search', subroute: 'form' },
},
{
description: "Top modal stack is empty - shouldn't really happen, return undefined",
state: stateWithRouteStack([
{
route: 'case-list',
subroute: 'case-list',
activeModal: [
{
route: 'case',
subroute: 'home',
activeModal: [],
},
],
},
]),
expected: undefined,
},
];

each(testCases).test('$description', ({ state, expected }) => {
expect(getCurrentTopmostRouteForTask(state, '1')).toEqual(expected);
});
});

describe('getCurrentBaseRouteForTask', () => {
const testCases: TestCase<AppRoutes>[] = [
{
description: 'No modals open - should return the current base route a task',
state: stateWithRouteStack([
{ route: 'case-list', subroute: 'case-list' },
{ route: 'case', subroute: 'home' },
]),
expected: { route: 'case', subroute: 'home' },
},
{
description: 'Modal open - should still return the current base route',
state: stateWithRouteStack([
{
route: 'case-list',
subroute: 'case-list',
activeModal: [
{ route: 'case', subroute: 'home' },
{ route: 'case', subroute: 'caseSummary', action: CaseItemAction.View, id: '' },
],
},
]),
expected: {
route: 'case-list',
subroute: 'case-list',
activeModal: [
{ route: 'case', subroute: 'home' },
{ route: 'case', subroute: 'caseSummary', action: CaseItemAction.View, id: '' },
],
},
},
{
description: 'Stacked modal open - should still return the current base route',
state: stateWithRouteStack([
{
route: 'case-list',
subroute: 'case-list',
activeModal: [
{
route: 'case',
subroute: 'home',
activeModal: [
{ route: 'case', subroute: 'household', action: CaseItemAction.View, id: 'x' },
{ route: 'case', subroute: 'household', action: CaseItemAction.Edit, id: 'x' },
],
},
],
},
]),
expected: {
route: 'case-list',
subroute: 'case-list',
activeModal: [
{
route: 'case',
subroute: 'home',
activeModal: [
{ route: 'case', subroute: 'household', action: CaseItemAction.View, id: 'x' },
{ route: 'case', subroute: 'household', action: CaseItemAction.Edit, id: 'x' },
],
},
],
},
},
{
description: "Modal open in history - shouldn't really happen, ignore it",
state: stateWithRouteStack([
{
route: 'case-list',
subroute: 'case-list',
activeModal: [
{
route: 'case',
subroute: 'home',
},
],
},
{ route: 'search', subroute: 'form' },
]),
expected: { route: 'search', subroute: 'form' },
},
{
description: "Bsse modal stack is empty - shouldn't really happen, return undefined",
state: stateWithRouteStack([]),
expected: undefined,
},
];

each(testCases).test('$description', ({ state, expected }) => {
expect(getCurrentBaseRoute(state, '1')).toEqual(expected);
});
});
Loading
Loading