Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Technical requirements for behavioural unit tests #5084

Merged
merged 50 commits into from
Mar 31, 2022

Conversation

Iku-turso
Copy link
Contributor

@Iku-turso Iku-turso commented Mar 23, 2022

Implement a lot of technical requirements for behavioural unit tests

With this:

  1. Routes and parameters related are strongly typed
  2. Routes exist in all environments making usage transparent
  3. Routes and related phenomena comply to Open Closed Principle (eg. what it means to be a new route does not require modification of existing code, but new code)
  4. Behavioural unit tests are possible (see Behavioural unit tests for navigation and reference #5085)

Note: the crux of this was to make routing env-agnostic, and not based on URLs as magic strings, but instead something type-enforced.

Note: extension-based routes comply to same exact interface by "late-registering" their routes when installed. Routes are injectables which implement a shared injection token.

Note: another chunk of global shared state is no more.

Note: a lot of stuff has become reactive as part if this.

Note: a lot of explicit side effects have been cornered to injectables with causesSideEffects: true.

Note: old unit tests which want to test what is causesSideEffects: true can now do so with di.permitSideEffects(someInjectable);.

@Iku-turso Iku-turso requested a review from a team as a code owner March 23, 2022 16:10
@Iku-turso Iku-turso requested review from jakolehm, jim-docker and Nokel81 and removed request for a team March 23, 2022 16:10
@Iku-turso Iku-turso force-pushed the technical-requirements-for-behavioural-tests branch from fbb7fe2 to d99771b Compare March 23, 2022 16:54
@Nokel81 Nokel81 added this to the 5.5.0 milestone Mar 23, 2022
"@ogre-tools/injectable-react": "5.1.2",
"@ogre-tools/injectable": "5.2.0",
"@ogre-tools/injectable-react": "5.2.0",
"@ogre-tools/fp": "5.2.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to raise notice against using this. I find that even with types pipeline is very hard to read. I would like to motion that chaining is better ergonomically.

Copy link
Contributor Author

@Iku-turso Iku-turso Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opinion noted! :)

Given a bit of time and familiarity, the pattern of pipeline will once again present itself as very easy to read, instead of anything else. This will become more apparent in more complex algorithms.

As with most design patterns, truly realized ergonomy comes from repetition ;)

Noteworthy: pipeline has multiple advantages over the proposed Collection chaining -pattern:

  1. Better support for functional composition, and other functional patterns, such as flow or ternary functions.
  2. Better refactorability, especially for nested or recursed scenarios.
  3. Power to control flow and aspect: eg. if required, pipeline can abstract promises and even generators.
  4. Full control of vocabulary (and not just map, reduce, filter, etc.) leads to more expressive code.
  5. It can be used for other than collections (yet, so can eg. lodash.chain, but then again this).
  6. Etc.

We used Collection chaining for years before growing out of it. As with everything, we do not use something like pipeline to flex, but instead for the necessity of the Greater good ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the pipeline syntax is good, but I'm a bit wary of adding this particular dependency, which appears to be quite a thin wrapper over lodash. This dependency has really small usage. Perhaps there's another alternative that is more commonly used in the ecosystem.

Copy link
Contributor Author

@Iku-turso Iku-turso Mar 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@panuhorsmalahti hmm, interesting point. Here's some thoughts:

  1. We control this library ourselves, and for that, it is flexible and without magic.

  2. We created the library only recently, and therefore there is yet little adoption in the ecosystem.

  3. We could have implemented this function in Lens as well, but it is pretty general to be local. Eg., also injectable uses it.

  4. To look for an alternative full foreign library for this "thin wrapper" is a bit of an overkill, as the proposed pattern is universal, and does not require certain library to work properly with. Instead, any function with arity of one can participate in composition. Therefore a full alternate library would add extra weight with all the other bells and whistles. I mean, we already have lodash.

@Iku-turso Iku-turso force-pushed the technical-requirements-for-behavioural-tests branch 2 times, most recently from 27100d9 to 0e7fe20 Compare March 25, 2022 14:15
src/common/hotbar-store.ts Outdated Show resolved Hide resolved
@jansav jansav removed the area/tests label Mar 28, 2022
@Iku-turso Iku-turso force-pushed the technical-requirements-for-behavioural-tests branch from 075a647 to 799e43b Compare March 28, 2022 07:48
jansav
jansav previously approved these changes Mar 28, 2022
@github-actions
Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@Iku-turso Iku-turso force-pushed the technical-requirements-for-behavioural-tests branch from 799e43b to 0835fa6 Compare March 28, 2022 12:51
@github-actions
Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

src/common/logger.ts Outdated Show resolved Hide resolved
src/common/user-store/user-store.injectable.ts Outdated Show resolved Hide resolved
src/common/utils/buildUrl.ts Outdated Show resolved Hide resolved
src/common/utils/is-allowed-resource.injectable.ts Outdated Show resolved Hide resolved
src/common/rbac.ts Outdated Show resolved Hide resolved
@Iku-turso Iku-turso force-pushed the technical-requirements-for-behavioural-tests branch from 9352219 to 3c86646 Compare March 29, 2022 10:57
Copy link
Contributor

@jim-docker jim-docker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still going...

import { getInjectable } from "@ogre-tools/injectable";
import navigateToAppPreferencesInjectable from "./app/navigate-to-app-preferences.injectable";

const navigateToPreferencesInjectable = getInjectable({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this? Can't navigateToAppPreferencesInjectable be used directly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to navigate to first page of preferences you should use navigateToPreferences. If you want to navigate to specific tab in preferences, you should use e.g. navigateToAppPreferences.

Motivation is to allow change of mind in future without need for multiple modifications.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean so one day navigateToAppPreferences may take optional param(s) to select the tab?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. navigateToAppPreferences doesn't need any parameters. However we might change our mind that navigateToPreferences doesn't go to app preferences. One day it might go to editor preferences and for that change we would need to change lot of file instead of one.

Implementation for navigateToPreferences could even be "go to first tab in preferences" and it shouldn't need to know which tab is first. In that case navigateToPreferences doesn't have to change at all if someday we change order of tabs in preferences.

Copy link
Collaborator

@Nokel81 Nokel81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do more reviewing today.

src/extensions/extension-loader/extension-loader.ts Outdated Show resolved Hide resolved
src/common/rbac.ts Outdated Show resolved Hide resolved
jansav and others added 17 commits March 31, 2022 15:13
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
…icit side effect

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
…e effect

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
…ution

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
@jansav jansav force-pushed the technical-requirements-for-behavioural-tests branch from 0c72746 to 7915e04 Compare March 31, 2022 12:16
@github-actions
Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

Copy link
Collaborator

@Nokel81 Nokel81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My qualms about some specific design aspects should be all non-breaking to fix later.

@jansav jansav merged commit a277cfc into master Mar 31, 2022
@jansav jansav deleted the technical-requirements-for-behavioural-tests branch March 31, 2022 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants