Skip to content

Commit

Permalink
Fixes #237. Adding strict- pattern to the PlotlyViaCDNModule.setPlotl…
Browse files Browse the repository at this point in the history
…yVersion method
  • Loading branch information
andrefarzat committed Jun 15, 2023
1 parent 435fd02 commit 0b443b9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog


## [5.1.1] - 2023-06-15
### Changed
- Adding support to strict version of bundle plotly (see https://github.com/plotly/angular-plotly.js/issues/237)

## [5.1.0] - 2023-04-10
### Changed
- Updated to Angular 15
Expand Down
27 changes: 23 additions & 4 deletions projects/plotly/src/lib/plotly-via-cdn.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,31 @@ describe('PlotlyViaCDNModule', () => {
});

it('should NOT set Plotly version', () => {
const version = "invalid";
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)";
spyOn(PlotlyViaCDNModule, "loadViaCDN").and.callThrough();

expect(() => {
PlotlyViaCDNModule.setPlotlyVersion(version);
}).toThrowError("Invalid plotly version. Please set 'latest' or version number (i.e.: 1.4.3)");
let version = "invalid";
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);

version = "strict-1";
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);

version = "1";
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);

version = "strict-1.1.a";
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);

version = "strit-1.1.1";
expect(() => { PlotlyViaCDNModule.setPlotlyVersion(version); }).toThrowError(errorMsg);
});

it('should allow Plotly version with strict- at the beginning', () => {
const version = "strict-2.24.1";
spyOn(PlotlyViaCDNModule, "loadViaCDN");

PlotlyViaCDNModule.setPlotlyVersion(version);
expect((PlotlyViaCDNModule as any).plotlyVersion).toBe(version);
});
});
});
4 changes: 2 additions & 2 deletions projects/plotly/src/lib/plotly-via-cdn.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class PlotlyViaCDNModule {
}

public static setPlotlyVersion(version: string): void {
const isOk = version === 'latest' || /^\d\.\d{1,2}\.\d{1,2}$/.test(version);
const isOk = version === 'latest' || /^(strict-)?\d\.\d{1,2}\.\d{1,2}$/.test(version);
if (!isOk) {
throw new Error(`Invalid plotly version. Please set 'latest' or version number (i.e.: 1.4.3)`);
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)`);
}

PlotlyViaCDNModule.loadViaCDN();
Expand Down

0 comments on commit 0b443b9

Please sign in to comment.