Skip to content

Commit ec9af37

Browse files
authored
chore: Storybook migration (evcc-io#19780)
1 parent 97b4b9a commit ec9af37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4952
-4501
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ asset-stats.html
4343
/playwright/.cache/
4444
.gitpod.yml
4545
/evcc.db
46+
47+
*storybook.log

.storybook/main.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @type { import('@storybook/vue3-vite').StorybookConfig } */
2+
const config = {
3+
stories: ["../assets/js/**/*.stories.@(js|ts)"],
4+
addons: [
5+
"@storybook/addon-essentials",
6+
"@chromatic-com/storybook",
7+
"@storybook/addon-interactions",
8+
],
9+
framework: {
10+
name: "@storybook/vue3-vite",
11+
options: {},
12+
},
13+
};
14+
export default config;

.storybook/preview.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { setup } from "@storybook/vue3";
2+
import "bootstrap/dist/css/bootstrap.min.css";
3+
import smoothscroll from "smoothscroll-polyfill";
4+
import setupI18n from "../assets/js/i18n";
5+
import "../assets/css/app.css";
6+
import { watchThemeChanges } from "../assets/js/theme";
7+
8+
smoothscroll.polyfill();
9+
watchThemeChanges();
10+
11+
// Setup global parameters
12+
/** @type { import('@storybook/vue3').Preview } */
13+
const preview = {
14+
parameters: {
15+
controls: {
16+
matchers: {
17+
color: /(background|color)$/i,
18+
date: /Date$/,
19+
},
20+
},
21+
backgrounds: {
22+
default: "default",
23+
values: [
24+
{
25+
name: "default",
26+
value: "var(--evcc-background)",
27+
},
28+
{
29+
name: "box",
30+
value: "var(--evcc-box)",
31+
},
32+
],
33+
},
34+
},
35+
};
36+
37+
setup((app) => {
38+
app.config.globalProperties.$hiddenFeatures = () => true;
39+
app.use(setupI18n());
40+
});
41+
42+
export default preview;

CONTRIBUTING.md

+8
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ npm install
8989
npm run dev
9090
```
9191

92+
#### Storybook
93+
94+
We're using storybook to develop and visualize UI components in different states. Running the command below will open your browser at http://127.0.0.1:6006/.
95+
96+
```sh
97+
npm run storybook
98+
```
99+
92100
#### Integration testing
93101

94102
We use Playwright for end-to-end integration tests. They start a local evcc instance with different configuration yamls and prefilled databases. To run them, you have to do a local build first.

assets/histoire.setup.js

-14
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import ChargingPlan from "./ChargingPlan.vue";
2+
3+
const hoursFromNow = (hours) => {
4+
const now = new Date();
5+
now.setHours(now.getHours() + hours);
6+
return now.toISOString();
7+
};
8+
9+
export default {
10+
title: "ChargingPlans/ChargingPlan",
11+
component: ChargingPlan,
12+
parameters: {
13+
layout: "centered",
14+
},
15+
argTypes: {
16+
id: { control: "text" },
17+
effectivePlanTime: { control: "text" },
18+
effectivePlanSoc: { control: "number" },
19+
planEnergy: { control: "number" },
20+
socBasedCharging: { control: "boolean" },
21+
socBasedPlanning: { control: "boolean" },
22+
vehicleSoc: { control: "number" },
23+
},
24+
};
25+
26+
const Template = (args) => ({
27+
components: { ChargingPlan },
28+
setup() {
29+
return { args };
30+
},
31+
template: '<ChargingPlan v-bind="args" />',
32+
});
33+
34+
export const None = Template.bind({});
35+
None.args = {
36+
id: "1",
37+
};
38+
39+
export const SocBasedCharging = Template.bind({});
40+
SocBasedCharging.args = {
41+
id: "1",
42+
effectivePlanTime: hoursFromNow(4),
43+
effectivePlanSoc: 77,
44+
socBasedCharging: true,
45+
socBasedPlanning: true,
46+
};
47+
48+
export const EnergyBasedCharging = Template.bind({});
49+
EnergyBasedCharging.args = {
50+
id: "1",
51+
effectivePlanTime: hoursFromNow(12),
52+
planEnergy: 77,
53+
socBasedCharging: false,
54+
socBasedPlanning: false,
55+
};

assets/js/components/ChargingPlans/ChargingPlan.story.vue

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import Preview from "./Preview.vue";
2+
3+
const now = new Date();
4+
5+
function createDate(hoursFromNow) {
6+
const result = new Date(now.getTime());
7+
result.setHours(result.getHours() + hoursFromNow);
8+
return result;
9+
}
10+
11+
function createRate(price, hoursFromNow, durationHours = 1) {
12+
const start = new Date(now.getTime());
13+
start.setHours(start.getHours() + hoursFromNow);
14+
start.setMinutes(0);
15+
start.setSeconds(0);
16+
start.setMilliseconds(0);
17+
const end = new Date(start.getTime());
18+
end.setHours(start.getHours() + durationHours);
19+
end.setMinutes(0);
20+
end.setSeconds(0);
21+
end.setMilliseconds(0);
22+
return { start: start.toISOString(), end: end.toISOString(), price };
23+
}
24+
25+
// Scenario data
26+
const co2Data = {
27+
rates: [
28+
545, 518, 545, 518, 0, 545, 527, 527, 536, 518, 400, 336, 336, 339, 344, 336, 336, 336, 372,
29+
400, 555, 555, 545, 555, 564, 545, 555, 545, 536, 545, 527, 536, 518, 545, 509, 336, 336, 336,
30+
].map((price, i) => createRate(price, i)),
31+
duration: 8695,
32+
plan: [createRate(213, 4), createRate(336, 11), createRate(336, 12)],
33+
smartCostType: "co2",
34+
targetTime: createDate(14),
35+
};
36+
37+
const fixedData = {
38+
rates: [createRate(0.442, 0, 50)],
39+
duration: 8695,
40+
plan: [createRate(0.442, 12, 3)],
41+
smartCostType: "price",
42+
currency: "EUR",
43+
targetTime: createDate(14),
44+
};
45+
46+
const zonedData = {
47+
rates: [
48+
createRate(3.72, 0, 4),
49+
createRate(2.39, 4, 12),
50+
createRate(3.72, 16, 12),
51+
createRate(2.39, 28, 12),
52+
createRate(3.72, 40, 12),
53+
],
54+
duration: 8695,
55+
plan: [createRate(2.39, 13, 3)],
56+
smartCostType: "price",
57+
currency: "DKK",
58+
targetTime: createDate(17),
59+
};
60+
61+
const unknownData = {
62+
rates: co2Data.rates.slice(0, 16),
63+
duration: 8695,
64+
plan: [createRate(213, 4), createRate(336, 11), createRate(336, 12)],
65+
smartCostType: "co2",
66+
targetTime: createDate(14),
67+
};
68+
69+
const dynamicData = {
70+
rates: [0.12, 0.15, 0, -0.05, -0.11, -0.24, -0.08, 0.12, 0.25, 0.29, 0.22, 0.31, 0.31, 0.33].map(
71+
(price, i) => createRate(price, i)
72+
),
73+
duration: 8695,
74+
plan: [createRate(0.23, 2, 5)],
75+
smartCostType: "price",
76+
currency: "EUR",
77+
targetTime: createDate(13),
78+
};
79+
80+
export default {
81+
title: "ChargingPlans/Preview",
82+
component: Preview,
83+
argTypes: {
84+
rates: { control: "object" },
85+
duration: { control: "number" },
86+
plan: { control: "object" },
87+
smartCostType: { control: "select", options: ["co2", "price"] },
88+
currency: { control: "text" },
89+
targetTime: { control: "text" },
90+
},
91+
};
92+
93+
const Template = (args) => ({
94+
components: { Preview },
95+
setup() {
96+
return { args };
97+
},
98+
template: '<Preview v-bind="args" />',
99+
});
100+
101+
export const Co2 = Template.bind({});
102+
Co2.args = co2Data;
103+
104+
export const Fixed = Template.bind({});
105+
Fixed.args = fixedData;
106+
107+
export const Zoned = Template.bind({});
108+
Zoned.args = zonedData;
109+
110+
export const Unknown = Template.bind({});
111+
Unknown.args = unknownData;
112+
113+
export const Dynamic = Template.bind({});
114+
Dynamic.args = dynamicData;

assets/js/components/ChargingPlans/Preview.story.vue

-100
This file was deleted.

0 commit comments

Comments
 (0)