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
VC assert.renders.dialogue
- Description: Asserts that a dialogue box is rendered on the view controller.
VC assert.renders.field
- Description: Asserts that a specific field is rendered in the form.
assert.is.false
- Description: Verifies that a specific condition or value is false.
form assert.field.renders.as
- Description: Ensures that a form field is rendered as a specific type, e.g., a text area.
assert.is.equal
- Description: Checks that two values are equal.
assert.renders.alert
- Description: Confirms that an alert is displayed on the view.
Event Handling
event Faker.on
- Description: Sets up a listener for a specified event to verify its behavior in tests.
event Faker.make.event.throw
- Description: Simulates an event throwing an error for testing purposes.
client.emit
- Description: Emits an event to a backend API.
client.emit.and.flatten.responses
- Description: Emits an event and simplifies the response structure, commonly used when responses contain nested data.
View Controllers and Forms
form VC.get value
- Description: Retrieves the value of a specific field from the form.
form VC.render
- Description: Renders a form in the view controller.
form VC.set value
- Description: Sets a value for a specific field in the form.
form assert.rendered.form
- Description: Asserts that a form is correctly rendered.
form assert.field.renders
- Description: Verifies that a specific form field is rendered.
View Setup
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.
Listener and Permissions
this.connect.to.API
- Description: Establishes a connection to the API for emitting or listening to events.
build.permission.reference
- 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
watch.views
- Description: Watches for changes in views and rebuilds them automatically during development.
create.view
- Description: Generates a new view controller file using the CLI.
sync.events
- Description: Synchronizes the events configuration, ensuring event types and handlers are up-to-date.
sync.permissions
- Description: Updates permission contracts and related configurations.
Schema and Data Handling
build.schema
- Description: Constructs a schema definition, including fields, types, and validation rules.
normalize.against.schema
- Description: Adjusts an object to match a defined schema, including type conversions and default values.
General Functions
handle.click.feedback
- Description: Handles click events on the feedback button and triggers corresponding actions.
handle.submit
- Description: Handles form submission logic, including validation and event emission.
submit.feedback
- Description: Submits the feedback to the backend by emitting an event.
Test Utilities
test.protected.static
- Description: Defines a protected static method used as a test case in the test framework.
this.VC.getformVC
- Description: Retrieves the form view controller from a parent view controller.