Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

Commit 7c600de

Browse files
committed
Merge branch 'b31.1.0'
# Conflicts: # charts-community-modules/ag-charts-vue/dist/ag-charts-vue.common.js # charts-community-modules/ag-charts-vue/dist/ag-charts-vue.umd.js # grid-enterprise-modules/charts-enterprise/LICENSE.html # grid-examples/ag-grid-angular-cli-example # grid-examples/ag-grid-angular-cli-package-example # grid-examples/ag-grid-react-example # grid-examples/ag-grid-react-package-example # grid-examples/ag-grid-solid-example # grid-examples/ag-grid-solid-package-example # grid-examples/ag-grid-vue-example # grid-examples/ag-grid-vue-package-example # grid-examples/ag-grid-vue3-example # grid-examples/ag-grid-vue3-package-example Merge branch 'b31.1.0'
2 parents c368c17 + d35d87d commit 7c600de

12 files changed

+1226
-43
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ To do a prod build (with AOT):
3232
- `npm run build`
3333

3434
The build artifacts will be stored in the `dist/` directory.
35+
36+

karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ module.exports = function (config) {
4242
restartOnFileChange: true,
4343
// not strictly required for testing but useful when debugging the grid in action
4444
files: [
45-
'../node_modules/@ag-grid-community/styles/ag-grid.css',
46-
'../node_modules/@ag-grid-community/styles/ag-theme-balham.css'
45+
'./node_modules/@ag-grid-community/styles/ag-grid.css',
46+
'./node_modules/@ag-grid-community/styles/ag-theme-balham.css'
4747
]
4848
});
4949
};

package.json

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ag-grid-angular-cli-example",
3-
"version": "31.0.2",
3+
"version": "31.1.0",
44
"description": "AG Grid Angular Example Using Angular CLI",
55
"license": "MIT",
66
"repository": {
@@ -12,24 +12,26 @@
1212
"start": "NODE_OPTIONS=--openssl-legacy-provider ng serve --port 8080",
1313
"build": "NODE_OPTIONS=\"--openssl-legacy-provider --max-old-space-size=8192\" ng build --aot",
1414
"build-prod": "npm run build",
15-
"lint": "tslint \"src/**/*.ts\""
15+
"lint": "tslint \"src/**/*.ts\"",
16+
"test:e2e": "NODE_OPTIONS=--openssl-legacy-provider ./node_modules/.bin/ng test --watch false --browsers ChromeHeadless",
17+
"test:watch": "NODE_OPTIONS=--openssl-legacy-provider ./node_modules/.bin/ng test --watch true --browsers ChromeHeadless"
1618
},
1719
"private": true,
1820
"dependencies": {
19-
"@ag-grid-community/angular": "~31.0.2",
20-
"@ag-grid-community/core": "~31.0.2",
21-
"@ag-grid-community/client-side-row-model": "~31.0.2",
22-
"@ag-grid-enterprise/core": "~31.0.2",
23-
"@ag-grid-enterprise/menu": "~31.0.2",
24-
"@ag-grid-enterprise/side-bar": "~31.0.2",
25-
"@ag-grid-enterprise/column-tool-panel": "~31.0.2",
26-
"@ag-grid-enterprise/filter-tool-panel": "~31.0.2",
27-
"@ag-grid-enterprise/row-grouping": "~31.0.2",
28-
"@ag-grid-enterprise/set-filter": "~31.0.2",
29-
"@ag-grid-enterprise/status-bar": "~31.0.2",
30-
"@ag-grid-enterprise/range-selection": "~31.0.2",
31-
"@ag-grid-enterprise/charts": "~31.0.2",
32-
"@ag-grid-community/styles": "~31.0.2",
21+
"@ag-grid-community/angular": "~31.1.0",
22+
"@ag-grid-community/core": "~31.1.0",
23+
"@ag-grid-community/client-side-row-model": "~31.1.0",
24+
"@ag-grid-enterprise/core": "~31.1.0",
25+
"@ag-grid-enterprise/menu": "~31.1.0",
26+
"@ag-grid-enterprise/side-bar": "~31.1.0",
27+
"@ag-grid-enterprise/column-tool-panel": "~31.1.0",
28+
"@ag-grid-enterprise/filter-tool-panel": "~31.1.0",
29+
"@ag-grid-enterprise/row-grouping": "~31.1.0",
30+
"@ag-grid-enterprise/set-filter": "~31.1.0",
31+
"@ag-grid-enterprise/status-bar": "~31.1.0",
32+
"@ag-grid-enterprise/range-selection": "~31.1.0",
33+
"@ag-grid-enterprise/charts": "~31.1.0",
34+
"@ag-grid-community/styles": "~31.1.0",
3335
"@angular/animations": "^14.3.0",
3436
"@angular/common": "^14.3.0",
3537
"@angular/compiler": "^14.3.0",
@@ -47,8 +49,10 @@
4749
"@angular-devkit/build-angular": "^14.2.12",
4850
"@angular/cli": "^14.2.12",
4951
"@angular/compiler-cli": "^14.3.0",
52+
"@testing-library/angular": "^12.3.0",
53+
"@testing-library/user-event": "^14.5.2",
5054
"@types/jasmine": "~3.8.0",
51-
"@types/node": "^12.11.1",
55+
"@types/node": "18.19.10",
5256
"jasmine-core": "~3.8.0",
5357
"karma": "~6.3.0",
5458
"karma-chrome-launcher": "~3.1.0",

src/app/rich-grid-example/rich-grid.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ <h1>Rich Grid Example</h1>
1515
</span>
1616
<span style="float: right">
1717
Column API:
18-
<button (click)="this.api.setColumnVisible('country', false)" class="btn btn-primary">Hide Country Column</button>
19-
<button (click)="this.api.setColumnVisible('country', true)" class="btn btn-primary">Show Country Column</button>
18+
<button (click)="this.api.setColumnsVisible(['country'], false)" class="btn btn-primary">Hide Country Column</button>
19+
<button (click)="this.api.setColumnsVisible(['country'], true)" class="btn btn-primary">Show Country Column</button>
2020
</span>
2121
</div>
2222
</div>

src/test.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
22

3-
import 'zone.js/dist/long-stack-trace-zone';
4-
import 'zone.js/dist/proxy.js';
5-
import 'zone.js/dist/sync-test';
6-
import 'zone.js/dist/jasmine-patch';
7-
import 'zone.js/dist/async-test';
8-
import 'zone.js/dist/fake-async-test';
9-
import {getTestBed} from '@angular/core/testing';
10-
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing';
3+
import 'zone.js';
4+
import 'zone.js/testing';
5+
import { getTestBed } from '@angular/core/testing';
6+
import {
7+
BrowserDynamicTestingModule,
8+
platformBrowserDynamicTesting
9+
} from '@angular/platform-browser-dynamic/testing';
1110

12-
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
13-
declare var __karma__: any;
14-
declare var require: any;
15-
16-
// Prevent Karma from running prematurely.
17-
__karma__.loaded = function () {
11+
declare const require: {
12+
context(path: string, deep?: boolean, filter?: RegExp): {
13+
keys(): string[];
14+
<T>(id: string): T;
15+
};
1816
};
1917

2018
// First, initialize the Angular testing environment.
2119
getTestBed().initTestEnvironment(
22-
BrowserDynamicTestingModule,
23-
platformBrowserDynamicTesting(), {
24-
teardown: { destroyAfterEach: false }
25-
}
20+
BrowserDynamicTestingModule,
21+
platformBrowserDynamicTesting(),
22+
{ teardown: { destroyAfterEach: true } },
2623
);
24+
2725
// Then we find all the tests.
2826
const context = require.context('./', true, /\.spec\.ts$/);
2927
// And load the modules.
30-
context.keys().map(context);
31-
// Finally, start Karma to run the tests.
32-
__karma__.start();
28+
context.keys().map(context);

src/tests/ag-grid-angular.spec.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { Component, ViewChild } from '@angular/core';
2+
import { ComponentFixture, TestBed } from '@angular/core/testing';
3+
4+
import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';
5+
import { GridApi, GridOptions, GridReadyEvent, Module } from '@ag-grid-community/core';
6+
import { AgGridAngular } from '@ag-grid-community/angular';
7+
8+
@Component({
9+
selector: 'app-grid-wrapper',
10+
standalone: true,
11+
imports: [AgGridAngular],
12+
template: `<ag-grid-angular
13+
[gridOptions]="gridOptions"
14+
[columnDefs]="columnDefs"
15+
[rowData]="rowData"
16+
[modules]="modules"
17+
(gridReady)="onGridReady($event)"
18+
[suppressBrowserResizeObserver]="suppressBrowserResizeObserver"
19+
(firstDataRendered)="onFirstDataRendered($event)"></ag-grid-angular>`,
20+
})
21+
export class GridWrapperComponent {
22+
modules: Module[] = [ClientSideRowModelModule];
23+
rowData: any[] | null = null;
24+
columnDefs = [{ field: 'make' }, { field: 'model' }, { field: 'price' }];
25+
26+
gridOptions: GridOptions = {};
27+
gridApi!: GridApi;
28+
29+
suppressBrowserResizeObserver = false;
30+
31+
@ViewChild(AgGridAngular) agGrid!: AgGridAngular;
32+
33+
onGridReady(params: GridReadyEvent) {
34+
this.gridApi = params.api;
35+
// this.gridApi.setGridOption('rowData', [{ make: 'Toyota', model: 'Celica', price: 35000 }]);
36+
this.rowData = [{ make: 'Toyota', model: 'Celica', price: 35000 }];
37+
}
38+
onFirstDataRendered(params: any) {}
39+
}
40+
41+
describe('Grid OnReady', () => {
42+
let component: GridWrapperComponent;
43+
let fixture: ComponentFixture<GridWrapperComponent>;
44+
45+
beforeEach(async () => {
46+
await TestBed.configureTestingModule({
47+
imports: [GridWrapperComponent, AgGridAngular],
48+
}).compileComponents();
49+
50+
fixture = TestBed.createComponent(GridWrapperComponent);
51+
component = fixture.componentInstance;
52+
});
53+
54+
it('gridReady is completed by the time a timeout finishes', (done) => {
55+
fixture.detectChanges();
56+
setTimeout(() => {
57+
expect(component.gridApi).toBeDefined();
58+
done();
59+
}, 0);
60+
});
61+
62+
const runGridReadyTest = async () => {
63+
spyOn(component, 'onGridReady').and.callThrough();
64+
spyOn(component, 'onFirstDataRendered').and.callThrough();
65+
66+
fixture.detectChanges();
67+
await fixture.whenStable();
68+
69+
expect(component.gridApi).toBeDefined();
70+
71+
fixture.detectChanges(); // force rowData binding to be applied
72+
await fixture.whenStable();
73+
74+
// If calling the gridApi.setRowData we don't need to call the fixture.detectChanges()
75+
76+
expect(component.onGridReady).toHaveBeenCalled();
77+
expect(component.onFirstDataRendered).toHaveBeenCalled();
78+
};
79+
80+
it('Fixture goes stable and calls gridReady', async () => {
81+
await runGridReadyTest();
82+
});
83+
84+
it('Fixture goes stable even with suppressBrowserResizeObserver= true', async () => {
85+
// Test with the fallback polling to mimic Jest not supporting ResizeObserver
86+
// We must have the polling run outside of the Angular zone
87+
component.suppressBrowserResizeObserver = true;
88+
89+
await runGridReadyTest();
90+
});
91+
92+
it('Grid Ready run Auto', async () => {
93+
spyOn(component, 'onGridReady').and.callThrough();
94+
spyOn(component, 'onFirstDataRendered').and.callThrough();
95+
fixture.autoDetectChanges();
96+
await fixture.whenStable();
97+
98+
expect(component.gridApi).toBeDefined();
99+
100+
expect(component.onGridReady).toHaveBeenCalled();
101+
expect(component.onFirstDataRendered).toHaveBeenCalled();
102+
});
103+
});

src/tests/clickingRows.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Component } from '@angular/core';
2+
3+
import { render, screen } from '@testing-library/angular';
4+
import userEvent from '@testing-library/user-event';
5+
6+
import { AgGridAngular } from '@ag-grid-community/angular';
7+
import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';
8+
import { ColDef, GridOptions, ModuleRegistry } from '@ag-grid-community/core';
9+
10+
ModuleRegistry.register(ClientSideRowModelModule);
11+
12+
@Component({
13+
selector: 'app-grid-wrapper',
14+
standalone: true,
15+
imports: [AgGridAngular],
16+
template: `<div data-testid="rowClicked">Row Clicked: {{ rowClicked?.make }}</div>
17+
<ag-grid-angular [gridOptions]="gridOptions" [columnDefs]="columnDefs" [rowData]="rowData"> </ag-grid-angular>`,
18+
})
19+
export class GridWrapperComponent {
20+
rowData: any[] = [
21+
{ make: 'Toyota', model: 'Celica', price: 35000 },
22+
{ make: 'Ford', model: 'Mondeo', price: 32000 },
23+
{ make: 'Porsche', model: 'Boxster', price: 72000 },
24+
];
25+
columnDefs: ColDef[] = [{ field: 'make' }, { field: 'model' }, { field: 'price' }];
26+
rowClicked: any;
27+
28+
gridOptions: GridOptions = {
29+
onRowClicked: (params) => {
30+
this.rowClicked = params.data;
31+
},
32+
};
33+
}
34+
35+
describe('Test Row Clicked', () => {
36+
it('Test cell clicked run row handler', async () => {
37+
render(GridWrapperComponent);
38+
39+
const row = await screen.findByText('Ford');
40+
41+
await userEvent.click(row);
42+
43+
const rowClicked = await screen.findByTestId('rowClicked');
44+
expect(rowClicked.textContent).toBe('Row Clicked: Ford');
45+
});
46+
});

0 commit comments

Comments
 (0)