Skip to content
Permalink
Browse files

Limit cow name length

  • Loading branch information...
jeremyckahn committed Aug 1, 2019
1 parent f163973 commit b267bc9ee594d91cca769c3fca3465e9f2a1fb17
@@ -50,6 +50,7 @@ import {
} from './enums';
import {
FERTILIZER_ITEM_ID,
MAX_ANIMAL_NAME_LENGTH,
PURCHASEABLE_COW_PENS,
PURCHASEABLE_FIELD_SIZES,
SCARECROW_ITEM_ID,
@@ -478,7 +479,10 @@ export default class Farmhand extends Component {
const cowIndex = cowInventory.indexOf(cow);

const newCowInventory = [...cowInventory];
newCowInventory[cowIndex] = { ...cow, name: newName };
newCowInventory[cowIndex] = {
...cow,
name: newName.slice(0, MAX_ANIMAL_NAME_LENGTH),
};

return {
cowInventory: newCowInventory,
@@ -12,6 +12,7 @@ import {
FERTILIZER_ITEM_ID,
INITIAL_FIELD_WIDTH,
INITIAL_FIELD_HEIGHT,
MAX_ANIMAL_NAME_LENGTH,
PURCHASEABLE_COW_PENS,
SCARECROW_ITEM_ID,
SPRINKLER_ITEM_ID,
@@ -462,6 +463,20 @@ describe('instance methods', () => {
name: 'new name',
});
});

test('restricts name length', () => {
const cow = generateCow();

component.setState({
cowInventory: [cow],
});

component.instance().changeCowName(cow, new Array(100).join('.'));

expect(component.state().cowInventory[0].name).toHaveLength(
MAX_ANIMAL_NAME_LENGTH
);
});
});

describe('plantInPlot', () => {
@@ -32,3 +32,5 @@ export const SPRINKLER_RANGE = 1;

export const COW_STARTING_WEIGHT_BASE = 1800;
export const COW_STARTING_WEIGHT_VARIANCE = 200;

export const MAX_ANIMAL_NAME_LENGTH = 30;
@@ -51,7 +51,6 @@ export const CowCard = ({
),
title: (
<>
{/* FIXME: Set name restrictions. */}
{isNameEditable ? (
<TextField
{...{
@@ -1,3 +1,4 @@
// NOTE: This needs to be manually kept aligned with __mocks__/constants.js.
const { freeze } = Object;

export const FERTILIZER_BONUS = 0.5;
@@ -32,3 +33,5 @@ export const SPRINKLER_RANGE = 1;

export const COW_STARTING_WEIGHT_BASE = 1800;
export const COW_STARTING_WEIGHT_VARIANCE = 200;

export const MAX_ANIMAL_NAME_LENGTH = 30;

0 comments on commit b267bc9

Please sign in to comment.
You can’t perform that action at this time.