Skip to content

Commit 0b443b9

Browse files
committed
Fixes #237. Adding strict- pattern to the PlotlyViaCDNModule.setPlotlyVersion method
1 parent 435fd02 commit 0b443b9

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

33

4+
## [5.1.1] - 2023-06-15
5+
### Changed
6+
- Adding support to strict version of bundle plotly (see https://github.com/plotly/angular-plotly.js/issues/237)
7+
48
## [5.1.0] - 2023-04-10
59
### Changed
610
- Updated to Angular 15

projects/plotly/src/lib/plotly-via-cdn.module.spec.ts

+23-4
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,31 @@ describe('PlotlyViaCDNModule', () => {
4545
});
4646

4747
it('should NOT set Plotly version', () => {
48-
const version = "invalid";
48+
const errorMsg= "Invalid plotly version. Please set 'latest' or version number (i.e.: 1.4.3) or strict version number (i.e.: strict-1.4.3)";
4949
spyOn(PlotlyViaCDNModule, "loadViaCDN").and.callThrough();
5050

51-
expect(() => {
52-
PlotlyViaCDNModule.setPlotlyVersion(version);
53-
}).toThrowError("Invalid plotly version. Please set 'latest' or version number (i.e.: 1.4.3)");
51+
let version = "invalid";
52+
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);
53+
54+
version = "strict-1";
55+
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);
56+
57+
version = "1";
58+
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);
59+
60+
version = "strict-1.1.a";
61+
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);
62+
63+
version = "strit-1.1.1";
64+
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);
65+
});
66+
67+
it('should allow Plotly version with strict- at the beginning', () => {
68+
const version = "strict-2.24.1";
69+
spyOn(PlotlyViaCDNModule, "loadViaCDN");
70+
71+
PlotlyViaCDNModule.setPlotlyVersion(version);
72+
expect((PlotlyViaCDNModule as any).plotlyVersion).toBe(version);
5473
});
5574
});
5675
});

projects/plotly/src/lib/plotly-via-cdn.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export class PlotlyViaCDNModule {
2424
}
2525

2626
public static setPlotlyVersion(version: string): void {
27-
const isOk = version === 'latest' || /^\d\.\d{1,2}\.\d{1,2}$/.test(version);
27+
const isOk = version === 'latest' || /^(strict-)?\d\.\d{1,2}\.\d{1,2}$/.test(version);
2828
if (!isOk) {
29-
throw new Error(`Invalid plotly version. Please set 'latest' or version number (i.e.: 1.4.3)`);
29+
throw new Error(`Invalid plotly version. Please set 'latest' or version number (i.e.: 1.4.3) or strict version number (i.e.: strict-1.4.3)`);
3030
}
3131

3232
PlotlyViaCDNModule.loadViaCDN();

0 commit comments

Comments
 (0)