Testing MCP-Generated Rive Data Binding States in Storybook and Playwright
By the Charmotion team · Updated · How we write guides

Test each MCP-generated Rive Data Binding mood state as its own Storybook story, then run Playwright against those stories and assert the mood value your app exposes, not canvas pixels. The character's mood property runs from 0 to 9, so one table of expected values covers every state. Add pixel checks only where the look matters.
Key takeaways
- Expose the mood number in the DOM so Playwright asserts a value the app reports, not the canvas.
- Treat the fixed mood table as the contract shared by the app, the Storybook stories and the Playwright specs.
- Assert state values on every build and review screenshots only for the moods where the look matters.
- Storybook visual tests suit UI components, and Chromatic is a separate paid service from the Storybook team.
- After a regeneration, rerun the assertions for every change and compare visuals when the file itself changed.
Already have a character or logo? See examples in real app screens: splash, onboarding, loading and empty-state screens, with the animation that plays in each.
What should you test in MCP-generated Rive mood states?
An MCP-generated character arrives as one Rive file with its emotional state exposed as a number. Charmotion's MCP server, for example, returns a CharacterViewModelMachine with a number property named mood, a CharacterStateMachine with a number input of the same name, and a LaunchStateMachine when launch was picked. The full set of server tools is on the MCP server page. Because the mood numbers are fixed, the test surface is small: does the app write the right number, does the character show that mood, and do the other states still work.
| Mood | Number | Typical use in an app |
|---|---|---|
| idle | 0 | Resting state, always included |
| happy | 1 | Success confirmation |
| wave | 2 | Greeting or onboarding start |
| thinking | 3 | Processing a request |
| sad | 4 | Error or failed action |
| loading | 5 | Waiting on the network |
| listening | 6 | Voice or text input in progress |
| talking | 7 | Reply playing |
| sleeping | 8 | Inactivity |
| attention | 9 | Needs the user to act |
Charmotion characters have no one-shot triggers for success or error, so those states map to happy and sad. Your tests should use the same mapping, and the table is the contract between the app and the file.
Split the work into three layers. First, a unit test checks the function that turns app state into a mood number. Second, a Storybook story per mood renders the real Rive file. Third, a Playwright run drives the app and reads what it reports. Each layer catches a different kind of bug.
How do you set up Storybook for a Rive character?
Storybook is a free, open source workshop for building UI components in isolation. Add it with the npm create storybook@latest command, or ask an AI agent to run that setup. The official docs list React with Vite or Webpack, Vue with Vite, Angular, Svelte with Vite, Preact with Vite and Next.js with Vite, so a Rive wrapper built for any of those can use the same approach. Vue projects have their own setup steps in Rive in Vue 3 and Nuxt.
Storybook renders components in a real browser page, so the Rive web runtime loads the same way it does in production. Rive's runtimes are open source and play any .riv file, so the file itself needs no special handling. On React, the @rive-app/react-canvas package provides a useRive hook. Rive's React docs mark the useStateMachineInput hook as deprecated in favor of newer data binding hooks, so new mood code should write to the view model instance rather than to a single input. The wiring for a Next.js app is covered in How to Use Rive in React and Next.js.
Keep the .riv file in your repository next to the component rather than in a remote location. Stories then load it from a fixed path, and the test result does not depend on a host that may change.
How do you write one story per mood?
Put the Rive canvas and the mood logic in one wrapper component. The app and every story use that wrapper, so a story that passes proves the same code path the app runs. The wrapper also writes the current mood into a data attribute, which gives Playwright a value to read.
// MoodMascot.jsx
export function MoodMascot({ mood, accents = true }) {
return (
<div data-mood={mood} data-accents={accents ? 'on' : 'off'}>
{/* Rive canvas bound to CharacterViewModelMachine goes here */}
</div>
);
}Then write one story for each mood your app uses, plus one for the accents switch:
// MoodMascot.stories.js
export default { title: 'Mascot/Mood', component: MoodMascot };
export const Idle = { args: { mood: 0 } };
export const Happy = { args: { mood: 1 } };
export const Sad = { args: { mood: 4 } };
export const Loading = { args: { mood: 5 } };
export const AccentsOff = { args: { mood: 1, accents: false } };Stories are the fixtures for every later test. Name them after the mood, not the screen where they appear, so a layout change in the app does not rename the tests. Storybook's interaction tests run inside a story and can be previewed and debugged in the Interactions panel, which helps when a mood needs a click to reach.
How do you configure Playwright to record mood runs?
Install Playwright Test with npm init playwright@latest. The config file, playwright.config.ts, controls target browsers, timeouts, retries, projects and reporters. Screenshot, video and trace capture are off by default, so you switch them on there. Trace files, screenshots and videos are written to the test output folder, usually named test-results.
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
baseURL: 'http://localhost:6006',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
trace: 'on-first-retry',
},
retries: 1,
});The video option accepts the modes off, on, retain-on-failure and on-first-retry. retain-on-failure keeps clips only for failing runs, which suits mood tests because you need the clip when a mood sticks. Check the full option list on Playwright's configuration page before you rely on a specific mode in CI. Playwright drives Chromium, Firefox and WebKit through one API, so run the mood specs in all three before a release.
Playwright MCP includes tools to start and stop video recording, so a coding agent can capture a clip while it debugs a run. That is useful when a transition looks wrong on screen and you want evidence without rerunning the suite by hand.
How to test MCP-generated Rive Data Binding mood states in Playwright and Storybook
Use these steps for each character. The first three happen once per generated set. The last three run on every build.
- Generate the set and save the mood map. Create the character with the MCP tools, then keep the mood numbers from the table above in a shared constants file that both the app and the tests import.
- Wrap the file in one component. Bind mood and accents through the view model instance, and write the mood to a data attribute.
- Write one Storybook story per mood. Include one story with accents off.
- Add the Playwright config. Enable screenshots and video on failure, and a trace on the first retry.
- Assert the value, then capture the picture. Each Playwright test loads a story, checks the data-mood value, then saves a screenshot for review.
- Run the suite on every build. Fail the build when a mood value is wrong, and review any changed screenshot before accepting a new baseline.
import { test, expect } from '@playwright/test';
import { MOODS } from './mood-map.js';
for (const mood of MOODS) {
test(`mood ${mood.name} renders as ${mood.value}`, async ({ page }) => {
await page.goto(`/iframe.html?id=mascot-mood--${mood.name}&viewMode=story`);
const mascot = page.locator('[data-mood]');
await expect(mascot).toHaveAttribute('data-mood', String(mood.value));
await page.screenshot({ path: `test-results/${mood.name}.png` });
});
}The assertion checks the number the app wrote. It does not prove that the drawing matches that number, which is what the visual checks in the next section cover. Add a test that loads the AccentsOff story and asserts data-accents is off, and a test that clicks through the app to reach a sad state and confirms the attribute changes.
Should you test Rive moods with visual snapshots or state assertions?
Use both, for different jobs. Storybook's snapshot tests render a component in a given state, save its DOM or HTML, and compare it with a baseline. The official docs say visual tests are usually the better fit for UI components. Visual tests compare the rendered pixels of each story against known baselines, and the docs say running them sends stories to the cloud to take the snapshots.
| Check | What it catches | Where it runs |
|---|---|---|
| State assertion on data-mood | Wrong mood number, missing binding | Playwright, local |
| Playwright screenshot | A saved image per mood for human review | Local file in test-results |
| Storybook visual test | Pixel changes across every story | Cloud snapshots, per the Storybook docs |
Chromatic is a separate paid service from the Storybook team, and this guide does not state its prices. Check its own pricing page for current plans as of December 2026.
Moods blend into each other, so a screenshot taken too early shows a half-finished pose. Wait for the data-mood value to settle and for the wrapper to signal that the change has finished, not for a fixed sleep. Clip lengths differ: launch runs 2.6 seconds, wave 3.0 seconds and sleeping 4.0 seconds. Plan waits around the longest clip in your set.
What should you rerun after the MCP regenerates a character?
Charmotion's MCP server creates a character set with the animations you choose, adds more later through add_animations (only the new ones use credits), and returns download links plus AI_README integration notes through get_character_set. export_videos produces MP4, GIF, transparent WebM and MOV copies. Each new file means a new test pass, but not the same pass every time. The MCP server page lists the tools and what each one returns.
- New animations on the same character: run the mood assertions and the accents test. The number map has not changed.
- A regenerated file: run every state assertion and the full screenshot set, then compare the new baselines with the old ones by eye.
- A changed mood map in your own code: treat it as a breaking change. Update the constants file, the wrapper and every story together.
Keep the test suite in the same repository as the app, and store the AI_README notes beside it, so a coding agent that edits the wrapper sees the mood contract. When a run fails, the trace and video that Playwright saved show what happened, so the fix starts from evidence rather than a guess. For a wider view of how states drive mascots in a product, see Lottie vs Rive state machines and data binding, and for the placement of moods in onboarding, How to add a mascot to onboarding and empty states.
How to test MCP-generated Rive Data Binding mood states in Playwright and Storybook
- Generate the set and save the mood map. Create the character with the MCP tools and keep the mood numbers in a constants file that the app and the tests both import.
- Wrap the file in one component. Bind mood and accents through the view model instance and write the mood to a data attribute the tests can read.
- Write one Storybook story per mood. Add a story for each mood the app uses, plus one with accents off.
- Add the Playwright config. Enable screenshots and video on failure and a trace on the first retry in playwright.config.ts.
- Assert the value, then capture the picture. Load each story, assert the data-mood value, then save a screenshot for review.
- Run the suite on every build. Fail the build on a wrong mood value and review any changed screenshot before accepting a new baseline.
Frequently asked questions
Can Playwright read the Rive state directly from the canvas?
Playwright works with the page's DOM and pixels, so it cannot tell which state a Rive canvas is in from the drawing alone. Have your wrapper write the mood it sent into a data attribute, then assert that attribute. Pixel checks cover the drawing separately.
Do I need Chromatic to run visual tests in Storybook?
No single service is required. Storybook's visual testing docs describe cloud snapshots, and Chromatic is the paid hosted option from the Storybook team. Check Chromatic's own pricing page for current plans, since this guide does not list them.
Does this approach work for a React Native app?
Storybook and Playwright test web builds, so they cover a web version of the character. The Rive React Native runtime is native and needs a development build or native project rather than Expo Go, so test native screens on a simulator or device.
How do I test that the small accent icons are hidden?
Use the boolean accents input in your wrapper and render the AccentsOff story. The accents are on by default, and the wrapper's data-accents attribute gives Playwright a value to assert, so the test does not depend on how the icons look.
Sources
- Snapshot testing, Storybook
- Visual tests, Storybook
- Interaction testing, Storybook
- Playwright configuration options (test-use-options), Playwright (Microsoft)
- Rive React runtime overview, Rive
- Charmotion MCP server, Charmotion