Concrete
GuidesPreview your work

Write a fixture

Your section renders empty in dev, or you need it to render the content a fill would actually produce.

Goal

A fixture that states the content a fill would generate for one property, so concrete dev renders something real and concrete check has a corpus to grade.

Prerequisites

  • A property in the workspace — Add a sample property, or the one the starter copied in.
  • Fixtures for why dev data is data and why none of it reaches a bundle.

Steps

Declare it

A fixture is one property plus a content layer, stated in a JSON document. Here is a gallery section:

import { fact, fill, image, list, object, section, text } from "@homepages/concrete";

const photo = image({ label: "Photo", from: fact.property.property_media });

export const Gallery = section(
  {
    key: "gallery",
    label: "Gallery",
    slots: {
      caption: text.short({
        label: "Caption",
        cap: 40,
        source: fill.write({
          reads: [fact.property.description],
          brief: "Name what makes the property worth seeing. Write one sentence. Plain and short.",
        }),
      }),
      slides: list({
        label: "Slides",
        min: 3,
        max: 12,
        source: fill.pick({ brief: "The rooms worth showing, one photo per room." }),
        item: object({
          label: text.short({ cap: 40, source: fill.write({ reads: [fact.property.description, photo], brief: "Name the room the photo shows." }) }),
          fields: { photo },
        }),
      }),
    },
  },
  () => null,
);

and a content fixture stating what a fill would write for it:

fixtures/typical.json
{
  "$schema": "../.concrete/schema/content-fixture.schema.json",
  "property": "properties/riverside/property.json",
  "content": {
    "gallery-1": {
      "slots": {
        "caption": "Every room, south-facing",
        "slides": [
          { "photo": { "media": "deck" }, "label": "The deck at golden hour" },
          { "photo": { "media": "kitchen" }, "label": "Galley kitchen" }
        ]
      }
    }
  }
}

Then list it in the fixture list template.ts names:

fixtures/index.json
{
  "$schema": "../.concrete/schema/fixture-list.schema.json",
  "properties": ["properties/starter/property.json", "properties/riverside/property.json"],
  "fixtures": ["starter-home.json", "typical.json"]
}

Only a listed document is loaded, so the file name is the fixture's one name — typical — what the playground lists it by, and the list's order is the playground's. Its property is listed too, by its document; the property's name is its folder's, riverside. property is a path relative to the fixture, and content is keyed by instance: gallery-1 is the first placement of the section whose key is gallery.

State what a fill would write, and nothing else

Run concrete dev once and the $schema line has a schema to point at: your editor then completes slot ids and flags a wrong value as you type. Whether it does or not, concrete check grades the document against the template — a slot the section does not declare, a field an item does not declare, a video where an image belongs, an instance stated twice — as fixtures/document-invalid, and a value that fails is dropped, so its slot renders empty.

What slots states is the generative half. A slot bound to a fact or a row's member with source:, or derived by a compute(), resolves from the property itself, so stating one bare is reported — the fix is to edit the property, which is the thing that decides it, or to state the user's override, below.

Override a sourced slot as the user would

A user can still type over a sourced slot in the editor — a price written as "Offers over $1.2M" where the fact holds a number, a street the listing spells differently. The platform keeps that edit as the user's, so no later re-derive replaces it. A fixture states it the same way: the value in slots, and its mark under slot_overrides.scalar.

import { compute, fact, fill, object, section, text } from "@homepages/concrete";

const street = text.short({ label: "Street", cap: 60, source: fact.property.address.street });

export const Hero = section({ key: "hero", label: "Hero", slots: {
  headline: text.medium({
    label: "Headline",
    cap: 60,
    source: fill.write({ reads: [fact.property.description], brief: "Name what makes the property worth seeing. Write one sentence." }),
  }),
  street,
  shout: text.short({ label: "Shout", cap: 60, source: compute({ reads: [street] }, (value) => (value ?? "").toUpperCase()) }),
  place: object({
    label: compute(() => "Place"),
    fields: {
      city: text.short({ label: "City", cap: 40, source: fact.property.address.city }),
      note: text.short({ label: "Note", cap: 40, source: fill.write({ reads: [fact.property.description], brief: "A line about the area." }) }),
    },
  }),
} }, () => null);
{
  "property": "properties/riverside/property.json",
  "content": {
    "hero-1": {
      "slots": {
        "headline": "Every room, in daylight",
        "street": "One Riverside Walk",
        "place": { "note": "Steps from the river", "city": "Old Town" }
      },
      "slot_overrides": { "scalar": { "street": true, "place.city": true } }
    }
  }
}

A mark names a sourced slot — a value slot bound to a fact, a row's member or a compute() — or an object's sourced field as <object>.<field>. A sourced value stated without its mark is fixtures/document-invalid, and so is a mark on a value the instance does not state. null states a slot the user cleared.

Each override replaces what its source resolves to and is marked the user's, as the platform marks the edit. A slot that reads it re-derives from the user's value — the shout above reads "ONE RIVERSIDE WALK" — and the overridden slot carries the authored provenance chip in concrete dev.

Name media by upload id

Media is stated as a pick of this fixture's own property's uploads — { "media": "deck" }, never a path. A cropped image states its crop beside the pick, { "media": "deck", "crop": { "x": 0, "y": 0.1, "width": 1, "height": 0.75 } } — each a share of the image, 0 to 1 — and may add "mobile": { "crop": … }. An upload the property does not carry is fixtures/media-not-in-property. A contact's headshot or logo is not an upload, so it is named through the contact: { "media": "contact:jordan-avery:headshot" }, or logo_dark / logo_light.

State a list, a row and an object by its shape

Each kind takes the value its declaration derives:

  • A list of objects takes its items, each stating the fields it sets. The field that holds the element states the element — the photo of each slide above is the photo the list's pick would have chosen.

  • A list sourced by a table — units, comparables, contacts — states only the fields a fill writes, item by item in the property's own order; the fields its row reads stay the property's. More items than the property carries is fixtures/rows-not-in-property.

  • A row states the identity of the row it holds — the user's re-pick. Leave it out and it holds what its source yields.

  • An object states its fields, one by one, as the slots of a section are stated.

import { compute, fact, fill, list, object, row, section, text } from "@homepages/concrete";

const agent = row({ label: "Agent", from: fact.property.contacts });

export const Units = section({ key: "units", label: "Units", slots: {
  units: list({
    label: "Units",
    source: fact.property.units,
    item: (el) => {
      const unit = row({ label: "Unit", from: fact.property.units, source: el });
      const name = text.medium({ label: "Unit name", cap: 40, source: unit.label });
      return object({
        label: name,
        fields: {
          unit,
          name,
          summary: text.medium({ label: "Summary", cap: 120, source: fill.write({ reads: [fact.property.description, unit.beds], brief: "One line on the unit." }) }),
        },
      });
    },
  }),
  contact: object({
    label: compute(() => "Listing agent"),
    fields: {
      agent,
      tagline: text.short({ label: "Tagline", cap: 80, source: fill.write({ reads: [fact.property.description, agent.name], brief: "A line about the agent." }) }),
    },
  }),
} }, () => null);
{
  "property": "properties/riverside/property.json",
  "content": {
    "units-1": {
      "slots": {
        "units": [{ "summary": "Two bedrooms over the garden" }, { "summary": "The top-floor studio" }],
        "contact": { "tagline": "Twenty years selling the riverfront" }
      }
    }
  }
}

Name the instance when there are two

An instance id is the section's key and which placement it is: hero-1 for the first, hero-2 for a second placement of the same section, or the id a placement names with instance. A template that places the hero twice states each one under its own id:

{
  "property": "properties/riverside/property.json",
  "content": {
    "hero-1": { "slots": { "headline": "A cape by the water" } },
    "hero-2": { "slots": { "headline": "Every room, in daylight" } }
  }
}

An id the composition does not place is fixtures/instance-not-placed.

Keep it out of the bundle

No module template.ts reaches may import a file the fixture list reaches, or the sample library. A published bundle is an immutable artifact, and dev data has no business inside it — concrete check refuses either, naming the file (fixtures/reachable-from-bundle).

Verify

Run concrete dev: the fixture appears in the picker under its label, and the canvas renders your sections over it. An edit you make there stays in the browser; to keep it, make it in the document. A slot card with the authored provenance chip is one this fixture states; a fact chip is one the property decided.

Then concrete check. It renders every fixture, plus one synthesized variant per slot with that slot emptied — so the empty branch of everything you just stated is graded whether you wrote a fixture for it or not.

On this page