Skip to content

Commit

Permalink
Merge pull request #1737 from techmatters/CHI-1994-modal_routing
Browse files Browse the repository at this point in the history
CHI-1994: Modal routing
  • Loading branch information
stephenhand authored Oct 24, 2023
2 parents 3fa07cb + d1244ef commit e6c576b
Show file tree
Hide file tree
Showing 32 changed files with 718 additions and 439 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const stateWithRoute = (taskSid: string, route: AppRoutes): RootState => {
[namespace]: {
[routingBase]: {
tasks: {
[taskSid]: route,
[taskSid]: [route],
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import { RootState } from '../../../states';
import AddEditCaseItem, { AddEditCaseItemProps } from '../../../components/case/AddEditCaseItem';
import { getDefinitionVersions } from '../../../hrmConfig';
import { CustomITask } from '../../../types/types';
import { AppRoutes, CaseItemAction, NewCaseSubroutes } from '../../../states/routing/types';
import { CaseItemAction, NewCaseSubroutes } from '../../../states/routing/types';
import { householdSectionApi } from '../../../states/case/sections/household';
import { changeRoute } from '../../../states/routing/actions';
import { newGoBackAction } from '../../../states/routing/actions';
import { ReferralLookupStatus } from '../../../states/contacts/resourceReferral';
import { VALID_EMPTY_CONTACT } from '../../testContacts';
import { configurationBase, connectedCaseBase, contactFormsBase, namespace } from '../../../states/storeNamespaces';
Expand Down Expand Up @@ -123,11 +123,13 @@ const hrmState: Partial<RootState[typeof namespace]> = {
editingContact: false,
isCallTypeCaller: false,
contactDetails: { contactSearch: { detailsExpanded: {} }, caseDetails: { detailsExpanded: {} } },
existingContacts: {},
tasks: {
task1: {
contact: {
existingContacts: {
1234: {
references: new Set(),
savedContact: {
...VALID_EMPTY_CONTACT,
id: '1234',
taskId: 'task1',
rawJson: {
...VALID_EMPTY_CONTACT.rawJson,
childInformation: {
Expand Down Expand Up @@ -163,9 +165,7 @@ const hrmState: Partial<RootState[typeof namespace]> = {
[connectedCaseBase]: addingNewHouseholdCaseState,
routing: {
tasks: {
task1: {
route: 'new-case',
},
task1: [{ route: 'case', subroute: 'household', action: CaseItemAction.Add }],
},
isAddingOfflineContact: false,
},
Expand All @@ -184,11 +184,8 @@ const state2 = {
...state1[namespace],
[connectedCaseBase]: addingNewHouseholdCaseState,
routing: {
route: 'new-case',
tasks: {
task1: {
route: 'new-case',
},
task1: [{ route: 'case', subroute: 'household', action: CaseItemAction.Add }],
},
},
},
Expand All @@ -198,9 +195,7 @@ store2.dispatch = jest.fn();

const routing3: RootState[typeof namespace]['routing'] = {
tasks: {
task1: {
route: 'new-case',
},
task1: [{ route: 'case', subroute: 'household', action: CaseItemAction.Add }],
},
isAddingOfflineContact: true,
};
Expand All @@ -218,18 +213,16 @@ store3.dispatch = jest.fn();
const themeConf: ThemeConfigProps = {};

describe('Test AddHousehold', () => {
const exitRoute: AppRoutes = { route: 'tabbed-forms', subroute: 'caseInformation' };
let ownProps: AddEditCaseItemProps;
beforeEach(
() =>
(ownProps = {
task: { taskSid: 'task1' } as CustomITask,
counselor: 'Someone',
exitRoute,
sectionApi: householdSectionApi,
definitionVersion: mockV1,
routing: {
route: 'tabbed-forms',
route: 'case',
subroute: NewCaseSubroutes.Household,
action: CaseItemAction.Add,
},
Expand All @@ -244,19 +237,19 @@ describe('Test AddHousehold', () => {
</StorelessThemeProvider>,
);

expect(store2.dispatch).not.toHaveBeenCalledWith(changeRoute(exitRoute, 'task1'));
expect(store2.dispatch).not.toHaveBeenCalledWith(newGoBackAction('task1'));

expect(screen.getByTestId('Case-CloseCross')).toBeInTheDocument();
screen.getByTestId('Case-CloseCross').click();

expect(store2.dispatch).toHaveBeenCalledWith(changeRoute(exitRoute, 'task1'));
expect(store2.dispatch).toHaveBeenCalledWith(newGoBackAction('task1'));

store2.dispatch.mockClear();

expect(screen.getByTestId('Case-CloseButton')).toBeInTheDocument();
screen.getByTestId('Case-CloseButton').click();

expect(store2.dispatch).toHaveBeenCalledWith(changeRoute(exitRoute, 'task1'));
expect(store2.dispatch).toHaveBeenCalledWith(newGoBackAction('task1'));
});

test('a11y', async () => {
Expand Down
4 changes: 2 additions & 2 deletions plugin-hrm-form/src/___tests__/components/case/Case.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('useState mocked', () => {
},
},
},
[routingBase]: { tasks: { task1: { route: 'new-case' } } },
routing: { tasks: { task1: [{ route: 'case', subroute: 'home' }] } },
});

ownProps = {
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('useState mocked', () => {
[connectedCaseBase]: {
tasks: {},
},
[routingBase]: { tasks: { task1: { route: 'new-case' } } },
[routingBase]: { tasks: { task1: [{ route: 'case', subroute: 'home' }] } },
[configurationBase]: {
counselors: {
list: [],
Expand Down
38 changes: 23 additions & 15 deletions plugin-hrm-form/src/___tests__/components/case/CaseHome.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('useState mocked', () => {
},
},
},
[routingBase]: { tasks: { task1: { route: 'new-case' } } },
[routingBase]: { tasks: { task1: [{ route: 'case', subroute: 'home' }] } },
});

const setState = jest.fn();
Expand Down Expand Up @@ -204,12 +204,13 @@ describe('useState mocked', () => {
screen.getByText('Case-Note').click();
expect(store.dispatch).toHaveBeenCalledWith({
routing: {
route: 'new-case',
route: 'case',
subroute: NewCaseSubroutes.Note,
action: CaseItemAction.Add,
},
taskId: 'task1',
type: 'CHANGE_ROUTE',
replace: false,
type: 'routing/change-route',
});
});

Expand All @@ -228,12 +229,13 @@ describe('useState mocked', () => {
screen.getByText('Case-Referral').click();
expect(store.dispatch).toHaveBeenCalledWith({
routing: {
route: 'new-case',
route: 'case',
subroute: NewCaseSubroutes.Referral,
action: CaseItemAction.Add,
},
taskId: 'task1',
type: 'CHANGE_ROUTE',
replace: false,
type: 'routing/change-route',
});
});

Expand All @@ -252,12 +254,13 @@ describe('useState mocked', () => {
screen.getByText('Case-Household').click();
expect(store.dispatch).toHaveBeenCalledWith({
routing: {
route: 'new-case',
route: 'case',
subroute: NewCaseSubroutes.Household,
action: CaseItemAction.Add,
},
taskId: 'task1',
type: 'CHANGE_ROUTE',
replace: false,
type: 'routing/change-route',
});
});

Expand All @@ -276,12 +279,13 @@ describe('useState mocked', () => {
screen.getByText('Case-Perpetrator').click();
expect(store.dispatch).toHaveBeenCalledWith({
routing: {
route: 'new-case',
route: 'case',
subroute: NewCaseSubroutes.Perpetrator,
action: CaseItemAction.Add,
},
taskId: 'task1',
type: 'CHANGE_ROUTE',
replace: false,
type: 'routing/change-route',
});
});

Expand All @@ -302,13 +306,14 @@ describe('useState mocked', () => {

expect(store.dispatch).toHaveBeenCalledWith({
routing: {
route: 'new-case',
route: 'case',
subroute: NewCaseSubroutes.Household,
action: CaseItemAction.View,
id: 'HOUSEHOLD_ID',
},
taskId: 'task1',
type: 'CHANGE_ROUTE',
replace: false,
type: 'routing/change-route',
});
});

Expand All @@ -329,13 +334,14 @@ describe('useState mocked', () => {

expect(store.dispatch).toHaveBeenCalledWith({
routing: {
route: 'new-case',
route: 'case',
subroute: NewCaseSubroutes.Perpetrator,
action: CaseItemAction.View,
id: 'PERPETRATOR_ID',
},
taskId: 'task1',
type: 'CHANGE_ROUTE',
replace: false,
type: 'routing/change-route',
});
});

Expand All @@ -355,12 +361,14 @@ describe('useState mocked', () => {
screen.getByText('Case-EditButton').click();
expect(store.dispatch).toHaveBeenCalledWith({
routing: {
route: 'new-case',
route: 'case',
subroute: NewCaseSubroutes.CaseSummary,
action: CaseItemAction.Edit,
id: '',
},
taskId: 'task1',
type: 'CHANGE_ROUTE',
replace: false,
type: 'routing/change-route',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { StandaloneITask } from '../../../types/types';
import { CaseItemAction, NewCaseSubroutes } from '../../../states/routing/types';
import { householdSectionApi } from '../../../states/case/sections/household';
import { configurationBase, connectedCaseBase, contactFormsBase, namespace } from '../../../states/storeNamespaces';
import { newGoBackAction } from '../../../states/routing/actions';

// eslint-disable-next-line react-hooks/rules-of-hooks
const { mockFetchImplementation, mockReset, buildBaseURL } = useFetchDefinitions();
Expand All @@ -58,6 +59,14 @@ const household = {

const state = {
[namespace]: {
routing: {
tasks: {
task1: [
{ route: 'case', subroute: 'home' },
{ route: 'case', subroute: NewCaseSubroutes.Household, action: CaseItemAction.View, id: 'HOUSEHOLD_2' },
],
},
},
[configurationBase]: {
counselors: {
list: [],
Expand Down Expand Up @@ -115,7 +124,6 @@ const task = {

describe('Test ViewHousehold', () => {
let mockV1: DefinitionVersion;
const exitItem = jest.fn();

let ownProps: ViewCaseItemProps;

Expand All @@ -130,12 +138,11 @@ describe('Test ViewHousehold', () => {

beforeEach(async () => {
ownProps = {
exitItem,
definitionVersion: mockV1,
task: task as StandaloneITask,
sectionApi: householdSectionApi,
routing: {
route: 'tabbed-forms',
route: 'case',
subroute: NewCaseSubroutes.Household,
action: CaseItemAction.View,
id: 'HOUSEHOLD_2',
Expand All @@ -153,21 +160,19 @@ describe('Test ViewHousehold', () => {
</StorelessThemeProvider>,
);

expect(exitItem).not.toHaveBeenCalled();

expect(screen.getByTestId('Case-CloseCross')).toBeInTheDocument();
expect(screen.getByTestId('Case-EditButton')).toBeInTheDocument();
screen.getByTestId('Case-CloseCross').click();

expect(exitItem).toHaveBeenCalled();
expect(store.dispatch).toHaveBeenCalledWith(newGoBackAction(task.taskSid));

exitItem.mockClear();
expect(exitItem).not.toHaveBeenCalled();
store.dispatch.mockClear();
expect(store.dispatch).not.toHaveBeenCalled();

expect(screen.getByTestId('Case-CloseButton')).toBeInTheDocument();
screen.getByTestId('Case-CloseButton').click();

expect(exitItem).toHaveBeenCalled();
expect(store.dispatch).toHaveBeenCalledWith(newGoBackAction(task.taskSid));
});
test('Test no edit permissions', async () => {
render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ test('Should dispatch fetchStarted and fetchSuccess actions if case lists return
currentDefinitionVersion: mockV1,
},
[caseListBase]: blankCaseListState,
routing: { tasks: {} },
});
const store = mockStore(initialState);

Expand Down Expand Up @@ -186,6 +187,7 @@ test('Should render list if it is populated', async () => {
listLoading: false,
},
},
routing: { tasks: {} },
});
const store = mockStore(initialState);

Expand Down Expand Up @@ -235,6 +237,7 @@ test('Should render no cases and show No Cases Found row', async () => {
listLoading: false,
},
},
routing: { tasks: {} },
});
const store = mockStore(initialState);

Expand Down Expand Up @@ -273,6 +276,7 @@ test('Should dispatch fetchStarted and fetchError actions if case lists error',
currentDefinitionVersion: mockV1,
},
[caseListBase]: blankCaseListState,
routing: { tasks: {} },
});
const store = mockStore(initialState);

Expand Down Expand Up @@ -309,6 +313,7 @@ test('Should render error page if fetchError set in store', async () => {
...blankCaseListState,
content: { ...blankCaseListState.content, fetchError: new Error('Some error') },
},
routing: { tasks: {} },
});
const store = mockStore(initialState);

Expand Down Expand Up @@ -347,6 +352,7 @@ test('Should render loading page if listLoading set in store', async () => {
...blankCaseListState,
content: { ...blankCaseListState.content, listLoading: true },
},
routing: { tasks: {} },
});
const store = mockStore(initialState);

Expand Down Expand Up @@ -378,6 +384,7 @@ test('a11y', async () => {
currentDefinitionVersion: mockV1,
},
[caseListBase]: blankCaseListState,
routing: { tasks: {} },
});
const store = mockStore(initialState);

Expand Down
Loading

0 comments on commit e6c576b

Please sign in to comment.