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

[Issue 1163] Add additional tests #1169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dpmott
Copy link
Contributor

@dpmott dpmott commented Feb 12, 2020

[Issue 1163] Add additional tests

EDIT: This also fixes issue #1176

  • Rolled back changes to translate.directive.ts from commit 24b7b2b (but keeping tests)
  • Added additional tests.
  • Issue 1163 appears to have actually been fixed by 1167/1164, as evidenced by the newly added tests.

24b7b2b (but keeping tests), and adding additional tests. 1163 appears to have actually been fixed by 1167/1164, as evidenced by the newly added tests.
@@ -72,28 +72,21 @@ export class TranslateDirective implements AfterViewChecked, OnDestroy {
if (forceUpdate) {
node.lastKey = null;
}
if(isDefined(node.lookupKey)) {
key = node.lookupKey;
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 believe that the lookup key will prevent the translation of an updated interpolated bound template variable.

// the current content is the translation, not the key, use the last real content as key
key = node.originalContent.trim();
} else if (content !== node.currentValue) {
// we want to use the content as a key, not the translation value
key = trimmedContent;
// the content was changed from the user, we'll use it as a reference if needed
node.originalContent = content || node.originalContent;
node.originalContent = content;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because of the if (trimmedContent.length) conditional, content is guaranteed to be truthy, so the OR statement will never be executed.

NESTED.TEST.KEY
</div>
<div #interpolatedWithSpaceAndLineBreakNoKeyNoParams translate>
{{ myInterpolatedTranslationKey }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding tests for interpolated bound template variables.

@@ -51,7 +53,7 @@ describe('TranslateDirective', () => {
],
declarations: [App]
});
translate = TestBed.inject(TranslateService);
translate = TestBed.get(TranslateService);
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 saw that this had been recently changed, but the tests work either way, so I'm unsure why it changed?

If it needs to be .inject(), I'll happily put it back.

const fr2="Un autre test";
const setKey = key => {
fixture.componentInstance.myInterpolatedTranslationKey = key;
fixture.componentInstance.changeDetectorRef.markForCheck(); // Needed when changeDetection is ChangeDetectionStrategy.OnPush
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'm not sure why the test harness is configured with changeDetection: ChangeDetectionStrategy.OnPush, as this isn't the default for Angular. It's fine, but it also means that angular won't detect an interpolated variable change on its own, and we have to tell the change detector when to check for changes.

@judomu
Copy link

judomu commented Apr 28, 2020

We're having the same issue and so far I moved from directive to pipes to mitigate the issue, but it would be perfect to be able to use directive in all cases :)

@tiaguinho
Copy link

@ocombe can you take a look into this?

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.

3 participants