Skip to content

Commit b0a104d

Browse files
Format files
1 parent 353af62 commit b0a104d

File tree

5 files changed

+136
-121
lines changed

5 files changed

+136
-121
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ repos:
4040
pass_filenames: false
4141
- id: format-ts-js
4242
name: Checks that all JS/TS files are formatted correctly
43-
entry: cd streamlit_bokeh/frontend && npm run format
43+
entry: bash -c 'cd streamlit_bokeh/frontend && npm run format'
4444
language: system
4545
always_run: true
4646
pass_filenames: false

streamlit_bokeh/frontend/package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

streamlit_bokeh/frontend/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
"streamlit-component-lib": "^2.0.0",
1111
"typescript": "^4.2.0"
1212
},
13-
"devDependencies": {
14-
"prettier": "^3.4.2"
15-
},
1613
"scripts": {
1714
"start": "react-scripts start",
1815
"format": "prettier --write src/**/*.ts",
@@ -37,6 +34,7 @@
3734
},
3835
"homepage": ".",
3936
"devDependencies": {
37+
"prettier": "^3.4.2",
4038
"util": "^0.12.5"
4139
}
4240
}

streamlit_bokeh/frontend/src/index.test.ts

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,120 +14,120 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Theme } from "streamlit-component-lib";
17+
import { Theme } from "streamlit-component-lib"
1818

1919
import {
2020
getChartDataGenerator,
2121
setChartThemeGenerator,
2222
getChartDimensions,
23-
} from "./index";
23+
} from "./index"
2424

2525
describe("getChartDataGenerator", () => {
2626
let getChartData: (figure: string) => {
27-
data: object | null;
28-
hasChanged: boolean;
29-
};
27+
data: object | null
28+
hasChanged: boolean
29+
}
3030

3131
beforeEach(() => {
32-
getChartData = getChartDataGenerator();
33-
});
32+
getChartData = getChartDataGenerator()
33+
})
3434

3535
test("should return parsed data and hasChanged true on first call", () => {
36-
const figure = JSON.stringify({ key: "value" });
37-
const result = getChartData(figure);
36+
const figure = JSON.stringify({ key: "value" })
37+
const result = getChartData(figure)
3838

39-
expect(result).toEqual({ data: { key: "value" }, hasChanged: true });
40-
});
39+
expect(result).toEqual({ data: { key: "value" }, hasChanged: true })
40+
})
4141

4242
test("should return hasChanged false for the same figure", () => {
43-
const figure = JSON.stringify({ key: "value" });
44-
getChartData(figure);
45-
const result = getChartData(figure);
43+
const figure = JSON.stringify({ key: "value" })
44+
getChartData(figure)
45+
const result = getChartData(figure)
4646

47-
expect(result).toEqual({ data: { key: "value" }, hasChanged: false });
48-
});
47+
expect(result).toEqual({ data: { key: "value" }, hasChanged: false })
48+
})
4949

5050
test("should return hasChanged true for a different figure", () => {
51-
getChartData(JSON.stringify({ key: "value" }));
52-
const newFigure = JSON.stringify({ key: "newValue" });
53-
const result = getChartData(newFigure);
51+
getChartData(JSON.stringify({ key: "value" }))
52+
const newFigure = JSON.stringify({ key: "newValue" })
53+
const result = getChartData(newFigure)
5454

55-
expect(result).toEqual({ data: { key: "newValue" }, hasChanged: true });
56-
});
57-
});
55+
expect(result).toEqual({ data: { key: "newValue" }, hasChanged: true })
56+
})
57+
})
5858

5959
// Unit tests for setChartThemeGenerator
6060
describe("setChartThemeGenerator", () => {
61-
let setChartTheme: (newTheme: string, newAppTheme: Theme) => boolean;
61+
let setChartTheme: (newTheme: string, newAppTheme: Theme) => boolean
6262

6363
beforeEach(() => {
64-
setChartTheme = setChartThemeGenerator();
65-
});
64+
setChartTheme = setChartThemeGenerator()
65+
})
6666

6767
test("should apply the theme when theme changes", () => {
68-
const newTheme = "dark";
68+
const newTheme = "dark"
6969
const newAppTheme = {
7070
textColor: "white",
7171
backgroundColor: "black",
7272
secondaryBackgroundColor: "gray",
73-
} as Theme;
74-
const result = setChartTheme(newTheme, newAppTheme);
73+
} as Theme
74+
const result = setChartTheme(newTheme, newAppTheme)
7575
const { use_theme: useTheme } =
76-
global.window.Bokeh.require("core/properties");
76+
global.window.Bokeh.require("core/properties")
7777

78-
expect(result).toBe(true);
79-
expect(useTheme).toHaveBeenCalled();
80-
});
78+
expect(result).toBe(true)
79+
expect(useTheme).toHaveBeenCalled()
80+
})
8181

8282
test("should not reapply the theme if it's the same", () => {
83-
const newTheme = "dark";
83+
const newTheme = "dark"
8484
const newAppTheme = {
8585
textColor: "white",
8686
backgroundColor: "black",
8787
secondaryBackgroundColor: "gray",
88-
} as Theme;
89-
setChartTheme(newTheme, newAppTheme);
90-
const result = setChartTheme(newTheme, newAppTheme);
88+
} as Theme
89+
setChartTheme(newTheme, newAppTheme)
90+
const result = setChartTheme(newTheme, newAppTheme)
9191

92-
expect(result).toBe(false);
93-
});
92+
expect(result).toBe(false)
93+
})
9494

9595
test("should apply Streamlit theme when appropriate", () => {
96-
const newTheme = "streamlit";
96+
const newTheme = "streamlit"
9797
const newAppTheme = {
9898
textColor: "white",
9999
backgroundColor: "black",
100100
secondaryBackgroundColor: "gray",
101-
} as Theme;
102-
const result = setChartTheme(newTheme, newAppTheme);
101+
} as Theme
102+
const result = setChartTheme(newTheme, newAppTheme)
103103

104-
expect(result).toBe(true);
105-
});
106-
});
104+
expect(result).toBe(true)
105+
})
106+
})
107107

108108
describe("getChartDimensions", () => {
109109
test("should return default dimensions when no width/height attributes are provided", () => {
110-
const plot = { attributes: {} };
111-
const result = getChartDimensions(plot, false);
112-
expect(result).toEqual({ width: 600, height: 600 });
113-
});
110+
const plot = { attributes: {} }
111+
const result = getChartDimensions(plot, false)
112+
expect(result).toEqual({ width: 600, height: 600 })
113+
})
114114

115115
test("should return provided dimensions when width/height attributes are set", () => {
116-
const plot = { attributes: { width: 800, height: 400 } };
117-
const result = getChartDimensions(plot, false);
118-
expect(result).toEqual({ width: 800, height: 400 });
119-
});
116+
const plot = { attributes: { width: 800, height: 400 } }
117+
const result = getChartDimensions(plot, false)
118+
expect(result).toEqual({ width: 800, height: 400 })
119+
})
120120

121121
test("should calculate new dimensions based on container width", () => {
122122
Object.defineProperty(document.documentElement, "clientWidth", {
123123
configurable: true,
124124
writable: true,
125125
value: 1200, // Set the desired value
126-
});
127-
128-
const plot = { attributes: { width: 800, height: 400 } };
129-
const result = getChartDimensions(plot, true);
130-
expect(result.width).toBe(1200);
131-
expect(result.height).toBeCloseTo(600);
132-
});
133-
});
126+
})
127+
128+
const plot = { attributes: { width: 800, height: 400 } }
129+
const result = getChartDimensions(plot, true)
130+
expect(result.width).toBe(1200)
131+
expect(result.height).toBeCloseTo(600)
132+
})
133+
})

0 commit comments

Comments
 (0)