-
Notifications
You must be signed in to change notification settings - Fork 121
Add Dumbbell & Tilemap examples, optional module-load timeout, and expanded tests/docs #418
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
Open
medbenmakhlouf
wants to merge
17
commits into
highcharts:master
Choose a base branch
from
medbenmakhlouf:split-modules-loading
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+555
−14
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d8877e7
add dumbbell and tilemap chart components with styles and templates
medbenmakhlouf a3fb2ac
add tilemap and dumbbell chart components to app
medbenmakhlouf 750e57d
update worldMap resource URL in MapChartComponent
medbenmakhlouf 22dd9c2
refactor: improve loading of Highcharts modules with delays
medbenmakhlouf 3b23edf
refactor: enhance linting command to include Prettier formatting
medbenmakhlouf bc4a91c
refactor: clean up HTML and TypeScript files for dumbbell and tilemap…
medbenmakhlouf 4b8fb8c
test: increase timeout duration in Highcharts loading tests
medbenmakhlouf 42b4d38
refactor: separate Prettier command from linting script in package.json
medbenmakhlouf 034b9e3
feat: add timeout configuration for Highcharts loading
medbenmakhlouf 57bf20d
refactor: simplify Highcharts loading logic and remove unnecessary de…
medbenmakhlouf 599056c
feat: add timeout handling for Highcharts chart creation and updates
medbenmakhlouf 60638ac
docs: update README with Highcharts module loading order and promise …
medbenmakhlouf 24c9e26
test: add unit tests for HighchartsChartService module loading behavior
medbenmakhlouf 58509a3
test: reduce timeout duration in HighchartsChartService tests
medbenmakhlouf 0382051
feat: add configurable timeout for Highcharts module loading
medbenmakhlouf 6550751
docs: add optional timeout configuration for module loading in README
medbenmakhlouf 35fb36b
fix: add missing comma for timeout configuration in module loading
medbenmakhlouf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
highcharts-angular/src/lib/highcharts-chart.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
import { Component, ChangeDetectionStrategy } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import type Highcharts from 'highcharts/esm/highcharts'; | ||
import { HighchartsChartComponent } from './highcharts-chart.component'; | ||
import { HighchartsChartService } from './highcharts-chart.service'; | ||
import { provideHighcharts, providePartialHighcharts } from './highcharts-chart.provider'; | ||
import { ModuleFactoryFunction } from './types'; | ||
|
||
/** | ||
* Minimal host component to attach per-test module providers via TestBed.overrideComponent. | ||
* We keep it simple to focus on DI and async loading behavior. | ||
*/ | ||
@Component({ | ||
selector: 'highcharts-test', | ||
template: `<highcharts-chart [options]="{}" />`, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [HighchartsChartComponent], | ||
standalone: true, | ||
}) | ||
class TestComponent {} | ||
|
||
describe('TestComponent / HighchartsChartService (load module)', () => { | ||
beforeEach(async () => { | ||
// 1) Register the standalone host + core Highcharts provider. | ||
// - provideHighcharts(): should wire up HIGHCHARTS_LOADER, etc., so the service can load core Highcharts. | ||
await TestBed.configureTestingModule({ | ||
imports: [TestComponent], | ||
providers: [provideHighcharts()], | ||
}).compileComponents(); | ||
}); | ||
|
||
it('resolves HighchartsChartService from the component injector', () => { | ||
const fixture = TestBed.createComponent(TestComponent); | ||
fixture.detectChanges(); | ||
|
||
// 2) Resolve the service from the component’s injector to honor component-level provider overrides. | ||
const service = fixture.debugElement.injector.get(HighchartsChartService); | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
// --------------------------------------------------------------------------- | ||
// Parameterized checks for different Highcharts modules. | ||
// | ||
// For each case, we: | ||
// - override the component’s providers to supply the module list | ||
// - create the fixture (activates providers) | ||
// - wait for the microtasks/imports to settle (fixture.whenStable) | ||
// - assert that the Highcharts instance contains the expected augmented APIs | ||
// --------------------------------------------------------------------------- | ||
|
||
type Case = { | ||
title: string; | ||
modules: ModuleFactoryFunction; | ||
assert(hc: any): void; | ||
timeout?: number; | ||
}; | ||
|
||
const CASES: Case[] = [ | ||
{ | ||
title: 'map → exposes Highcharts.MapChart', | ||
modules: () => [import('highcharts/esm/modules/map')], | ||
assert: (hc: typeof Highcharts) => { | ||
expect(hc.MapChart).toBeDefined(); | ||
expect(typeof hc.MapChart).toBe('function'); | ||
}, | ||
}, | ||
{ | ||
title: 'tilemap → exposes Highcharts.seriesTypes.tilemap', | ||
modules: () => [import('highcharts/esm/modules/tilemap')], | ||
assert: hc => { | ||
expect(hc.seriesTypes?.tilemap).toBeDefined(); | ||
}, | ||
}, | ||
{ | ||
title: 'highcharts-more → exposes arearange series + dumbbell → exposes Highcharts.seriesTypes.dumbbell', | ||
modules: () => [import('highcharts/esm/highcharts-more').then(() => import('highcharts/esm/modules/dumbbell'))], | ||
assert: hc => { | ||
expect(hc.seriesTypes?.arearange).toBeDefined(); | ||
expect(hc.seriesTypes?.dumbbell).toBeDefined(); | ||
}, | ||
timeout: 2000, | ||
}, | ||
{ | ||
title: 'pattern-fill → adds SVGRenderer.addPattern', | ||
modules: () => [import('highcharts/esm/modules/pattern-fill')], | ||
assert: hc => { | ||
// pattern-fill augments the renderer with addPattern utility | ||
expect(typeof hc.SVGRenderer?.prototype?.addPattern).toBe('function'); | ||
}, | ||
}, | ||
{ | ||
title: 'gantt → exposes Highcharts.ganttChart or Highcharts.GanttChart', | ||
modules: () => [import('highcharts/esm/modules/gantt')], | ||
assert: hc => { | ||
// Some versions expose both; at least one must exist. | ||
const ok = typeof hc.ganttChart === 'function' || typeof hc.GanttChart === 'function'; | ||
expect(ok).toBeTrue(); | ||
}, | ||
}, | ||
]; | ||
|
||
for (const c of CASES) { | ||
it(`attaches expected API when module is provided: ${c.title}`, async () => { | ||
// 3) Provide the module(s) at the component level. This mirrors your real component’s | ||
// `providers: [providePartialHighcharts({ modules: () => [...] })]`. | ||
TestBed.overrideComponent(TestComponent, { | ||
set: { providers: [providePartialHighcharts({ modules: c.modules, timeout: c.timeout })] }, | ||
}); | ||
|
||
const fixture = TestBed.createComponent(TestComponent); | ||
fixture.detectChanges(); | ||
|
||
// 4) Get the service from this component’s injector scope | ||
const service = fixture.debugElement.injector.get(HighchartsChartService); | ||
expect(service).toBeTruthy(); | ||
|
||
// 5) Wait for all async work to stabilize: | ||
// - dynamic imports for modules | ||
// - the service’s microtasks and internal timers (your working test already relies on whenStable) | ||
await fixture.whenStable(); | ||
|
||
// 6) Read the Highcharts instance from the signal | ||
const hc = service.highcharts(); | ||
expect(hc).toBeTruthy(); | ||
|
||
// 7) Case-specific assertions for the module’s side effects | ||
c.assert(hc); | ||
}); | ||
} | ||
|
||
it('can load multiple modules together (map + tilemap + more + dumbbell + pattern-fill + gantt)', async () => { | ||
TestBed.overrideComponent(TestComponent, { | ||
set: { | ||
providers: [ | ||
providePartialHighcharts({ | ||
modules: () => [ | ||
import('highcharts/esm/modules/map'), | ||
import('highcharts/esm/modules/tilemap'), | ||
import('highcharts/esm/modules/gantt'), | ||
import('highcharts/esm/highcharts-more').then(() => import('highcharts/esm/modules/dumbbell')), | ||
import('highcharts/esm/modules/pattern-fill'), | ||
], | ||
}), | ||
], | ||
}, | ||
}); | ||
|
||
const fixture = TestBed.createComponent(TestComponent); | ||
fixture.detectChanges(); | ||
|
||
const service = fixture.debugElement.injector.get(HighchartsChartService); | ||
expect(service).toBeTruthy(); | ||
|
||
await fixture.whenStable(); | ||
|
||
const hc: any = service.highcharts(); | ||
expect(hc).toBeTruthy(); | ||
|
||
// Consolidated assertions (quick smoke for “all together”) | ||
expect(typeof hc.MapChart).toBe('function'); // map | ||
expect(hc.seriesTypes?.tilemap).toBeDefined(); // tilemap | ||
expect(hc.seriesTypes?.arearange).toBeDefined(); // highcharts-more | ||
expect(hc.seriesTypes?.dumbbell).toBeDefined(); // dumbbell | ||
expect(typeof hc.SVGRenderer?.prototype?.addPattern).toBe('function'); // pattern-fill | ||
expect(typeof hc.ganttChart === 'function' || typeof hc.GanttChart === 'function').toBeTrue(); // gantt | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
h2 { | ||
font-family: Arial, Helvetica, sans-serif; | ||
font-size: 1.25rem; | ||
margin: 0 0 1.5rem 0; | ||
} | ||
|
||
.main { | ||
width: 100%; | ||
height: 650px; | ||
display: block; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<article> | ||
<h2>Demo #8: Highcharts Dumbbell</h2> | ||
<highcharts-chart class="main" [options]="options" /> | ||
</article> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this change (some methods/properties being async) should be listed as a breaking change and described in the readme.