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

fix: test and visual testing update for otter training #2638

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

cpaulve-1A
Copy link
Contributor

Proposed change

Related issues

- No issue associated -

@cpaulve-1A cpaulve-1A requested a review from a team as a code owner December 19, 2024 18:35
Copy link

nx-cloud bot commented Dec 19, 2024

View your CI Pipeline Execution ↗ for commit bfa43cb.

Command Status Duration Result
nx run-many --target=build --projects=eslint-pl... ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2024-12-20 13:38:00 UTC

@github-actions github-actions bot added bug Something isn't working project:@o3r/showcase labels Dec 19, 2024
@@ -195,7 +195,9 @@ export class CodeEditorViewComponent implements OnDestroy {
*/
private readonly monacoPromise = firstValueFrom(this.newMonacoEditorCreated.pipe(
map(() => window.monaco)
));
)).catch(
(err) => console.error(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not use the logger instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we set a logger for now on the Otter showcase
If we don't have one set up, I would expect to do it in another PR

Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we let it throw? Lot of things will be broken if we don't have the global monaco instance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will throw if the monaco editor is never instantiated and the newMonacoEditorCreated subject is completed.
This is the case in the unit tests.
I could catch the monacoPromise in the tests themselves but that would require making it public and I prefer adding a catch than transforming a private property into a public one for testing purposes.

Copy link
Contributor

Choose a reason for hiding this comment

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

we should be able to test monaco-editor in the unit-tests? only the webcontainer part should be mocked?

@@ -195,7 +195,9 @@ export class CodeEditorViewComponent implements OnDestroy {
*/
private readonly monacoPromise = firstValueFrom(this.newMonacoEditorCreated.pipe(
Copy link
Contributor

Choose a reason for hiding this comment

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

To have a better typing for monacoPromise, maybe you can caught error in the observable and use the second parameter of firstValueFrom to define { defaultValue: undefined }

Copy link
Contributor

@matthieu-crouzet matthieu-crouzet Dec 20, 2024

Choose a reason for hiding this comment

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

Currently the typing is Promise<void | typeof Monaco>, the void comes from the .catch so adding { defaultValue: undefined } will change the type to Promise<void | typeof Monaco | undefined>
if we want to have Promise<typeof Monaco | undefined>, we should either have

(err) => {
      console.error(err);
      return undefined;
}

or

.catch<undefined>(...)

I checked the implementation of the option defaultValue it is used only if the subject newMonacoEditorCreated complete before providing a value.
implementation of firstValueFrom

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I think defaultValue might better fit my use case here.

@@ -12,6 +12,7 @@ import {
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [],
providers: [NgbActiveModal],
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 you have to add this ?
I don't see it on the bootstrap exemple

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I choose to put it here instead of inside the unit test to keep the SaveCodeDialog as a standalone, but maybe I should add it in the unit tests themselves.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I don't have opinion if it should be done one UT or in the component itself

Copy link
Contributor

Choose a reason for hiding this comment

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

I had a similar problem with markdown and I had to put it on the tests otherwise the component would not receive the instance provided globally (the global config for markdown was not applied)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will go for the same solution in that case

@cpaulve-1A cpaulve-1A force-pushed the merge-main-to-otter-training branch from 3b0e4b2 to bfa43cb Compare December 20, 2024 13:36
@cpaulve-1A cpaulve-1A merged commit ac5d4e7 into feat/otter-training Dec 20, 2024
2 checks passed
@cpaulve-1A cpaulve-1A deleted the merge-main-to-otter-training branch December 20, 2024 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working project:@o3r/showcase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants