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

Angular 18 Update #2340

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Migration guide

## Migrating to JSON Forms 3.3

### Angular support now targets Angular 17 and Angular 18

When using JSON Forms 3.3, your Angular application now needs to target Angular 17 or 18.

Use JSON Forms 3.2 if you need to stay on Angular 16.

## Migrating to JSON Forms 3.2

### React Material Renderers using Outlined Inputs
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build:examples-app": "lerna run build:examples-app && node packages/examples-app/prepare-examples-app.js"
},
"devDependencies": {
"@angular/core": "^16.0.0",
"@angular/core": "^17.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.5",
"@babel/plugin-proposal-optional-chaining": "^7.16.5",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
Expand All @@ -44,7 +44,7 @@
"ts-loader": "^9.5.1",
"ts-node": "^10.4.0",
"tslib": "^2.5.0",
"typescript": "~4.9.5",
"typescript": "~5.2.2",
"webpack": "^5.78.0",
"webpack-merge": "^5.10.0"
}
Expand Down
61 changes: 30 additions & 31 deletions packages/angular-material/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
]
},
"peerDependencies": {
"@angular/animations": "^16.0.0 || ^17.0.0",
"@angular/cdk": "^16.0.0 || ^17.0.0",
"@angular/common": "^16.0.0 || ^17.0.0",
"@angular/core": "^16.0.0 || ^17.0.0",
"@angular/forms": "^16.0.0 || ^17.0.0",
"@angular/material": "^16.0.0 || ^17.0.0",
"@angular/platform-browser": "^16.0.0 || ^17.0.0",
"@angular/router": "^16.0.0 || ^17.0.0",
"@angular/animations": "^17.0.0 || ^18.0.0",
"@angular/cdk": "^17.0.0 || ^18.0.0",
"@angular/common": "^17.0.0 || ^18.0.0",
"@angular/core": "^17.0.0 || ^18.0.0",
"@angular/forms": "^17.0.0 || ^18.0.0",
"@angular/material": "^17.0.0 || ^18.0.0",
"@angular/platform-browser": "^17.0.0 || ^18.0.0",
"@angular/router": "^17.0.0 || ^18.0.0",
"@jsonforms/angular": "3.3.0-beta.0",
"@jsonforms/core": "3.3.0-beta.0",
"dayjs": "^1.11.7",
Expand All @@ -78,30 +78,29 @@
"lodash": "^4.17.21"
},
"devDependencies": {
"@angular-devkit/build-angular": "^16.0.0",
"@angular-devkit/core": "^16.0.0",
"@angular-eslint/eslint-plugin": "^16.0.0",
"@angular-eslint/eslint-plugin-template": "^16.0.0",
"@angular-eslint/schematics": "^16.0.0",
"@angular-eslint/template-parser": "^16.0.0",
"@angular/animations": "^16.0.0",
"@angular/cdk": "^16.0.0",
"@angular/common": "^16.0.0",
"@angular/compiler": "^16.0.0",
"@angular/compiler-cli": "^16.0.0",
"@angular/core": "^16.0.0",
"@angular/forms": "^16.0.0",
"@angular/material": "^16.0.0",
"@angular/platform-browser": "^16.0.0",
"@angular/platform-browser-dynamic": "^16.0.0",
"@angular/router": "^16.0.0",
"@angular-devkit/build-angular": "^17.0.0",
"@angular-devkit/core": "^17.0.0",
"@angular-eslint/eslint-plugin": "^17.0.0",
"@angular-eslint/eslint-plugin-template": "^17.0.0",
"@angular-eslint/schematics": "^17.0.0",
"@angular-eslint/template-parser": "^17.0.0",
"@angular/animations": "^17.0.0",
"@angular/cdk": "^17.0.0",
"@angular/common": "^17.0.0",
"@angular/compiler": "^17.0.0",
"@angular/compiler-cli": "^17.0.0",
"@angular/core": "^17.0.0",
"@angular/forms": "^17.0.0",
"@angular/material": "^17.0.0",
"@angular/platform-browser": "^17.0.0",
"@angular/platform-browser-dynamic": "^17.0.0",
"@angular/router": "^17.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.5",
"@babel/plugin-proposal-optional-chaining": "^7.16.5",
"@jsonforms/angular": "workspace:*",
"@jsonforms/angular-test": "workspace:*",
"@jsonforms/core": "workspace:*",
"@jsonforms/examples": "workspace:*",
"@ngtools/webpack": "^16.0.0",
"@ngtools/webpack": "^17.0.0",
"@types/jasmine": "~3.8.0",
"@types/lodash": "4.14.149",
"@types/node": "^18.19.4",
Expand All @@ -118,14 +117,14 @@
"http-server": "^14.1.1",
"jasmine": "^3.99.0",
"jasmine-spec-reporter": "^4.2.1",
"karma": "^6.4.1",
"karma": "^6.4.3",
"karma-chrome-launcher": "^3.2.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "^2.0.1",
"karma-jasmine-html-reporter": "^1.7.0",
"karma-sourcemap-loader": "^0.3.8",
"karma-webpack": "^5.0.0",
"ng-packagr": "^16.0.0",
"ng-packagr": "^17.0.0",
"null-loader": "^0.1.1",
"nyc": "^15.1.0",
"prettier": "^2.8.4",
Expand All @@ -135,9 +134,9 @@
"ts-loader": "^9.5.1",
"tslib": "^2.5.0",
"typedoc": "~0.25.3",
"typescript": "~4.9.5",
"typescript": "~5.2.2",
"webpack": "^5.78.0",
"yargs": "^17.7.2",
"zone.js": "~0.13.0"
"zone.js": "~0.14.0"
}
}
93 changes: 37 additions & 56 deletions packages/angular-material/test/autocomplete-control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ import {
} from '@angular/material/autocomplete';
import { MatError, MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { OverlayContainer } from '@angular/cdk/overlay';
import { DebugElement, NgZone } from '@angular/core';
import { DebugElement } from '@angular/core';
import {
ComponentFixture,
fakeAsync,
inject,
TestBed,
tick,
waitForAsync,
} from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
Expand All @@ -44,11 +43,15 @@ import {
ErrorTestExpectation,
setupMockStore,
getJsonFormsService,
} from '@jsonforms/angular-test';
} from './common';
import { ControlElement, JsonSchema, Actions } from '@jsonforms/core';
import { AutocompleteControlRenderer } from '../src';
import { JsonFormsAngularService } from '@jsonforms/angular';
import { ErrorObject } from 'ajv';
import { initTestEnvironment } from './test';
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatAutocompleteHarness } from '@angular/material/autocomplete/testing';

const data = { foo: 'A' };
const schema: JsonSchema = {
Expand Down Expand Up @@ -80,17 +83,19 @@ const errorTest: ErrorTestExpectation = {
indexOfElement: 0,
};

initTestEnvironment();

describe('Autocomplete control Base Tests', () => {
let fixture: ComponentFixture<AutocompleteControlRenderer>;
let component: AutocompleteControlRenderer;
let inputElement: HTMLInputElement;
beforeEach(() => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [componentUT],
imports: imports,
providers: providers,
}).compileComponents();
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(componentUT);
component = fixture.componentInstance;
Expand Down Expand Up @@ -211,40 +216,21 @@ describe('Autocomplete control Base Tests', () => {
describe('AutoComplete control Input Event Tests', () => {
let fixture: ComponentFixture<AutocompleteControlRenderer>;
let component: AutocompleteControlRenderer;
let inputElement: HTMLInputElement;
let overlayContainer: OverlayContainer;
let overlayContainerElement: HTMLElement;
let zone: NgZone;
beforeEach(() => {
let loader: HarnessLoader;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [componentUT],
imports: imports,
providers: [...providers],
}).compileComponents();

inject([OverlayContainer], (oc: OverlayContainer) => {
overlayContainer = oc;
overlayContainerElement = oc.getContainerElement();
})();
});
beforeEach(() => {
}));
beforeEach(waitForAsync(() => {
fixture = TestBed.createComponent(componentUT);
component = fixture.componentInstance;
zone = TestBed.inject(NgZone);
spyOn(zone, 'runOutsideAngular').and.callFake((fn: () => any) => fn());
inputElement = fixture.debugElement.query(By.css('input')).nativeElement;
});
loader = TestbedHarnessEnvironment.loader(fixture);
}));

afterEach(inject(
[OverlayContainer],
(currentOverlayContainer: OverlayContainer) => {
// Since we're resetting the testing module in some of the tests,
// we can potentially have multiple overlay containers.
currentOverlayContainer.ngOnDestroy();
overlayContainer.ngOnDestroy();
}
));
it('should update via input event', fakeAsync(() => {
it('should update via input event', fakeAsync(async () => {
setupMockStore(fixture, { uischema, schema, data });
getJsonFormsService(component).updateCore(
Actions.init(data, schema, uischema)
Expand All @@ -255,14 +241,12 @@ describe('AutoComplete control Input Event Tests', () => {

const spy = spyOn(component, 'onSelect');

inputElement.focus();
zone.runOutsideAngular(() => zone.onStable.emit(null));
await (await loader.getHarness(MatAutocompleteHarness)).focus();
fixture.detectChanges();

const options = overlayContainerElement.querySelectorAll(
'mat-option'
) as NodeListOf<HTMLElement>;
options.item(1).click();
await (
await loader.getHarness(MatAutocompleteHarness)
).selectOption({ text: 'B' });
tick();
fixture.detectChanges();

Expand All @@ -272,7 +256,7 @@ describe('AutoComplete control Input Event Tests', () => {

expect(event.option.value).toBe('B');
}));
it('options should prefer own props', fakeAsync(() => {
it('options should prefer own props', fakeAsync(async () => {
setupMockStore(fixture, { uischema, schema, data });
getJsonFormsService(component).updateCore(
Actions.init(data, schema, uischema)
Expand All @@ -283,33 +267,30 @@ describe('AutoComplete control Input Event Tests', () => {
fixture.detectChanges();
const spy = spyOn(component, 'onSelect');

inputElement.focus();
zone.runOutsideAngular(() => zone.onStable.emit(null));
await (await loader.getHarness(MatAutocompleteHarness)).focus();
fixture.detectChanges();

fixture.whenStable().then(() => {
const options = overlayContainerElement?.querySelectorAll(
'mat-option'
) as NodeListOf<HTMLElement>;
(options[1] as HTMLElement).click();
fixture.detectChanges();
tick();
const event = spy.calls.mostRecent()
.args[0] as MatAutocompleteSelectedEvent;
expect(event.option.value).toBe('Y');
});
await (
await loader.getHarness(MatAutocompleteHarness)
).selectOption({ text: 'Y' });
fixture.detectChanges();
tick();

const event = spy.calls.mostRecent()
.args[0] as MatAutocompleteSelectedEvent;
expect(event.option.value).toBe('Y');
}));
});
describe('AutoComplete control Error Tests', () => {
let fixture: ComponentFixture<AutocompleteControlRenderer>;
let component: AutocompleteControlRenderer;
beforeEach(() => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [componentUT],
imports: imports,
providers: providers,
}).compileComponents();
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(componentUT);
component = fixture.componentInstance;
Expand Down Expand Up @@ -349,13 +330,13 @@ describe('AutoComplete control updateFilter function', () => {
let fixture: ComponentFixture<AutocompleteControlRenderer>;
let component: AutocompleteControlRenderer;

beforeEach(() => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [componentUT],
imports: imports,
providers: providers,
}).compileComponents();
});
}));

beforeEach(() => {
fixture = TestBed.createComponent(componentUT);
Expand Down
5 changes: 4 additions & 1 deletion packages/angular-material/test/boolean-control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ import {
booleanErrorTest,
booleanInputEventTest,
ErrorTestExpectation,
} from '@jsonforms/angular-test';
} from './common';
import { BooleanControlRenderer, booleanControlTester } from '../src';
import { JsonFormsAngularService } from '@jsonforms/angular';
import { initTestEnvironment } from './test';

initTestEnvironment();

describe('Material boolean field tester', () => {
const uischema = {
Expand Down
Loading
Loading