diff --git a/packages/theme/src/__tests__/createThemeValuesProxy.test.ts b/packages/theme/src/__tests__/createThemeValuesProxy.test.ts deleted file mode 100644 index 6af6d0243..000000000 --- a/packages/theme/src/__tests__/createThemeValuesProxy.test.ts +++ /dev/null @@ -1,398 +0,0 @@ -import createThemeValuesProxy from "../createThemeValuesProxy"; - -const breakpoints = { - small: 100, - medium: 400, - large: 700, -}; - -const value: any = { - nested: { - nestedOne: "nestedOne", - nestedTwo: "nestedTwo", - nestedNumber: 5, - nestedMore: { - nestedMoreOne: "nestedMoreOne", - }, - }, - primary: "primary", - numberValue: 5, - secondary: "secondary", - tertiary: "tertiary", - accent: "accent", - platform: { - default: "default", - ios: "ios", - android: "android", - }, - platformNested: { - ios: { - nested: "nestedIos", - }, - android: { - nested: "nestedAndroid", - }, - }, - breakpoint: { - default: "default", - small: "small", - medium: "medium", - large: "large", - }, - breakpointNested: { - small: { - nested: "nestedSmall", - }, - medium: { - nested: "nestedMedium", - }, - }, - lightDark: { - default: "defaultLightDark", - light: "lightValue", - dark: "darkValue", - }, - lightDarkNested: { - light: { - nested: "nestedLight", - }, - dark: { - nested: "nestedDark", - }, - }, - typography: { - body1: { - fontFamily: "body1", - fontSize: 18, - }, - bodyNested: { - mine: { - fontFamily: "nestedMine", - fontSize: 14, - }, - }, - bodyPlatform: { - android: { - fontFamily: "android", - fontSize: 13, - }, - default: { - fontFamily: "default", - fontSize: 22, - }, - }, - }, -}; - -const proxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "android", - currentLightDarkSelection: "light", -})!; - -describe("createThemeValuesProxy tests", () => { - describe("Value Returned Directly", () => { - test("returns value directly when string", () => { - expect(proxied.primary).toEqual(value.primary); - }); - - test("returns value directly when number", () => { - expect(proxied.numberValue).toEqual(value.numberValue); - }); - - test("returns value directly when nested and string", () => { - expect(proxied.nested.nestedOne).toEqual(value.nested.nestedOne); - }); - - test("returns value directly when nested and number", () => { - expect(proxied.nested.nestedNumber).toEqual(value.nested.nestedNumber); - }); - - test("returns value directly when deeply nested", () => { - expect(proxied.nested.nestedMore.nestedMoreOne).toEqual( - value.nested.nestedMore.nestedMoreOne - ); - }); - }); - - describe("Platform Value", () => { - test("returns android value when platform is android", () => { - const androidProxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(androidProxied.platform).toEqual(value.platform.android); - }); - - test("returns ios value when platform is ios", () => { - const iosProxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "ios", - currentLightDarkSelection: "light", - })!; - expect(iosProxied.platform).toEqual(value.platform.ios); - }); - - test("returns default platform value when platform is not in keys", () => { - const windowsProxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "windows", - currentLightDarkSelection: "light", - })!; - expect(windowsProxied.platform).toEqual(value.platform.default); - }); - - test("returns nested android value when platform is android", () => { - const androidProxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(androidProxied.platformNested.nested).toEqual( - value.platformNested.android.nested - ); - }); - - test("returns nested ios value when platform is ios", () => { - const iosProxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "ios", - currentLightDarkSelection: "light", - })!; - expect(iosProxied.platformNested.nested).toEqual( - value.platformNested.ios.nested - ); - }); - }); - - describe("Breakpoint Value", () => { - test("returns small breakpoint value when device width matches exactly", () => { - const smallProxied = createThemeValuesProxy({ - value, - breakpoints, - deviceWidth: breakpoints.small, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(smallProxied.breakpoint).toEqual(value.breakpoint.small); - }); - - test("returns small breakpoint value when device width matches", () => { - const smallProxied = createThemeValuesProxy({ - value, - breakpoints, - deviceWidth: breakpoints.small + 50, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(smallProxied.breakpoint).toEqual(value.breakpoint.small); - }); - - test("returns medium breakpoint value when device width matches exactly", () => { - const mediumProxied = createThemeValuesProxy({ - value, - breakpoints, - deviceWidth: breakpoints.medium, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(mediumProxied.breakpoint).toEqual(value.breakpoint.medium); - }); - - test("returns medium breakpoint value when device width matches", () => { - const mediumProxied = createThemeValuesProxy({ - value, - breakpoints, - deviceWidth: breakpoints.medium + 50, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(mediumProxied.breakpoint).toEqual(value.breakpoint.medium); - }); - - test("returns large breakpoint value when device width matches exactly", () => { - const largeProxied = createThemeValuesProxy({ - value, - breakpoints, - deviceWidth: breakpoints.large, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(largeProxied.breakpoint).toEqual(value.breakpoint.large); - }); - - test("returns large breakpoint value when device width matches is over the largest", () => { - const largeProxied = createThemeValuesProxy({ - value, - breakpoints, - deviceWidth: breakpoints.large + 400, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(largeProxied.breakpoint).toEqual(value.breakpoint.large); - }); - - test("returns default breakpoint value when device width matches is below the smallest", () => { - const verySmallProxied = createThemeValuesProxy({ - value, - breakpoints, - deviceWidth: 50, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(verySmallProxied.breakpoint).toEqual(value.breakpoint.default); - }); - - test("returns nested small breakpoint value when device width matches", () => { - const smallProxied = createThemeValuesProxy({ - value, - breakpoints, - deviceWidth: breakpoints.small, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(smallProxied.breakpointNested.nested).toEqual( - value.breakpointNested.small.nested - ); - }); - - test("returns nested medium breakpoint value when device width matches", () => { - const mediumProxied = createThemeValuesProxy({ - value, - breakpoints, - deviceWidth: breakpoints.medium, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(mediumProxied.breakpointNested.nested).toEqual( - value.breakpointNested.medium.nested - ); - }); - }); - - describe("Light Dark Value", () => { - test("returns light value when key is light", () => { - const lightProxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(lightProxied.lightDark).toEqual(value.lightDark.light); - }); - - test("returns dark value when key is dark", () => { - const darkProxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "android", - currentLightDarkSelection: "dark", - })!; - expect(darkProxied.lightDark).toEqual(value.lightDark.dark); - }); - - test("returns default value when key is not light or dark", () => { - const otherProxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "android", - currentLightDarkSelection: "other" as any, - })!; - expect(otherProxied.lightDark).toEqual(value.lightDark.default); - }); - - test("returns nested light value when key is light", () => { - const lightProxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(lightProxied.lightDarkNested.nested).toEqual( - value.lightDarkNested.light.nested - ); - }); - - test("returns nested dark value when key is dark", () => { - const darkProxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "android", - currentLightDarkSelection: "dark", - })!; - expect(darkProxied.lightDarkNested.nested).toEqual( - value.lightDarkNested.dark.nested - ); - }); - }); - - describe("Typography Values", () => { - test("returns typography object when value is top level", () => { - const proxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(proxied.typography.body1).toEqual(value.typography.body1); - }); - - test("returns nested typography object when value is nested", () => { - const proxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(proxied.typography.bodyNested.mine).toEqual( - value.typography.bodyNested.mine - ); - }); - - test("returns android platform typography object when device is android", () => { - const proxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "android", - currentLightDarkSelection: "light", - })!; - expect(proxied.typography.bodyPlatform).toEqual( - value.typography.bodyPlatform.android - ); - }); - - test("returns default platform typography object when device is other", () => { - const proxied = createThemeValuesProxy({ - value, - breakpoints: {}, - deviceWidth: 400, - devicePlatform: "web", - currentLightDarkSelection: "light", - })!; - expect(proxied.typography.bodyPlatform).toEqual( - value.typography.bodyPlatform.default - ); - }); - }); -}); diff --git a/packages/theme/src/__tests__/validators.test.ts b/packages/theme/src/__tests__/validators.test.ts deleted file mode 100644 index 16784f9a9..000000000 --- a/packages/theme/src/__tests__/validators.test.ts +++ /dev/null @@ -1,220 +0,0 @@ -import { - validatePalettes, - validateBreakpoints, - validateTheme, -} from "../validators"; -import DefaultTheme from "../DefaultTheme"; - -describe("Theme validators tests", () => { - describe("validatePalettes", () => { - const invalidPalettes = [ - { - draftbit: { - primary: 1000, - secondary: "rgb(59, 201, 234)", - }, - }, - { - draftbit: { - primary: true, - secondary: "rgb(59, 201, 234)", - }, - }, - { - draftbit: { - primary: "rgb(59, 201, 234)", - secondary: "rgb(59, 201, 234)", - }, - another: { - primary: 1000, - secondary: "rgb(59, 201, 234)", - }, - }, - ]; - - const validPalettes = [ - { - draftbit: { - primary: "rgb(59, 201, 234)", - secondary: "rgb(59, 201, 234)", - }, - }, - { - draftbit: { - primary: "rgb(59, 201, 234)", - secondary: "rgb(59, 201, 234)", - }, - another: { - primary: "rgb(59, 201, 234)", - secondary: "rgb(59, 201, 234)", - }, - }, - {}, - ]; - test.each(invalidPalettes)( - "should throw an error with invalid palettes (%#)", - (palette) => { - expect(() => validatePalettes(palette as any)).toThrowError(); - } - ); - test.each(validPalettes)( - "should not throw an error with valid palettes (%#)", - (palette) => { - expect(() => validatePalettes(palette as any)).not.toThrowError(); - } - ); - }); - - describe("validateBreakpoints", () => { - const invalidBreakpoints = [ - { mobile: "100" }, - { mobile: true, laptop: 200 }, - { mobile: 100, laptop: "400" }, - ]; - - const validBreakpoints = [ - { - mobile: 100, - laptop: 200, - desktop: 300, - }, - { mobile: 100 }, - {}, - ]; - test.each(invalidBreakpoints)( - "should throw an error with invalid breakpoints (%#)", - (breakpoint) => { - expect(() => validateBreakpoints(breakpoint as any)).toThrowError(); - } - ); - test.each(validBreakpoints)( - "should not throw an error with valid breakpoints (%#)", - (breakpoint) => { - expect(() => validateBreakpoints(breakpoint as any)).not.toThrowError(); - } - ); - }); - - describe("validateTheme", () => { - const invalidThemes = [ - { - name: "Draftbit", - colors: { - branding: { - primary: true, - }, - }, - typography: {}, - }, - { - name: "Draftbit", - colors: { - branding: { - primary: { - something: { - nested: true, - }, - }, - }, - }, - typography: {}, - }, - { - name: "Draftbit", - colors: { - branding: { - primary: "red", - }, - }, - typography: { - headline4: { - fontSize: 24, - letterSpacing: 0, - lineHeight: 34, - }, - headline6: 20, - }, - }, - { - name: "Draftbit", - colors: { - branding: { - primary: "red", - }, - }, - typography: { - headline4: { - sub: false, - }, - }, - }, - ]; - - const validThemes = [ - DefaultTheme, - { - name: "Draftbit", - colors: { - branding: { - primary: { - another: 50, - something: { - nested: "rgba(0,0,0,1)", - }, - }, - }, - }, - typography: {}, - }, - { - name: "Draftbit", - colors: { - branding: { - primary: { - another: 50, - something: { - nested: "rgba(0,0,0,1)", - }, - }, - }, - }, - typography: { - headline4: { - fontSize: 24, - letterSpacing: 0, - lineHeight: 34, - }, - headline5: { - fontSize: 20, - letterSpacing: 0, - lineHeight: 26, - }, - headline6: { - android: { - fontSize: 20, - letterSpacing: 0, - lineHeight: 26, - }, - ios: { - fontSize: 16, - letterSpacing: 1, - lineHeight: 20, - }, - }, - }, - }, - ]; - test.each(invalidThemes)( - "should throw an error with invalid theme (%#)", - (theme) => { - expect(() => validateTheme(theme as any)).toThrowError(); - } - ); - test.each(validThemes)( - "should not throw an error with valid theme (%#)", - (theme) => { - expect(() => validateTheme(theme as any)).not.toThrowError(); - } - ); - }); -});