Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #188 from manywho/feature/FLOW-3829
Browse files Browse the repository at this point in the history
FLOW-3829 - Moved empty date check to only check definite dates
  • Loading branch information
TomFullalove authored Sep 1, 2021
2 parents 165a0d7 + bd1b94d commit bfcf0c6
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 14 deletions.
91 changes: 90 additions & 1 deletion ui-bootstrap/__tests__/table-input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { shallow } from 'enzyme';

import TableInput from '../js/components/table-input';

import * as moment from 'moment';


describe('Table input component behaviour', () => {
Expand All @@ -16,6 +17,8 @@ describe('Table input component behaviour', () => {

const globalAny:any = global;

const mockOnCommitted = jest.fn();

function manyWhoMount(
{
contentType = 'string',
Expand All @@ -31,7 +34,7 @@ describe('Table input component behaviour', () => {
flowKey: 'string',
contentFormat: 'string',
propertyId: 'string',
onCommitted: jest.fn(),
onCommitted: mockOnCommitted,
};

globalAny.window.manywho.component['contentTypes'] = {
Expand All @@ -51,6 +54,7 @@ describe('Table input component behaviour', () => {

afterEach(() => {
tableInputWrapper.unmount();
mockOnCommitted.mockClear();
});

test('Table input component renders without crashing', () => {
Expand Down Expand Up @@ -272,4 +276,89 @@ describe('Table input component behaviour', () => {

expect(globalAny.window.manywho.model.setModal).toHaveBeenCalled();
});

test('Committing content boolean commits successfully', () => {
// This must be false so that the isDateTimeInput fails
globalAny.window.manywho.utils.isEqual = jest.fn(() => false);

const value = true;

tableInputWrapper = manyWhoMount({
contentType: globalAny.window.manywho.component.contentTypes.boolean,
value,
});

tableInputWrapper.instance().onCommit();

expect(mockOnCommitted).toHaveBeenCalledWith('string', 'string', value);
});

test('Committing content string commits successfully', () => {
// This must be false so that the isDateTimeInput fails
globalAny.window.manywho.utils.isEqual = jest.fn(() => false);

const value = 'true';

tableInputWrapper = manyWhoMount({
contentType: globalAny.window.manywho.component.contentTypes.string,
value,
});

tableInputWrapper.instance().onCommit();

expect(mockOnCommitted).toHaveBeenCalledWith('string', 'string', value);
});

test('Committing content number commits successfully', () => {
// This must be false so that the isDateTimeInput fails
globalAny.window.manywho.utils.isEqual = jest.fn(() => false);

const value = 37;

tableInputWrapper = manyWhoMount({
contentType: globalAny.window.manywho.component.contentTypes.number,
value,
});

tableInputWrapper.instance().onCommit();

expect(mockOnCommitted).toHaveBeenCalledWith('string', 'string', value);
});

test('Committing content password commits successfully', () => {
// This must be false so that the isDateTimeInput fails
globalAny.window.manywho.utils.isEqual = jest.fn(() => false);

const value = 'password';

tableInputWrapper = manyWhoMount({
contentType: globalAny.window.manywho.component.contentTypes.password,
value,
});

tableInputWrapper.instance().onCommit();

expect(mockOnCommitted).toHaveBeenCalledWith('string', 'string', value);
});

test('Committing content datetime commits successfully', () => {
// This must be true so that the isDateTimeInput succeeds
globalAny.window.manywho.utils.isEqual = jest.fn(() => true);

const value = '02/02/0002';

tableInputWrapper = manyWhoMount({
contentType: globalAny.window.manywho.component.contentTypes.datetime,
value,
});

tableInputWrapper.instance().onCommit();

const expectedDate = moment(
value,
['MM/DD/YYYY hh:mm:ss A ZZ', moment.ISO_8601, 'string' || ''],
).format();

expect(mockOnCommitted).toHaveBeenCalledWith('string', 'string', expectedDate);
});
});
27 changes: 14 additions & 13 deletions ui-bootstrap/js/components/table-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,20 @@ class TableInput extends React.Component<ITableInputProps, ITableInputState> {
true,
);

const isEmptyDate = this.isEmptyDate(this.state.value);

if (isDateTimeInput && !isEmptyDate) {
const dateTime = moment(
this.state.value,
['MM/DD/YYYY hh:mm:ss A ZZ', moment.ISO_8601, this.props.contentFormat || ''],
);

this.props.onCommitted(this.props.id, this.props.propertyId, dateTime.format());
manywho.model.setModal(this.props.flowKey, null);

} else if (isDateTimeInput && isEmptyDate) {
this.renderDateTimeModal('Please select a date');
if (isDateTimeInput) {
const isEmptyDate = this.isEmptyDate(this.state.value);

if (isEmptyDate) {
this.renderDateTimeModal('Please select a date');
} else {
const dateTime = moment(
this.state.value,
['MM/DD/YYYY hh:mm:ss A ZZ', moment.ISO_8601, this.props.contentFormat || ''],
);

this.props.onCommitted(this.props.id, this.props.propertyId, dateTime.format());
manywho.model.setModal(this.props.flowKey, null);
}
} else {
this.props.onCommitted(this.props.id, this.props.propertyId, this.state.value);
}
Expand Down

0 comments on commit bfcf0c6

Please sign in to comment.