Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

chore: Visual regression tests for advanced section (#3214)

Oleg Isonenf4f4e7c5abeb
diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.stories.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.stories.tsx
new file mode 100644
index 0000000000..78d12d97c5
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.stories.tsx
@@ -0,0 +1,47 @@
+import { Section } from "./advanced";
+
+const currentStyle = {
+ accentColor: {
+ value: {
+ type: "keyword",
+ value: "red",
+ },
+ local: {
+ type: "keyword",
+ value: "red",
+ },
+ },
+ alignContent: {
+ value: {
+ type: "keyword",
+ value: "normal",
+ },
+ local: {
+ type: "keyword",
+ value: "normal",
+ },
+ },
+ opacity: {
+ value: {
+ type: "unit",
+ unit: "number",
+ value: 11.2,
+ },
+ local: {
+ type: "unit",
+ unit: "number",
+ value: 11.2,
+ },
+ },
+} as const;
+
+export const Advanced = () => {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const props = {} as any;
+ return <Section currentStyle={currentStyle} {...props} />;
+};
+
+export default {
+ title: "Style Panel/Advanced",
+ component: Advanced,
+};
diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx
index fd5185f935..bc612cab6b 100644
--- a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx
@@ -18,7 +18,7 @@ import {
} from "../../shared/style-info";
import { Add } from "./add";
import { CollapsibleSection } from "../../shared/collapsible-section";
-import { sectionsProperties } from "../sections";
+import { sections } from "../sections";
import { toKebabCase } from "../../shared/keyword-utils";
import type { DeleteProperty } from "../../shared/use-style-data";
@@ -40,13 +40,25 @@ const usePropertyNames = (currentStyle: StyleInfo) => {
const styles = useInstanceStyles(selectedInstanceSelector?.[0]);
// Ordererd recent properties for sorting.
const recent = useRef<Set<StyleProperty>>(new Set());
+
+ const baseProperties = useMemo(() => {
+ // All properties used by the panels except the advanced panel
+ const base = new Set<StyleProperty>([]);
+ for (const { properties } of sections.values()) {
+ for (const property of properties) {
+ base.add(property);
+ }
+ }
+ return base;
+ }, []);
+
const propertyNames = useMemo(() => {
const names = new Set(initialPropertyNames);
let property: StyleProperty;
for (property in currentStyle) {
if (
hasInstanceValue(currentStyle, property) &&
- sectionsProperties.has(property) === false
+ baseProperties.has(property) === false
) {
names.add(property);
}
@@ -63,7 +75,7 @@ const usePropertyNames = (currentStyle: StyleInfo) => {
.filter((name) => recent.current.has(name) === false)
.reverse(),
];
- }, [styles, currentStyle]);
+ }, [styles, currentStyle, baseProperties]);
return { propertyNames, recentProperties: recent.current };
};
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.stories.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.stories.tsx
index 6a17e919e2..4189105dae 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.stories.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.stories.tsx
@@ -66,6 +66,6 @@ export const BackgroundContentStory = () => {
};
export default {
- title: "Style/Background",
+ title: "Style Panel/Background",
component: BackgroundContent,
};
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/backgrounds.stories.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/backgrounds.stories.tsx
index c5a3b58d01..1d72108842 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/backgrounds.stories.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/backgrounds.stories.tsx
@@ -1,6 +1,5 @@
import type { LayersValue } from "@webstudio-is/css-engine";
import { styled, theme } from "@webstudio-is/design-system";
-import { setEnv } from "@webstudio-is/feature-flags";
import { useRef, useState } from "react";
import type { StyleInfo } from "../../shared/style-info";
import type {
@@ -10,8 +9,6 @@ import type {
} from "../../shared/use-style-data";
import { Section } from "./backgrounds";
-setEnv("*");
-
const backgroundImageStyle: LayersValue = {
type: "layers",
value: [
@@ -139,6 +136,6 @@ export const Backgrounds = () => {
};
export default {
- title: "Style/Background",
+ title: "Style Panel/Background",
component: Section,
};
diff --git a/apps/builder/app/builder/features/style-panel/sections/borders/borders.stories.tsx b/apps/builder/app/builder/features/style-panel/sections/borders/borders.stories.tsx
index db2d33d2df..a068318daa 100644
--- a/apps/builder/app/builder/features/style-panel/sections/borders/borders.stories.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/borders/borders.stories.tsx
@@ -1,5 +1,4 @@
import { styled, theme } from "@webstudio-is/design-system";
-import { setEnv } from "@webstudio-is/feature-flags";
import { useRef, useState } from "react";
import type { StyleInfo } from "../../shared/style-info";
import type {
@@ -8,7 +7,6 @@ import type {
SetProperty,
} from "../../shared/use-style-data";
import { Section } from "./borders";
-setEnv("*");
const styleInfoInitial: StyleInfo = {
borderTopColor: {
@@ -91,6 +89,6 @@ export const Borders = () => {
};
export default {
- title: "Style/Borders",
+ title: "Style Panel/Borders",
component: Section,
};
diff --git a/apps/builder/app/builder/features/style-panel/sections/position/position-control.stories.tsx b/apps/builder/app/builder/features/style-panel/sections/position/position-control.stories.tsx
index d490f8c19a..73cedc502b 100644
--- a/apps/builder/app/builder/features/style-panel/sections/position/position-control.stories.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/position/position-control.stories.tsx
@@ -117,6 +117,6 @@ export const PositionControlComponent = (
};
export default {
- title: "Position/Control",
+ title: "Style Panel/Position",
component: PositionControlComponent,
} as Meta<typeof PositionControlComponent>;
diff --git a/apps/builder/app/builder/features/style-panel/sections/position/position-layout.stories.tsx b/apps/builder/app/builder/features/style-panel/sections/position/position-layout.stories.tsx
index d2ca9a51cb..bbec24987e 100644
--- a/apps/builder/app/builder/features/style-panel/sections/position/position-layout.stories.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/position/position-layout.stories.tsx
@@ -22,7 +22,7 @@ export const PositionLayoutComponent = (
);
export default {
- title: "Position/Layout",
+ title: "Style Panel/Position",
component: PositionLayoutComponent,
argTypes: {
diff --git a/apps/builder/app/builder/features/style-panel/sections/sections.ts b/apps/builder/app/builder/features/style-panel/sections/sections.ts
index 80c85354d6..75ea996206 100644
--- a/apps/builder/app/builder/features/style-panel/sections/sections.ts
+++ b/apps/builder/app/builder/features/style-panel/sections/sections.ts
@@ -38,11 +38,3 @@ export const sections = new Map<
["outline", outline],
["advanced", advanced],
]);
-
-export const sectionsProperties = new Set<StyleProperty>([]);
-
-for (const { properties } of sections.values()) {
- for (const property of properties) {
- sectionsProperties.add(property);
- }
-}