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

Prevent font chooser open error listing #638

Merged

Conversation

hernanmd
Copy link
Member

@hernanmd hernanmd commented Dec 6, 2023

Issue

Opening font chooser with a non-existent font family raises an exception.

Solution

Try updating Font Chooser with the selected font; if not found, inform and select the first available font family and style.

Add tests

Fixes #637.

Hernán Morales Durand added 3 commits December 6, 2023 16:07
…ected aFont.

If we do not find a font family matching aFont (for example not yet loaded fonts), inform and then select the first family in the system.
If we do not find a font style, select the first one available as initial style
@hernanmd
Copy link
Member Author

hernanmd commented Dec 6, 2023

@Ducasse Ducasse merged commit 10aba7b into pharo-spec:Pharo12 Dec 10, 2023
1 of 2 checks passed
@@ -347,13 +347,18 @@ StFontChooserPresenter >> updatePreview [

{ #category : 'initialization' }
StFontChooserPresenter >> updateWithFont: aFont [
"Try to update the receiver's listing with the selected aFont.
If we do not find a font family matching aFont (for example not yet loaded fonts), inform and then select the first family in the system.
If we do not find a font style, select the first one available as initial style"

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I would select the first one.
Why not just abort the current update of font?

Copy link
Member Author

Choose a reason for hiding this comment

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

Christoph could you reproduce the bug in your image? (note that it requires you to select a non default font). It is not about canceling to open the lookup but to prevent an error when you have already a configured font.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just reproduced the problem.
I do not know where this presenter is used but If I understand correctly, this presenter can only works if a font is selected, right?
In this case, the fix is ok.

self shouldnt: [
| window |
window := presenter open.
window close ] raise: Error
Copy link
Contributor

Choose a reason for hiding this comment

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

The goal of a test is to capture an error if any.
Then shouldnt: raise: Error is useless but the test is also useless.
The method should just be named openPresenter.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand. The presenter configured in the setUp fails to open if the fix in the PR is not applied. As stated in the issue:

| fontChooser presenter |

fontChooser := FontChooser newWithAllFamilies
	title: 'Title';
	font: (LogicalFont
		familyName: 'Arial'
		pointSize: 11
		stretchValue: 5
		weightValue: 300
		slantValue: 0);
	onAcceptDo: [ : e | self halt ].
presenter := StFontChooserPresenter on: fontChooser.
presenter open.

See the following screenshot:
Screenshot 2023-12-11 at 16 46 45

The method is named openPresenterShouldntRaiseError since it is common code called from multiple tests:

StFontChooserPresenterTest>>#testOpenAllOnNonExistantFontFamily StFontChooserPresenterTest>>#testOpenDefaultOnUnloadedFontFamily StFontChooserPresenterTest>>#testOpenDefaultOnNonExistantFontFamily StFontChooserPresenterTest>>#testOpenAllOnUnloadedFontFamily

Copy link
Contributor

Choose a reason for hiding this comment

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

What I mean is that a method test should never include:

self shouldnt: [ ] raise: Error

It is the purpose of the test framework to capture all Errors and to make your test fail if any.
It would only make sense if you wanted to check for a specific error that should not happen.
You should rename StFontChooserPresenterTest>>#openPresenterShouldntRaiseError to StFontChooserPresenterTest>>#openPresenter with:

openPresenter

	| window | 
	window := presenter open.
	window close 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Font family listing defaults to nil and prevents font chooser to open
3 participants