Skip to content

plugin: Add unit tests for StateChip and allocation utility#10

Open
NAME-ASHWANIYADAV wants to merge 2 commits into
agones-dev:mainfrom
NAME-ASHWANIYADAV:test/statechip-and-allocation
Open

plugin: Add unit tests for StateChip and allocation utility#10
NAME-ASHWANIYADAV wants to merge 2 commits into
agones-dev:mainfrom
NAME-ASHWANIYADAV:test/statechip-and-allocation

Conversation

@NAME-ASHWANIYADAV

Copy link
Copy Markdown
Contributor

Type of change

  • 🚀 New feature / enhancement

What this PR does

Adds the project's first unit tests using Vitest:

  • StateChip (13 tests): Verifies all 11 Agones GameServer lifecycle states
    map to correct chip colors, including graceful fallback for unmapped states.
  • buildAllocationBody (15 tests): Validates the allocation payload builder
    with edge cases for label selectors, counter/list filters, mutations, and priorities.

28 tests total, all passing.

Test plan

Automated checks

  • npm run test (28 tests passing in ~2.6s)
  • npm run tsc
  • npm run lint

Introduce robust unit tests for the StateChip component and the
buildAllocationBody utility using Vitest. This ensures that GameServer
lifecycle state colors map correctly and allocation payload generation
handles all form edge cases properly.

Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
Comment thread src/components/StateChip.test.ts Outdated
});

// Unknown / unmapped states should not crash (fallback to 'default')
it.each(['PortAllocation', 'Starting', 'SomeUnknownState', ''])(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be out of the scope of these unit tests, but I would probably add the PortAllocation and Starting as info from the stateChip.tsx to match all the states (maybe also the created / deleted, not fully sure about these ones)
https://agones.dev/site/docs/reference/gameserver/#gameserver-state-diagram
WDYT ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the same time I just seen your comment L 21-24, I'd say let's map them and add a unit test for a case which doesn't exist ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mapped PortAllocation and Starting as info in StateChip.tsx and moved them into the info test group.
The fallback test now only covers states that don't actually exist in Agones. Thanks for the pointer to the state diagram 👍

Signed-off-by: ashwani yadav <22ashwaniyadav@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants