Skip to content

Conversation

@rita-codes
Copy link
Member

@rita-codes rita-codes commented Oct 24, 2025

A tiny, type-safe Event Builder for tests with a simple API for complex things like recurrence

Why this helps

  • Slashes boilerplate in tests.
    Tests no longer need to manually create full CalendarEvent objects with adapter.date(...) everywhere.
    Common patterns like "single-day timed event", "all-day span", or "weekly recurrence" become one-liners, which keeps tests readable and focused on behavior instead of setup.
  • Consistent with production logic.
    The builder relies on the adapter so it automatically respects locale, time zones, and weekday mapping, no more mismatches caused by hardcoded weekday codes or date math.
  • Safer defaults: if you don't need to use the title, or another property, they're automatically filled with sensible defaults (reducing boilerplate even further)

Use examples
Full default event:
Produces a valid CalendarEventOccurrence with: Randomized id, auto title and description, starts at DEFAULT_TESTING_VISIBLE_DATE, duration 60 min and realistic key.

const event = EventBuilder.new().build();

Weekly recurring event with startAt

const event = EventBuilder.new()
.singleDay('2025-07-02T09:00:00Z', 30)
.recurrent('weekly')
.build();

All day spaning multiple days with title

const event = EventBuilder.new()
  .title('Conference')
  .span('2025-07-10T09:00:00Z', '2025-07-12T18:00:00Z', { allDay: true })
  .build();

@mui-bot
Copy link

mui-bot commented Oct 24, 2025

Deploy preview: https://deploy-preview-20081--material-ui-x.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against 617c345

@rita-codes rita-codes changed the title [PoC] Testing - event builders for reducing test boilerplate. [draft][PoC] Testing - event builders for reducing test boilerplate. Oct 24, 2025
@rita-codes rita-codes self-assigned this Oct 24, 2025
@rita-codes rita-codes added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. proof of concept scope: scheduler Changes related to the scheduler. labels Oct 24, 2025
@rita-codes rita-codes requested review from flaviendelangle and noraleonte and removed request for flaviendelangle October 24, 2025 11:00
@rita-codes rita-codes changed the title [draft][PoC] Testing - event builders for reducing test boilerplate. [PoC] Testing - event builders for reducing test boilerplate. Oct 24, 2025
Copy link
Member

@flaviendelangle flaviendelangle left a comment

Choose a reason for hiding this comment

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

One final comment and we are good to go.

Thanks for doing it!
It will make the tests a lot more robust and easy to manipulate!

@rita-codes rita-codes changed the title [PoC] Testing - event builders for reducing test boilerplate. [scheduler] Testing - event builders for reducing test boilerplate Nov 3, 2025
@rita-codes rita-codes merged commit 843853b into mui:master Nov 3, 2025
21 checks passed
bernardobelchior pushed a commit to bernardobelchior/mui-x that referenced this pull request Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: scheduler Changes related to the scheduler. test type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants