Chapter 2: Feedback
Overview
Alright! Now, we get to build more sophisticated functionality! But, before we dive in, we’ll review where we left off. Then, we’ll render a dialog, create a form, and handle our first events. Along the way, we’ll refactor for cleaner code, explore schemas, and implement permissions.
Training
Pre-requisites
- Understanding of the previous chapter,
building a dashboard
and adding a card with images and buttons.
Concepts Covered in This Chapter
Mercury
- Event-handling and communication via Mercury.Tests
- TDD by the 3 laws!Views
- The visual representation of your skill provided by the Heartwood Skill.Events
- Custom event creation and handling.Schemas
- Data validation and normalization through schemas.Permissions
- Controlling access with permission contracts.Listeners
- Listening for backend events and responding appropriately.Errors
- Handling and displaying errors effectively.
Tools Used in This Chapter
spruce-cli
- The Spruce Command Line Interface (CLI) is a tool that enables you create, build, and test your skills.vscode
- A free code editor that works on Windows, macOS, and Linux.- Development Theatre - The runtime that executes your skills.
Commands Used in This Chapter
Assertions
vcAssert.rendersDialogue
- Description: Asserts that a dialogue box is rendered on the view controller.
formAssert.formRendersField
- Description: Asserts that a specific field is rendered in the form.
assert.isFalse
- Description: Verifies that a specific condition or value is false.
formAssert.fieldRendersAs
- Description: Ensures that a form field is rendered as a specific type, e.g., a text area.
assert.isEqual
- Description: Checks that two values are equal.
assert.renders.alert
- Description: Confirms that an alert is displayed on the view.
form.cardRenderedForm
- Description: Asserts that a card renders a form.
form assert.field.renders
- Description: Verifies that a specific form field is rendered.
Events
eventFaker.on
- Description: Sets up a listener for a specified event to verify its behavior in tests.
eventFaker.makeEventThrow
- Description: Simulates an event throwing an error for testing purposes.
client.emit
- Description: Emits an event to a backend API.
client.emitAndFlattenResponses
- Description: Emits an event and simplifies the response structure, commonly used when responses contain nested data.
Forms
formVC.getValue
- Description: Retrieves the value of a specific field from the form.
formVc.setValue
- Description: Sets a value for a specific field in the form.
Views
controller.Factory
- Description: Creates a new instance of a controller for use in the application.
this.controller.card
- Description: Initializes a card view controller encapsulating the necessary view components.
this.render.in.dialogue
- Description: Renders a dialogue box with specific options and content.
build.form
- Description: Builds a form object with fields, sections, and schema definitions.
Listeners and Permissions
this.connect.to.API
- Description: Establishes a connection to the API for emitting or listening to events.
buildPermissionReference
- Description: Creates a reference for a permission contract, specifying roles and permissions.
permissions.sync
- Description: Synchronizes the permissions configuration to ensure it reflects the latest changes.
Terminal and CLI Commands
spruce watch.views
- Description: Watches for changes in views and rebuilds them automatically during development.
spruce create.view
- Description: Generates a new view controller file using the CLI.
spruce sync.events
- Description: Synchronizes the events configuration, ensuring event types and handlers are up-to-date.
spruce sync.permissions
- Description: Updates permission contracts and related configurations.
Schemas
spruce create.schema
- Description: Constructs a schema definition, including fields, types, and validation rules.
Test Doubles
SpyFeedbackCard
- Description: Defines a protected method used as a test case in the test framework.