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

feat(chore): Angular 16 update #195

Merged
merged 25 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2ec74bb
chore update
tse018 Oct 4, 2023
7fbc782
Merge branch 'master' of https://github.com/transifex/transifex-javas…
tse018 Oct 4, 2023
7f269c7
Merge branch 'master' of https://github.com/transifex/transifex-javas…
tse018 Oct 4, 2023
836e603
update support versions
tse018 Oct 4, 2023
6069705
chore update
tse018 Oct 4, 2023
e001ca2
github.workflows
tse018 Oct 4, 2023
c244b76
Merge branch 'feat/chore/angular-update-v16' of https://github.com/ts…
tse018 Oct 4, 2023
7f46f34
working progress on github matrix
tse018 Oct 11, 2023
8cd294b
change on angular-version matrix
tse018 Oct 11, 2023
4c4d5a5
matrix change
tse018 Oct 11, 2023
c8919a7
angular 16 no support for node14
tse018 Oct 11, 2023
30155cd
chore update
tse018 Oct 4, 2023
1f7a408
update support versions
tse018 Oct 4, 2023
d323b92
github.workflows
tse018 Oct 4, 2023
e2a240c
chore update
tse018 Oct 4, 2023
326eb4b
working progress on github matrix
tse018 Oct 11, 2023
1d33e4f
change on angular-version matrix
tse018 Oct 11, 2023
83944a8
matrix change
tse018 Oct 11, 2023
20eaea0
angular 16 no support for node14
tse018 Oct 11, 2023
c60c2c6
Merge branch 'feat/chore/angular-update-v16' of https://github.com/ts…
tse018 Oct 12, 2023
b01a699
Merge branch 'master' into feat/chore/angular-update-v16
tse018 Oct 12, 2023
c4f71db
Merge https://github.com/transifex/transifex-javascript into feat/cho…
tse018 Jan 30, 2024
c819237
need zone.js version 13
tse018 Feb 1, 2024
e26eaef
Merge branch 'master' into feat/chore/angular-update-v16
tse018 Feb 1, 2024
a4df7cc
only support angular 16
tse018 Feb 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/angular/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,20 @@
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": ["**/*.spec.ts"],
"packageDir": "./" // Needed for angular library support
"devDependencies": [
"**/*.spec.ts"
],
"packageDir": "./"
}
],
"tsdoc/syntax": "warn",
"unicorn/filename-case": "off", // We are naming files with capitals
// I think some of these are silly. `e` is bad, but `err` and `exc` are decent. `user of users` is confusing, `usr of users` is safer.
"unicorn/filename-case": "off",
"unicorn/prevent-abbreviations": "off"
},
"settings": {
"import/resolver": {
"typescript": {
"alwaysTryTypes": true // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
"alwaysTryTypes": true
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions packages/angular/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/tx-native-angular-sdk/test.ts",
"polyfills": ["zone.js", "zone.js/testing"],
"tsConfig": "projects/tx-native-angular-sdk/tsconfig.spec.json",
"karmaConfig": "projects/tx-native-angular-sdk/karma.conf.js",
"codeCoverage": true
Expand All @@ -46,5 +46,12 @@
}
}
},
"defaultProject": "@transifex/angular"
"schematics": {
"@angular-eslint/schematics:application": {
"setParserOptionsProject": true
},
"@angular-eslint/schematics:library": {
"setParserOptionsProject": true
}
}
}
40 changes: 20 additions & 20 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@
},
"private": true,
"dependencies": {
"@angular/animations": "~14.3.0",
"@angular/common": "~14.3.0",
"@angular/compiler": "~14.3.0",
"@angular/core": "~14.3.0",
"@angular/forms": "~14.3.0",
"@angular/platform-browser": "^14.3.0",
"@angular/platform-browser-dynamic": "^14.3.0",
"@angular/router": "~14.3.0",
"@angular/animations": "~16.2.7",
"@angular/common": "~16.2.7",
"@angular/compiler": "~16.2.7",
"@angular/core": "~16.2.7",
"@angular/forms": "~16.2.7",
"@angular/platform-browser": "^16.2.7",
"@angular/platform-browser-dynamic": "^16.2.7",
"@angular/router": "~16.2.7",
"@transifex/native": "^7.0.1",
"rxjs": "~6.6.0",
"tslib": "^2.6.2",
"zone.js": "^0.11.8"
"zone.js": "^0.13.3"
},
"devDependencies": {
"@angular-devkit/architect": "^0.1402.11",
"@angular-devkit/build-angular": "^14.2.13",
"@angular-eslint/builder": "^14.4.0",
"@angular-eslint/eslint-plugin": "^14.4.0",
"@angular-eslint/eslint-plugin-template": "^14.4.0",
"@angular-eslint/schematics": "14.4.0",
"@angular-eslint/template-parser": "^14.4.0",
"@angular/cli": "^14.2.13",
"@angular/compiler-cli": "^14.3.0",
"@angular-devkit/architect": "^0.1602.4",
"@angular-devkit/build-angular": "^16.2.4",
"@angular-eslint/builder": "^16.2.0",
"@angular-eslint/eslint-plugin": "^16.2.0",
"@angular-eslint/eslint-plugin-template": "^16.2.0",
"@angular-eslint/schematics": "16.2.0",
"@angular-eslint/template-parser": "^16.2.0",
"@angular/cli": "^16.2.4",
"@angular/compiler-cli": "^16.2.7",
"@types/jasmine": "~4.0.0",
"@types/node": "^16.18.70",
"@typescript-eslint/eslint-plugin": "^5.62.0",
Expand All @@ -76,8 +76,8 @@
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.1.0",
"ng-packagr": "^14.2.2",
"ng-packagr": "^16.2.3",
"ts-node": "~8.3.0",
"typescript": "~4.6.4"
"typescript": "~4.9.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"rules": {
"@angular-eslint/component-selector": [
"off", // We are not following the angular styleguide to match other implementations
"off",
{
"prefix": "tx",
"style": "kebab-case",
Expand Down
6 changes: 3 additions & 3 deletions packages/angular/projects/tx-native-angular-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"repository": "git://github.com/transifex/transifex-javascript.git",
"license": "Apache-2.0",
"peerDependencies": {
"@angular/common": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0",
"@angular/core": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0",
"@transifex/native": "^7.0.0"
"@angular/common": "^16.0.0",
"@angular/core": " ^16.0.0",
"@transifex/native": "^7.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReplaySubject } from 'rxjs';
import { tx } from '@transifex/native';
import { ReplaySubject } from 'rxjs';

import { TComponent } from '../src/lib/T.component';
import { SafeHtmlPipe, TranslationService, TXInstanceComponent } from '../src/public-api';

import { TComponent } from '../lib/T.component';
import {
SafeHtmlPipe,
TranslationService,
TXInstanceComponent,
} from '../public-api';

describe('TComponent', () => {
let localeChangedSubject: ReplaySubject<string>;
Expand All @@ -30,16 +33,19 @@ describe('TComponent', () => {
await TestBed.configureTestingModule({
declarations: [TComponent, SafeHtmlPipe, TXInstanceComponent],
providers: [TXInstanceComponent],
})
.compileComponents();
}).compileComponents();

localeChangedSubject = new ReplaySubject<string>(0);

service = TestBed.inject(TranslationService);
instance = TestBed.inject(TXInstanceComponent);

spyOn(service, 'getCurrentLocale').and.returnValue('en');
localeChangedSpy = spyOnProperty(service, 'localeChanged', 'get').and.returnValue(localeChangedSubject);
localeChangedSpy = spyOnProperty(
service,
'localeChanged',
'get'
).and.returnValue(localeChangedSubject);
spyOn(service, 'setCurrentLocale').and.callFake(async (locale) => {
localeChangedSubject.next(locale);
});
Expand All @@ -54,8 +60,11 @@ describe('TComponent', () => {
it('should create the component', async () => {
// setup
spyOn(component, 'translate');
localeChangedSpy = spyOnProperty(component, 'localeChanged', 'get')
.and.returnValue(localeChangedSubject);
localeChangedSpy = spyOnProperty(
component,
'localeChanged',
'get'
).and.returnValue(localeChangedSubject);

// act
component.ngOnInit();
Expand All @@ -82,8 +91,11 @@ describe('TComponent', () => {
fixture.detectChanges();

// assert
expect(service.translate).toHaveBeenCalledWith('not-translated',
{ ...translationParams }, '');
expect(service.translate).toHaveBeenCalledWith(
'not-translated',
{ ...translationParams },
''
);
expect(component.translatedStr).toEqual('translated');
});

Expand All @@ -98,8 +110,11 @@ describe('TComponent', () => {
fixture.detectChanges();

// assert
expect(service.translate).toHaveBeenCalledWith('not-translated',
{ ...translationParams }, '');
expect(service.translate).toHaveBeenCalledWith(
'not-translated',
{ ...translationParams },
''
);
expect(component.translatedStr).toEqual('translated');
});

Expand All @@ -114,8 +129,11 @@ describe('TComponent', () => {
fixture.detectChanges();

// assert
expect(service.translate).toHaveBeenCalledWith('not-translated',
{ ...translationParams, _key: 'key-not-translated' }, '');
expect(service.translate).toHaveBeenCalledWith(
'not-translated',
{ ...translationParams, _key: 'key-not-translated' },
''
);
expect(component.translatedStr).toEqual('translated');
});

Expand All @@ -130,8 +148,9 @@ describe('TComponent', () => {

// assert
const compiled = fixture.debugElement.nativeElement;
expect((compiled as HTMLDivElement).innerHTML)
.toContain('&lt;a&gt;translated&lt;/a&gt;');
expect((compiled as HTMLDivElement).innerHTML).toContain(
'&lt;a&gt;translated&lt;/a&gt;'
);
});

it('should translate and sanitize the string', () => {
Expand All @@ -146,8 +165,9 @@ describe('TComponent', () => {

// assert
const compiled = fixture.debugElement.nativeElement;
expect((compiled as HTMLDivElement).innerHTML)
.toContain('<span><a>translated</a></span>');
expect((compiled as HTMLDivElement).innerHTML).toContain(
'<span><a>translated</a></span>'
);
});

it('should detect input parameters change and translate', () => {
Expand All @@ -158,14 +178,15 @@ describe('TComponent', () => {
// act
service.translate('test', { ...translationParams });
component.str = 'other-value';
component.ngOnChanges()
component.ngOnChanges();
fixture.detectChanges();

// assert
expect(service.translate).toHaveBeenCalled();
const compiled = fixture.debugElement.nativeElement;
expect((compiled as HTMLDivElement).innerHTML)
.toContain('&lt;a&gt;translated&lt;/a&gt;');
expect((compiled as HTMLDivElement).innerHTML).toContain(
'&lt;a&gt;translated&lt;/a&gt;'
);
});

it('should detect localeChange and translate', async () => {
Expand All @@ -183,8 +204,11 @@ describe('TComponent', () => {
fixture.detectChanges();

// assert
expect(service.translate).toHaveBeenCalledWith('not-translated',
{ ...translationParams, _key: 'key-not-translated' }, '');
expect(service.translate).toHaveBeenCalledWith(
'not-translated',
{ ...translationParams, _key: 'key-not-translated' },
''
);
expect(component.translatedStr).toEqual('translated-again');
});

Expand All @@ -203,11 +227,15 @@ describe('TComponent', () => {
fixture.detectChanges();

// assert
expect(service.translate).toHaveBeenCalledWith('not-translated', {
...translationParams,
_key: 'key-not-translated',
_context: 'late',
}, '');
expect(service.translate).toHaveBeenCalledWith(
'not-translated',
{
...translationParams,
_key: 'key-not-translated',
_context: 'late',
},
''
);
expect(component.translatedStr).toEqual('translated');
});

Expand All @@ -223,8 +251,11 @@ describe('TComponent', () => {
fixture.detectChanges();

// assert
expect(service.translate).toHaveBeenCalledWith('not-translated',
{ ...translationParams }, 'instance-alias');
expect(service.translate).toHaveBeenCalledWith(
'not-translated',
{ ...translationParams },
'instance-alias'
);
expect(component.translatedStr).toEqual('translated');
});

Expand All @@ -245,24 +276,26 @@ describe('TComponent', () => {
expect(service.translate).toHaveBeenCalled();
});

it('should detect translationsFetched using alternative instance',
async () => {
// setup
instance.token = 'instance-token';
instance.alias = 'instance-alias';
spyOn(service, 'translate').and.returnValue('translated');

// act
component.str = 'not-translated';
component.ngOnInit();
fixture.detectChanges();

// change
await service.fetchTranslations('tag1');
fixture.detectChanges();

// assert
expect(service.translate).toHaveBeenCalledWith('not-translated',
{ ...translationParams }, 'instance-alias');
});
it('should detect translationsFetched using alternative instance', async () => {
// setup
instance.token = 'instance-token';
instance.alias = 'instance-alias';
spyOn(service, 'translate').and.returnValue('translated');

// act
component.str = 'not-translated';
component.ngOnInit();
fixture.detectChanges();

// change
await service.fetchTranslations('tag1');
fixture.detectChanges();

// assert
expect(service.translate).toHaveBeenCalledWith(
'not-translated',
{ ...translationParams },
'instance-alias'
);
});
});
Loading
Loading