architecture

mathpunk 2019-01-19T17:07:43.023600Z

I've got an ongoing big problem that I have to work around, and big surprise, it's related to state---

mathpunk 2019-01-19T17:08:56.024900Z

I write a lot of end-to-end tests: I dig around in the DOM of our application, discovering things I want to grab to click or fill in or select, etc, and adding test-hooks to the code that generates the markup.

mathpunk 2019-01-19T17:09:22.025400Z

So I write code that drives what the state of our application is, and I read to it and write to it as though I were a human user

mathpunk 2019-01-19T17:10:49.027Z

The most common mistake I make is thinking I'm in one application state when I'm not. So for instance, I have to open up an accordion to get at a button that will open a modal that I want to interact with, and I am not waiting long enough for the accordion animation

mathpunk 2019-01-19T17:10:51.027200Z

that kind of thing

mathpunk 2019-01-19T17:11:38.027900Z

I do have predicates I can call to find out things about the current application state

mathpunk 2019-01-19T17:12:39.029Z

but I thought I'd ask the #architecture crew if you think there's a strategy I should have in mind for this situation where I have state that I can't remove, cause I'm driving another program around into various states

mathpunk 2019-01-19T17:14:10.030500Z

my first half-baked solution is maybe I should create a model of the states and transitions available in the application, something viewable with graphviz, and use that to think with

2019-01-19T18:55:29.031Z

@mathpunk to me it sounds that the problem is that your e2e tests derive the application state

2019-01-19T18:55:43.031800Z

it seems a bit upside down

2019-01-19T18:55:59.032400Z

what i would personally do is take a bit of a "declarative" approach

2019-01-19T18:56:21.032900Z

e2e tests require a certain application state as a predicate

2019-01-19T18:56:27.033100Z

then they perform their test

2019-01-19T18:56:47.033700Z

optionally, you can have a separate component, that tries to get the application into the desired state

2019-01-19T18:56:58.034100Z

but this is completely separate from the actual test

2019-01-19T18:57:05.034400Z

the actual test should be just contracts

2019-01-19T18:57:23.034800Z

"provided state is X, if we do Y, then new state becomes Z"

2019-01-19T18:58:07.035500Z

then you can optionally have a completely separate utility that tries to get the application into desired state X

2019-01-19T18:58:27.035800Z

but this is fairly complex and error-prone

2019-01-19T18:58:49.036400Z

i would probably prefer to rebuild application state from scratch in a fixture, if that's possible

mathpunk 2019-01-19T20:25:45.036800Z

i do have separation of the tests from the components that command state

mathpunk 2019-01-19T20:26:33.037600Z

but the methods they have for setting state is that "complex and error prone" bit you're talking about

mathpunk 2019-01-19T20:27:11.038Z

thank you for your thoughts

2019-01-19T21:58:10.038700Z

have you looked at perhaps using something like https://github.com/reifyhealth/specmonstah ?