Skip to content

Commit

Permalink
Merge pull request #95 from walmat/issue_94
Browse files Browse the repository at this point in the history
Use Default Values as Fallback
  • Loading branch information
pr1sm authored Oct 16, 2018
2 parents c708fc6 + 9dbb47e commit 9293835
Show file tree
Hide file tree
Showing 13 changed files with 373 additions and 174 deletions.
2 changes: 1 addition & 1 deletion frontend/src/__tests__/server/createProxies.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('<CreateProxies />', () => {
const destroyButton = getByTestId(wrapper, 'CreateProxies.destroyProxiesButton');
const generateButton = getByTestId(wrapper, 'CreateProxies.generateProxiesButton');
expect(numProxiesInput).toHaveLength(1);
expect(numProxiesInput.prop('value')).toBe(0);
expect(numProxiesInput.prop('value')).toBe('');
expect(usernameInput).toHaveLength(1);
expect(usernameInput.prop('value')).toBe('');
expect(passwordInput).toHaveLength(1);
Expand Down
142 changes: 45 additions & 97 deletions frontend/src/__tests__/state/reducers/profile/locationReducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,112 +9,60 @@ describe('location reducer', () => {
expect(actual).toEqual(initialProfileStates.location);
});

it('should handle edit first name action', () => {
const expected = {
...initialProfileStates.location,
firstName: 'testing',
describe('when editing', () => {
const _testEditField = (field) => {
it('should update when using a non-null value', () => {
const expected = {
...initialProfileStates.location,
[field]: 'testing',
};
const actual = locationReducer(
initialProfileStates.location,
{ type: field, value: 'testing' },
);
expect(actual).toEqual(expected);
});

it('should update when using an empty value', () => {
const expected = {
...initialProfileStates.location,
};
const actual = locationReducer(
initialProfileStates.location,
{ type: field, value: '' },
);
expect(actual).toEqual(expected);
});

it('should clear the state when using a null value', () => {
const expected = {
...initialProfileStates.location,
};
const actual = locationReducer(
initialProfileStates.location,
{ type: field, value: null },
);
expect(actual).toEqual(expected);
});
};
const actual = locationReducer(
initialProfileStates.location,
{ type: LOCATION_FIELDS.FIRST_NAME, value: 'testing' },
);
expect(actual).toEqual(expected);
});

it('should handle edit last name action', () => {
const expected = {
...initialProfileStates.location,
lastName: 'testing',
};
const actual = locationReducer(
initialProfileStates.location,
{ type: LOCATION_FIELDS.LAST_NAME, value: 'testing' },
);
expect(actual).toEqual(expected);
});
describe('first name', () => _testEditField(LOCATION_FIELDS.FIRST_NAME));

it('should handle edit address action', () => {
const expected = {
...initialProfileStates.location,
address: 'testing',
};
const actual = locationReducer(
initialProfileStates.location,
{ type: LOCATION_FIELDS.ADDRESS, value: 'testing' },
);
expect(actual).toEqual(expected);
});
describe('last name', () => _testEditField(LOCATION_FIELDS.LAST_NAME));

it('should handle edit apt action', () => {
const expected = {
...initialProfileStates.location,
apt: 'testing',
};
const actual = locationReducer(
initialProfileStates.location,
{ type: LOCATION_FIELDS.APT, value: 'testing' },
);
expect(actual).toEqual(expected);
});
describe('address', () => _testEditField(LOCATION_FIELDS.ADDRESS));

it('should handle edit city action', () => {
const expected = {
...initialProfileStates.location,
city: 'testing',
};
const actual = locationReducer(
initialProfileStates.location,
{ type: LOCATION_FIELDS.CITY, value: 'testing' },
);
expect(actual).toEqual(expected);
});
describe('apt', () => _testEditField(LOCATION_FIELDS.APT));

it('should handle edit zip code action', () => {
const expected = {
...initialProfileStates.location,
zipCode: 'testing',
};
const actual = locationReducer(
initialProfileStates.location,
{ type: LOCATION_FIELDS.ZIP_CODE, value: 'testing' },
);
expect(actual).toEqual(expected);
});
describe('city', () => _testEditField(LOCATION_FIELDS.CITY));

it('should handle edit phone action', () => {
const expected = {
...initialProfileStates.location,
phone: 'testing',
};
const actual = locationReducer(
initialProfileStates.location,
{ type: LOCATION_FIELDS.PHONE_NUMBER, value: 'testing' },
);
expect(actual).toEqual(expected);
});
describe('zip code', () => _testEditField(LOCATION_FIELDS.ZIP_CODE));

it('should handle edit country action', () => {
const expected = {
...initialProfileStates.location,
country: 'testing',
};
const actual = locationReducer(
initialProfileStates.location,
{ type: LOCATION_FIELDS.COUNTRY, value: 'testing' },
);
expect(actual).toEqual(expected);
});
describe('phone number', () => _testEditField(LOCATION_FIELDS.PHONE_NUMBER));

it('should handle edit state action', () => {
const expected = {
...initialProfileStates.location,
state: 'testing',
};
const actual = locationReducer(
initialProfileStates.location,
{ type: LOCATION_FIELDS.STATE, value: 'testing' },
);
expect(actual).toEqual(expected);
describe('state', () => _testEditField(LOCATION_FIELDS.STATE));

describe('country', () => _testEditField(LOCATION_FIELDS.COUNTRY));
});

it('should not respond to invalid action type', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,50 @@ describe('payment reducer', () => {
expect(actual).toEqual(initialProfileStates.payment);
});

it('should handle edit email action', () => {
const expected = {
...initialProfileStates.payment,
email: 'testing',
};
const actual = paymentReducer(
initialProfileStates.payment,
{ type: PAYMENT_FIELDS.EMAIL, value: 'testing' },
);
expect(actual).toEqual(expected);
});
describe('when editing', () => {
const _testEditField = (field) => {
it('should update when using a non-null value', () => {
const expected = {
...initialProfileStates.payment,
[field]: 'testing',
};
const actual = paymentReducer(
initialProfileStates.payment,
{ type: field, value: 'testing' },
);
expect(actual).toEqual(expected);
});

it('should handle edit card number action', () => {
const expected = {
...initialProfileStates.payment,
cardNumber: 'testing',
};
const actual = paymentReducer(
initialProfileStates.payment,
{ type: PAYMENT_FIELDS.CARD_NUMBER, value: 'testing' },
);
expect(actual).toEqual(expected);
});
it('should update when using an empty value', () => {
const expected = {
...initialProfileStates.payment,
};
const actual = paymentReducer(
initialProfileStates.payment,
{ type: field, value: '' },
);
expect(actual).toEqual(expected);
});

it('should handle edit expiration action', () => {
const expected = {
...initialProfileStates.payment,
exp: 'testing',
it('should clear the state when using a null value', () => {
const expected = {
...initialProfileStates.payment,
};
const actual = paymentReducer(
initialProfileStates.payment,
{ type: field, value: null },
);
expect(actual).toEqual(expected);
});
};
const actual = paymentReducer(
initialProfileStates.payment,
{ type: PAYMENT_FIELDS.EXP, value: 'testing' },
);
expect(actual).toEqual(expected);
});

it('should handle edit cvv action', () => {
const expected = {
...initialProfileStates.payment,
cvv: 'testing',
};
const actual = paymentReducer(
initialProfileStates.payment,
{ type: PAYMENT_FIELDS.CVV, value: 'testing' },
);
expect(actual).toEqual(expected);
describe('email', () => _testEditField(PAYMENT_FIELDS.EMAIL));

describe('card number', () => _testEditField(PAYMENT_FIELDS.CARD_NUMBER));

describe('expiration', () => _testEditField(PAYMENT_FIELDS.EXP));

describe('cvv', () => _testEditField(PAYMENT_FIELDS.CVV));
});

it('should not respond to invalid actions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,38 @@ describe('profile reducer', () => {
);
expect(actual).toEqual(expected);
});

test(`${message} when empty`, () => {
const expected = {
...initialProfileStates.profile,
[mapProfileFieldToKey[field]]: {
...initialFieldState,
},
};
const actual = profileReducer(
initialProfileStates.profile,
{
type: PROFILE_ACTIONS.EDIT, field, value: '', subField,
},
);
expect(actual).toEqual(expected);
});

test(`${message} when null`, () => {
const expected = {
...initialProfileStates.profile,
[mapProfileFieldToKey[field]]: {
...initialFieldState,
},
};
const actual = profileReducer(
initialProfileStates.profile,
{
type: PROFILE_ACTIONS.EDIT, field, value: null, subField,
},
);
expect(actual).toEqual(expected);
});
};

test('action when field is invalid', () => {
Expand Down Expand Up @@ -365,16 +397,42 @@ describe('profile reducer', () => {
expect(actual2).toEqual(start);
});

test('name action', () => {
const expected = {
...initialProfileStates.profile,
profileName: 'testing',
};
const actual = profileReducer(
initialProfileStates.profile,
{ type: PROFILE_ACTIONS.EDIT, field: PROFILE_FIELDS.EDIT_NAME, value: 'testing' },
);
expect(actual).toEqual(expected);
describe('name action', () => {
test('when valid', () => {
const expected = {
...initialProfileStates.profile,
profileName: 'testing',
};
const actual = profileReducer(
initialProfileStates.profile,
{ type: PROFILE_ACTIONS.EDIT, field: PROFILE_FIELDS.EDIT_NAME, value: 'testing' },
);
expect(actual).toEqual(expected);
});

test('when empty', () => {
const expected = {
...initialProfileStates.profile,
profileName: '',
};
const actual = profileReducer(
initialProfileStates.profile,
{ type: PROFILE_ACTIONS.EDIT, field: PROFILE_FIELDS.EDIT_NAME, value: '' },
);
expect(actual).toEqual(expected);
});

test('when null', () => {
const expected = {
...initialProfileStates.profile,
profileName: '',
};
const actual = profileReducer(
initialProfileStates.profile,
{ type: PROFILE_ACTIONS.EDIT, field: PROFILE_FIELDS.EDIT_NAME, value: null },
);
expect(actual).toEqual(expected);
});
});
});

Expand Down
20 changes: 20 additions & 0 deletions frontend/src/__tests__/state/reducers/server/serverReducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ describe('server reducer', () => {
expect(actual).toEqual(expected);
});

it('when proxy number is empty', () => {
const expected = {
...initialServerStates.serverInfo,
proxyOptions: {
...initialServerStates.proxyOptions,
numProxies: 0,
},
};
const actual = serverReducer(
initialServerStates.serverInfo,
{
type: SERVER_ACTIONS.EDIT,
id: null,
field: SERVER_FIELDS.EDIT_PROXY_NUMBER,
value: '',
},
);
expect(actual).toEqual(expected);
});

it('when proxy number is invalid', () => {
const actual = serverReducer(
initialServerStates.serverInfo,
Expand Down
Loading

0 comments on commit 9293835

Please sign in to comment.