Fifthtry

Testing Internals

Realm’s test framework is implemented by Realm/Test.elm.

Lets look at a simple test first:

import Realm.Test as RT


main =
    RT.app { tests = tests, title = "hello" }

Here we are using RT.app function as our main method, this is how it looks like:

app : Config -> Program () Model Msg
app config =
    B.application
        { init = init config
        , view = document
        , update = update
        , subscriptions = subscriptions
        , onUrlRequest = always NoOp
        , onUrlChange = always NoOp
        }

app uses Browser.application as underlying app.

Lets declare a test:

tests : List RT.Test
tests =
    [ { id = id, context = [], steps = index } ]

Lets review RT.Test:

type alias Test =
    { id : String
    , context : List ( String, JE.Value )
    , steps : List Step
    }

index : List RT.Step index = [ RT.Navigate Index.anonymousEmpty Routes.index ]

What does RT.Navigate do?

RT.Navigate helps us in sending a GET request to an endpoint and receiving an HTML page in return where we can check what data was passed on the Page’s Config.

What does RT.SubmitForm Do?

RT.SubmitForm first sends a POST request to the server allowing it to perform some operations, then sends a GET request at the same endpoint and to find a HTML Page with data same as in GET method. This is currently buggy since we are only supposed to send 1 POST request and skip GET request.

What does RT.Api do?

Explain RT.Api

What does RT.apiOk do?

This verifies whether JSON Response object contains the fields result with value "ok" (String) and success with value true (Boolean). To return such a type of JSON object we call the method realm::json_ok() in the backend.

What does RT.apiError do?

This verifies whether JSON Response object contains the fields success with value true (Boolean) and a field called error which contains an object with key, value pair containing what all went wrong. To return such a type of JSON object we call the method realm::error(<key>, <message>) in the backend.

What does RT.apiTrue/RT.apiFalse do?

RT.apiTrue and RT.apiFalse both verify whether JSON Response object contains the field success with value true and false (Boolean) respectively. To return such a type of JSON object we call the method realm::json(&true)/realm::json(&false) respectively in the backend. In the both the cases, it will test whether the response contains a field success with value true.

What does RT.FormError do?

RT.FormError helps us in sending a POST request to an endpoint and the backend would return a response containing an issue in the format key and value. The second parameter to the function RT.FormError takes a function RT.only with two parameters, first one being the key of the error and the second being value of the error. So, this way we can check if the endpoint we hit returned the error of the key, value pair we are expecting.

Table Of Content

What is Realm?

A Bit On Motivation

Routing is Hard

What does Realm do?

Backend Data And Type Safety

Tutorial

Quick Start Realm Tutorial

In Depth Tutorial (not ready)

Nix
Shell
Doit
Hello Rust
Hello Elm
Hello Static Files
Hello Server Side Rendering
Pre-Commit Hooks

Routing, Request And Response

Frontend, Data, Navigation, And APIs

How To Guides

File Upload

Backend: S3 File Upload
Authenticated File Serving
Frontend: Uploading Files From Elm

How to use storybook?

How to implement “loading..”?

Docs

Realm.In

Realm.Storybook.Story

realm::In

realm::Context

realm::Result

realm.magicSlice

realm::RequestConfig

Environment Variables

Internals - Only for Realm Developers, not Users

“Realm DATA”
iFrame Controller
Shutdown Routine
Testing Internals

Change Log

Get Realm Starter Working

Transparent Offline Feature

How to make http requests in Realm?

Development

Tutorial: ToDo App

Realm Testing

Enhance Realm Starter

Double Load Issue

Deploy To Heroku Button

End failure

Realm-Starter Github Template

Proposal: Tracker And Visit

Proposal: Activity Store

Proposal: Bundling

Proposal: Retry On Network Error

Storybook: Editable JSON

Storybook: Notes

Storybook: Reference

Backlog

Readings

Change Log

How to Publish

Testing

Code Snippets

Skip rustfmt For Some Section

Close Modal Dialog When Clicked Outside

Ignoring Lints In Python

Ignoring Lints (clippy and rustc warnings) In Rust

Handle DateTime in Rust & Elm

Handle CiText value read in Rust

Transport Enum Type to and fro Rust/Elm through JSON