Skip to content

Commit

Permalink
10409: Delete old SelectSearch related functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Rogers committed Sep 24, 2024
1 parent 7d8e835 commit 15d313b
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 330 deletions.
163 changes: 1 addition & 162 deletions web-client/src/ustc-ui/Utils/documentTypeSelectHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,167 +1,6 @@
import {
docketEntryOnChange,
fileDocumentPrimaryOnChange,
onInputChange,
reactSelectValue,
} from './documentTypeSelectHelper';
import { reactSelectValue } from './documentTypeSelectHelper';

describe('documentTypeSelectHelper', () => {
let updateSequenceSpy, validateSequenceSpy;

beforeEach(() => {
updateSequenceSpy = jest.fn();
validateSequenceSpy = jest.fn();
});

describe('fileDocumentPrimaryOnChange', () => {
it('should call update sequence multiple times with correct props followed by validate sequence if "action" is "select-option"', () => {
const inputValue = {
category: 'Answer (filed by respondent only)',
documentTitle: 'Amended Answer',
documentType: 'Amended Answer',
eventCode: 'AA',
scenario: 'Standard',
};

fileDocumentPrimaryOnChange({
action: 'select-option',
inputValue,
updateSequence: updateSequenceSpy,
validateSequence: validateSequenceSpy,
});

expect(updateSequenceSpy).toHaveBeenCalled();
expect(updateSequenceSpy.mock.calls[0][0]).toEqual({
key: 'category',
value: inputValue.category,
});
expect(updateSequenceSpy.mock.calls[1][0]).toEqual({
key: 'documentType',
value: inputValue.documentType,
});
expect(updateSequenceSpy.mock.calls[2][0]).toEqual({
key: 'documentTitle',
value: inputValue.documentTitle,
});
expect(updateSequenceSpy.mock.calls[3][0]).toEqual({
key: 'eventCode',
value: inputValue.eventCode,
});
expect(updateSequenceSpy.mock.calls[4][0]).toEqual({
key: 'scenario',
value: inputValue.scenario,
});
expect(validateSequenceSpy).toHaveBeenCalled();
});

it('should call update sequence a single time followed by validate sequence if "action" is "clear"', () => {
fileDocumentPrimaryOnChange({
action: 'clear',
inputValue: undefined,
updateSequence: updateSequenceSpy,
validateSequence: validateSequenceSpy,
});

expect(updateSequenceSpy).toHaveBeenCalled();
expect(updateSequenceSpy.mock.calls[0][0]).toEqual({
key: 'category',
value: '',
});
expect(validateSequenceSpy).toHaveBeenCalled();
});

it('should not call update or validate sequence if "action" is not "select-option" or "clear"', () => {
fileDocumentPrimaryOnChange({
action: 'something-else',
inputValue: undefined,
updateSequence: updateSequenceSpy,
validateSequence: validateSequenceSpy,
});

expect(updateSequenceSpy).not.toHaveBeenCalled();
expect(validateSequenceSpy).not.toHaveBeenCalled();
});
});

describe('docketEntryOnChange', () => {
it('should call update sequence multiple times with correct props followed by validate sequence if "action" is "select-option"', () => {
const inputValue = {
value: 'AA',
};

docketEntryOnChange({
action: 'select-option',
inputName: 'primaryDocument.eventCode',
inputValue,
updateSequence: updateSequenceSpy,
validateSequence: validateSequenceSpy,
});

expect(updateSequenceSpy).toHaveBeenCalled();
expect(updateSequenceSpy.mock.calls[0][0]).toEqual({
key: 'primaryDocument.eventCode',
value: inputValue.value,
});
expect(validateSequenceSpy).toHaveBeenCalled();
});

it('should call update sequence a single time followed by validate sequence if "action" is "clear"', () => {
docketEntryOnChange({
action: 'clear',
inputName: 'primaryDocument.eventCode',
inputValue: undefined,
updateSequence: updateSequenceSpy,
validateSequence: validateSequenceSpy,
});

expect(updateSequenceSpy).toHaveBeenCalled();
expect(updateSequenceSpy.mock.calls[0][0]).toEqual({
key: 'primaryDocument.eventCode',
value: '',
});
expect(validateSequenceSpy).toHaveBeenCalled();
});

it('should not call update or validate sequence if "action" is not "select-option" or "clear"', () => {
docketEntryOnChange({
action: 'something-else',
inputName: undefined,
inputValue: undefined,
updateSequence: updateSequenceSpy,
validateSequence: validateSequenceSpy,
});

expect(updateSequenceSpy).not.toHaveBeenCalled();
expect(validateSequenceSpy).not.toHaveBeenCalled();
});
});

describe('onInputChange', () => {
it('should call update sequence a single time if "action" is "input-change"', () => {
onInputChange({
action: 'input-change',
inputText: 'something',
updateSequence: updateSequenceSpy,
});

expect(updateSequenceSpy).toHaveBeenCalled();
expect(updateSequenceSpy.mock.calls[0][0]).toEqual({
key: 'searchText',
value: 'something',
});
});

it('should not call update sequence if "action" is not "input-change"', () => {
onInputChange({
action: 'something-else',
inputText: 'something',
updateSequence: updateSequenceSpy,
});

expect(updateSequenceSpy).not.toHaveBeenCalled();
});
});

describe('reactSelectValue', () => {
const documentTypes = [
{
Expand Down
67 changes: 0 additions & 67 deletions web-client/src/ustc-ui/Utils/documentTypeSelectHelper.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,3 @@
export const fileDocumentPrimaryOnChange = ({
action,
inputValue,
updateSequence,
validateSequence,
}) => {
switch (action) {
case 'select-option':
[
'category',
'documentType',
'documentTitle',
'eventCode',
'scenario',
].forEach(key =>
updateSequence({
key,
value: inputValue[key],
}),
);
validateSequence();
break;
case 'clear':
updateSequence({
key: 'category',
value: '',
});
validateSequence();
break;
}
};

export const docketEntryOnChange = ({
action,
inputName,
inputValue,
updateSequence,
validateSequence,
}) => {
switch (action) {
case 'select-option':
updateSequence({
key: inputName,
value: inputValue.value,
});
validateSequence();
break;
case 'clear':
updateSequence({
key: inputName,
value: '',
});
validateSequence();
break;
}
return true;
};

export const onInputChange = ({ action, inputText, updateSequence }) => {
if (action === 'input-change') {
updateSequence({
key: 'searchText',
value: inputText,
});
}
};

export const reactSelectValue = ({ documentTypes, selectedEventCode }) => {
return documentTypes.filter(option => option.eventCode === selectedEventCode);
};
52 changes: 0 additions & 52 deletions web-client/src/ustc-ui/Utils/selectSearchHelper.test.ts

This file was deleted.

49 changes: 0 additions & 49 deletions web-client/src/ustc-ui/Utils/selectSearchHelper.ts

This file was deleted.

0 comments on commit 15d313b

Please sign in to comment.