Skip to content

Commit

Permalink
Merge branch 'develop' into feat/create-user-account
Browse files Browse the repository at this point in the history
  • Loading branch information
riqwan authored Mar 25, 2024
2 parents f1d16f7 + 509ddf9 commit 0be54d8
Show file tree
Hide file tree
Showing 128 changed files with 4,164 additions and 1,203 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-houses-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

feat(medusa): migrate medusa unit tests to run with swc jest
11 changes: 11 additions & 0 deletions .changeset/thirty-moons-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@medusajs/ui-preset": patch
"@medusajs/ui": patch
"@medusajs/medusa": patch
"@medusajs/client-types": patch
---

feat(ui-preset): Pull latest styles from Figma.
fix(ui): Fix invalid state styling of Select, so it correctly shows when aria-invalid is true.
fix(medusa): Align query params between `/admin/products/:id/variants` and `/admin/variants`.
chore(client-types): Update `medusa` client types to reflect changes to the API.
31 changes: 0 additions & 31 deletions integration-tests/api/__tests__/admin/__snapshots__/auth.js.snap

This file was deleted.

2 changes: 1 addition & 1 deletion integration-tests/api/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
`__testfixtures__`,
`.cache`,
],
transformIgnorePatterns: [`/dist`],
transformIgnorePatterns: ["/dist", "/node_modules/"],
transform: { "^.+\\.[jt]s$": ["@swc/jest"] },
setupFiles: ["../setup-env.js"],
setupFilesAfterEnv: ["../setup.js"],
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"private": true,
"scripts": {
"test:integration": "jest --silent=false --maxWorkers=50% --bail --detectOpenHandles --forceExit --logHeapUsage",
"test:integration:chunk": "jest --silent --bail --maxWorkers=50% --forceExit --testPathPattern=$(echo $CHUNKS | jq -r \".[${CHUNK}] | .[]\")",
"test:integration:chunk": "jest --silent --bail --maxWorkers=50% --forceExit --detectOpenHandles --testPathPattern=$(echo $CHUNKS | jq -r \".[${CHUNK}] | .[]\")",
"build": "babel src -d dist --extensions \".ts,.js\""
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/modules/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
`__testfixtures__`,
`.cache`,
],
transformIgnorePatterns: [`/dist`],
transformIgnorePatterns: ["/dist", "/node_modules/"],
transform: {
"^.+\\.[jt]s$": ["@swc/jest"],
},
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"private": true,
"scripts": {
"test:integration": "jest --silent=false --maxWorkers=50% --bail --detectOpenHandles --forceExit --logHeapUsage",
"test:integration": "jest --silent --maxWorkers=50% --bail --detectOpenHandles --forceExit --logHeapUsage",
"test:integration:chunk": "jest --silent --bail --maxWorkers=50% --forceExit --testPathPattern=$(echo $CHUNKS | jq -r \".[${CHUNK}] | .[]\")",
"build": "babel src -d dist --extensions \".ts,.js\""
},
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/plugins/__tests__/inventory/order/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe("/store/carts", () => {
})

const customer = await simpleCustomerFactory(dbConnection, {}, 100)

const items = []
const cart = await simpleCartFactory(dbConnection, {
email: "[email protected]",
region: regionId,
Expand All @@ -194,7 +194,6 @@ describe("/store/carts", () => {
],
})

const items = []
for (let i = 0; i < 13; i++) {
const product = await simpleProductFactory(dbConnection, {})
await prodVarInventoryService.attachInventoryItem(
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/plugins/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = {
`__testfixtures__`,
`.cache`,
],
transformIgnorePatterns: [`/dist`],
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
transformIgnorePatterns: ["/dist", "/node_modules/"],
transform: { "^.+\\.[jt]s$": `@swc/jest` },
setupFiles: ["../setup-env.js"],
setupFilesAfterEnv: ["../setup.js"],
globalSetup: "../globalSetup.js",
Expand Down
4 changes: 3 additions & 1 deletion integration-tests/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"private": true,
"scripts": {
"test:integration": "node --expose-gc ./../../node_modules/.bin/jest --silent=false --runInBand --bail --detectOpenHandles --logHeapUsage --clearMocks --forceExit",
"test:integration": "jest --silent=false --maxWorkers=50% --bail --detectOpenHandles --clearMocks --forceExit",
"build": "babel src -d dist --extensions \".ts,.js\""
},
"dependencies": {
Expand Down Expand Up @@ -40,6 +40,8 @@
"@babel/core": "^7.12.10",
"@babel/node": "^7.12.10",
"@medusajs/types": "workspace:^",
"@swc/core": "^1.4.8",
"@swc/jest": "^0.2.36",
"babel-preset-medusa-package": "*",
"jest": "^26.6.3",
"jest-environment-node": "26.6.2"
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/repositories/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
`__testfixtures__`,
`.cache`,
],
transformIgnorePatterns: [`/dist`],
transformIgnorePatterns: ["/dist", "/node_modules/"],
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
setupFiles: ["../setup-env.js"],
setupFilesAfterEnv: ["../setup.js"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"edit": "Edit",
"download": "Download",
"clearAll": "Clear all",
"apply": "Apply"
"apply": "Apply",
"add": "Add"
},
"filters": {
"date": {
Expand Down Expand Up @@ -391,6 +392,34 @@
"status": {
"open": "Open",
"completed": "Completed"
},
"create": {
"createDraftOrder": "Create Draft Order",
"createDraftOrderHint": "Create a new draft order to manage the details of an order before it is placed.",
"chooseRegionHint": "Choose region",
"existingItemsLabel": "Existing items",
"existingItemsHint": "Add existing products to the draft order.",
"customItemsLabel": "Custom items",
"customItemsHint": "Add custom items to the draft order.",
"addExistingItemsAction": "Add existing items",
"addCustomItemAction": "Add custom item",
"noCustomItemsAddedLabel": "No custom items added yet",
"noExistingItemsAddedLabel": "No existing items added yet",
"chooseRegionTooltip": "Choose a region first",
"useExistingCustomerLabel": "Use existing customer",
"addShippingMethodsAction": "Add shipping methods",
"unitPriceOverrideLabel": "Unit price override",
"shippingOptionLabel": "Shipping option",
"shippingOptionHint": "Choose the shipping option for the draft order.",
"shippingPriceOverrideLabel": "Shipping price override",
"shippingPriceOverrideHint": "Override the shipping price for the draft order.",
"sendNotificationLabel": "Send notification",
"sendNotificationHint": "Send a notification to the customer when the draft order is created."
},
"validation": {
"requiredEmailOrCustomer": "Email or customer is required.",
"requiredItems": "At least one item is required.",
"invalidEmail": "Email must be a valid email address."
}
},
"discounts": {
Expand Down Expand Up @@ -846,6 +875,7 @@
"orders": "Orders",
"account": "Account",
"total": "Total",
"totalExclTax": "Total excl. tax",
"subtotal": "Subtotal",
"shipping": "Shipping",
"tax": "Tax",
Expand Down Expand Up @@ -887,6 +917,7 @@
"thumbnail": "Thumbnail",
"sku": "SKU",
"managedInventory": "Managed inventory",
"allowBackorder": "Allow backorder",
"inStock": "In stock",
"location": "Location",
"quantity": "Quantity",
Expand All @@ -896,9 +927,11 @@
"maxSubtotal": "Max. Subtotal",
"shippingProfile": "Shipping Profile",
"summary": "Summary",
"details": "Details",
"label": "Label",
"rate": "Rate",
"requiresShipping": "Requires shipping",
"unitPrice": "Unit price",
"startDate": "Start date",
"endDate": "End date",
"draft": "Draft"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const ComboboxImpl = <T extends Value = string>(
const results = isSearchControlled ? options : matches

return (
<Popover.Root open={open} onOpenChange={setOpen}>
<Popover.Root modal open={open} onOpenChange={setOpen}>
<PrimitiveComboboxProvider
open={open}
setOpen={setOpen}
Expand All @@ -199,7 +199,7 @@ const ComboboxImpl = <T extends Value = string>(
"bg-ui-bg-field transition-fg shadow-borders-base",
"hover:bg-ui-bg-field-hover",
"has-[input:focus]:shadow-borders-interactive-with-active",
"has-[:invalid]:shadow-borders-error",
"has-[:invalid]:shadow-borders-error has-[[aria-invalid=true]]:shadow-borders-error",
"has-[:disabled]:bg-ui-bg-disabled has-[:disabled]:text-ui-fg-disabled has-[:disabled]:cursor-not-allowed",
{
"pl-0.5": hasValue && isArrayValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Tooltip } from "@medusajs/ui"
import { PropsWithChildren, ReactNode } from "react"

type ConditionalTooltipProps = PropsWithChildren<{
content: ReactNode
showTooltip?: boolean
}>

export const ConditionalTooltip = ({
children,
content,
showTooltip = false,
}: ConditionalTooltipProps) => {
if (showTooltip) {
return <Tooltip content={content}>{children}</Tooltip>
}

return children
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./conditional-tooltip"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Address, Cart, Order } from "@medusajs/medusa"
import { Avatar, Copy, Text } from "@medusajs/ui"
import { useTranslation } from "react-i18next"
import { Link } from "react-router-dom"
import { getFormattedAddress, isSameAddress } from "../../../lib/addresses"

const ID = ({ data }: { data: Cart | Order }) => {
const { t } = useTranslation()
Expand Down Expand Up @@ -182,74 +183,6 @@ export const CustomerInfo = Object.assign(
}
)

const isSameAddress = (a: Address | null, b: Address | null) => {
if (!a || !b) {
return false
}

return (
a.first_name === b.first_name &&
a.last_name === b.last_name &&
a.address_1 === b.address_1 &&
a.address_2 === b.address_2 &&
a.city === b.city &&
a.postal_code === b.postal_code &&
a.province === b.province &&
a.country_code === b.country_code
)
}

const getFormattedAddress = ({ address }: { address: Address }) => {
const {
first_name,
last_name,
company,
address_1,
address_2,
city,
postal_code,
province,
country,
country_code,
} = address

const name = [first_name, last_name].filter(Boolean).join(" ")

const formattedAddress = []

if (name) {
formattedAddress.push(name)
}

if (company) {
formattedAddress.push(company)
}

if (address_1) {
formattedAddress.push(address_1)
}

if (address_2) {
formattedAddress.push(address_2)
}

const cityProvincePostal = [city, province, postal_code]
.filter(Boolean)
.join(" ")

if (cityProvincePostal) {
formattedAddress.push(cityProvincePostal)
}

if (country) {
formattedAddress.push(country.display_name)
} else if (country_code) {
formattedAddress.push(country_code.toUpperCase())
}

return formattedAddress
}

const getCartOrOrderCustomer = (obj: Cart | Order) => {
const { first_name: sFirstName, last_name: sLastName } =
obj.shipping_address || {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { clx } from "@medusajs/ui"
import { ComponentPropsWithoutRef } from "react"

interface DividerProps
extends Omit<ComponentPropsWithoutRef<"div">, "children"> {
orientation?: "horizontal" | "vertical"
variant?: "dashed" | "solid"
}

export const Divider = ({
orientation = "horizontal",
variant = "solid",
className,
...props
}: DividerProps) => {
return (
<div
aria-orientation={orientation}
role="separator"
className={clx(
{
"w-full border-t": orientation === "horizontal",
"h-full border-l": orientation === "vertical",
"border-dashed": variant === "dashed",
},
className
)}
{...props}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./divider"
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Photo } from "@medusajs/icons";
import { Photo } from "@medusajs/icons"

type ThumbnailProps = {
src?: string | null;
alt?: string;
};
src?: string | null
alt?: string
}

export const Thumbnail = ({ src, alt }: ThumbnailProps) => {
return (
Expand All @@ -15,8 +15,8 @@ export const Thumbnail = ({ src, alt }: ThumbnailProps) => {
className="h-full w-full object-cover object-center"
/>
) : (
<Photo />
<Photo className="text-ui-fg-subtle" />
)}
</div>
);
};
)
}
Loading

0 comments on commit 0be54d8

Please sign in to comment.