Skip to content

Commit

Permalink
move e2e testing to app-dev (#10479)
Browse files Browse the repository at this point in the history
* move e2e testing to app-dev

This should take care of step 1 in #10419.

CHANGELOG_BEGIN
CHANGELOG_END

* change title
  • Loading branch information
garyverhaegen-da authored Aug 5, 2021
1 parent 6e0e46e commit 185f888
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
1 change: 0 additions & 1 deletion docs/configs/pdf/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Getting started
Building Your App <getting-started/index>
getting-started/app-architecture
getting-started/first-feature
getting-started/testing
Cheat Sheet <https://docs.daml.com/cheat-sheet>

Writing Daml
Expand Down
1 change: 1 addition & 0 deletions docs/redirects.map
Original file line number Diff line number Diff line change
Expand Up @@ -820,3 +820,4 @@ support.html -> /support/support.html
release-notes.html -> support/releases.html#release-notes
support/release-notes.html -> support/releases.html#release-notes
support/roadmap.html -> support/releases.html#roadmap
getting-started/testing.html -> app-dev/bindings-ts/testing.html
1 change: 1 addition & 0 deletions docs/source/app-dev/bindings-ts/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ and `@daml/ledger <daml-ledger/index.html>`_ libraries.
daml-react
daml-ledger
daml-types
testing
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.. Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
.. SPDX-License-Identifier: Apache-2.0
Testing Your App
****************
Testing Your Web App
********************

When developing your application, you will want to test that user flows work from end to end.
When developing a UI for your Daml application, you will want to test that user flows work from end to end.
This means that actions performed in the web UI trigger updates to the ledger and give the desired results on the page.
In this section we show how you can do such testing automatically in TypeScript (equally JavaScript).
This will allow you to iterate on your app faster and with more confidence!
Expand All @@ -20,6 +20,9 @@ run the following command in the ``ui`` directory::

npm add --only=dev puppeteer wait-on @types/jest @types/node @types/puppeteer @types/wait-on

Because these things are easier to describe with concrete examples, this
section will show how to set up end-to-end tests for the application you would
end with at the end of the :doc:`/getting-started/first-feature` section.

Setting up our tests
====================
Expand Down Expand Up @@ -61,7 +64,7 @@ This means we use Puppeteer to type text into input forms, click buttons and sea
In order to find those elements, we do need to make some adjustments in our React components, which we'll show later.
Let's start at a higher level with a ``test``.

.. literalinclude:: code/testing/index.test.ts
.. literalinclude:: ../../getting-started/code/testing/index.test.ts
:language: ts
:start-after: // LOGIN_TEST_BEGIN
:end-before: // LOGIN_TEST_END
Expand All @@ -87,7 +90,7 @@ We showed how to write a simple test at a high level, but haven't shown how to m
This was hidden in the ``login()`` and ``logout()`` functions.
Let's see how ``login()`` is implemented.

.. literalinclude:: code/testing/index.test.ts
.. literalinclude:: ../../getting-started/code/testing/index.test.ts
:language: ts
:start-after: // LOGIN_FUNCTION_BEGIN
:end-before: // LOGIN_FUNCTION_END
Expand All @@ -105,7 +108,7 @@ In this case we use *class selectors*, which look for CSS classes we've given to
This means we must manually add classes to the components we want to test.
For example, here is a snippet of the ``LoginScreen`` React component with classes added to the ``Form`` elements.

.. literalinclude:: code/templates-tarball/create-daml-app/ui/src/components/LoginScreen.tsx
.. literalinclude:: ../../getting-started/code/templates-tarball/create-daml-app/ui/src/components/LoginScreen.tsx
:language: tsx
:start-after: {/* FORM_BEGIN */}
:end-before: {/* FORM_END */}
Expand All @@ -121,7 +124,7 @@ Writing CSS Selectors
When writing CSS selectors for your tests, you will likely need to check the structure of the rendered HTML in your app by running it manually and inspecting elements using your browser's developer tools.
For example, the image below is from inspecting the username field using the developer tools in Google Chrome.

.. figure:: images/inspect-element.png
.. figure:: ../../getting-started/images/inspect-element.png

There is a subtlety to explain here due to the `Semantic UI <https://semantic-ui.com/>`_ framework we use for our app.
Semantic UI provides a convenient set of UI elements which get translated to HTML.
Expand All @@ -135,5 +138,5 @@ While harmless in this case, in general you may need to inspect the HTML transla
The Full Test Suite
===================

.. literalinclude:: code/testing/index.test.ts
.. literalinclude:: ../../getting-started/code/testing/index.test.ts
:language: ts
2 changes: 1 addition & 1 deletion docs/source/daml/intro/12_Testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This chapter is all about testing and debugging the Daml contracts you've built
- The ``trace`` and ``debug`` functions
- Contention

Note that this section only covers testing your Daml contracts. For more holistic application testing, please refer to :doc:`/getting-started/testing`.
Note that this section only covers testing your Daml contracts. For more holistic application testing, please refer to :doc:`/app-dev/bindings-ts/testing`.

If you no longer have your projects set up, please follow the setup instructions in :doc:`9_Dependencies` to get hold of the code for this chapter. There is no code specific to this chapter.

Expand Down
2 changes: 1 addition & 1 deletion docs/source/getting-started/first-feature.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,4 @@ We've gone through the process of setting up a full-stack Daml app and implement
As the next step we encourage you to really dig into the fundamentals of Daml and understand its core concepts such as parties, signatories, observers, and controllers.
You can do that either by :doc:`going through our docs </daml/intro/0_Intro>` or by taking an `online course <https://daml.com/learn/fundamental-concepts>`_.

After you've got a good grip on these concepts learn :doc:`how to conduct end-to-end testing of your app <testing>`.
After you've got a good grip on these concepts learn :doc:`how to conduct end-to-end testing of your app </app-dev/bindings-ts/testing>`.
1 change: 0 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Daml Documentation
Building Your App <getting-started/index>
getting-started/app-architecture
getting-started/first-feature
getting-started/testing
Cheat Sheet <https://docs.daml.com/cheat-sheet>

.. toctree::
Expand Down

0 comments on commit 185f888

Please sign in to comment.