Skip to content

Commit

Permalink
Merge branch 'main' into tests-for-setting-balance-and-exporting-gift…
Browse files Browse the repository at this point in the history
…-cards
  • Loading branch information
karola312 authored Feb 5, 2024
2 parents fbb4cc4 + 9a48841 commit 9c68092
Show file tree
Hide file tree
Showing 16 changed files with 276 additions and 99 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-kings-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Fix variant availability
5 changes: 5 additions & 0 deletions .changeset/neat-apples-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Fix action that configures login to staging Saleor Cloud for CLI
9 changes: 6 additions & 3 deletions .github/actions/cli-login/action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Saleor CLI login
description: Saleor CLI login
description: Saleor CLI login to staging Saleor Cloud
inputs:
token:
description: "Cloud accces token"
description: "Cloud access token"
required: true
runs:
using: "composite"
Expand All @@ -12,4 +12,7 @@ runs:
id: write-config-file
env:
ACCESS_TOKEN: ${{ inputs.token }}
run: jq --null-input --arg token "Token $ACCESS_TOKEN" '{"token":$token,"telemetry":"false","organization_slug":"saleor","organization_name":"Saleor"}' > ~/.config/saleor.json
run: |
jq --null-input \
--arg token "Token $ACCESS_TOKEN" \
'{"token":$token,"telemetry":"false","saleor_env":"staging","cloud_api_url":"https://staging-cloud.saleor.io/platform/api","organization_slug":"saleor","organization_name":"Saleor"}' > ~/.config/saleor.json
1 change: 0 additions & 1 deletion .github/actions/prepare-backups-variables/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ runs:
id: backup
shell: bash
env:
SALEOR_CLI_ENV: staging
BACKUP_NAME: ${{ inputs.BACKUP_NAMESPACE }}
run: |
BACKUPS=$(npx saleor backup list --name="$BACKUP_NAME" --latest --json)
Expand Down
5 changes: 1 addition & 4 deletions .github/actions/prepare-instance/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ runs:
shell: bash
id: instance_check
env:
SALEOR_CLI_ENV: staging
INSTANCE_NAME: ${{ inputs.POOL_NAME }}
run: |
set +o pipefail
Expand All @@ -47,7 +46,6 @@ runs:
shell: bash
if: ${{ steps.instance_check.outputs.INSTANCE_KEY }}
env:
SALEOR_CLI_ENV: staging
BACKUP_ID: ${{ inputs.BACKUP_ID }}
INSTANCE_NAME: ${{ inputs.POOL_NAME }}
run: |
Expand All @@ -59,7 +57,6 @@ runs:
shell: bash
if: ${{ !steps.instance_check.outputs.INSTANCE_KEY }}
env:
SALEOR_CLI_ENV: staging
BACKUP_ID: ${{ inputs.BACKUP_ID }}
INSTANCE_NAME: ${{ inputs.POOL_NAME }}
run: |
Expand All @@ -70,4 +67,4 @@ runs:
--saleor=saleor-master-staging \
--domain="$INSTANCE_NAME" \
--skip-restrict \
--skip-webhooks-update
--skip-webhooks-update
3 changes: 1 addition & 2 deletions .github/workflows/pr-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ jobs:

- name: Remove instance
env:
SALEOR_CLI_ENV: staging
PULL_REQUEST_NUMBER: ${{ github.event.number }}
run: npx saleor env remove "pr-${PULL_REQUEST_NUMBER}" --force
run: npx saleor env remove "pr-${PULL_REQUEST_NUMBER}" --force
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
import {
ChannelPriceAndPreorderData,
IChannelPriceAndPreorderArgs,
} from "@dashboard/channels/utils";
import { Divider } from "@dashboard/components/Divider";
import { FormsetData } from "@dashboard/hooks/useFormset";
import React from "react";

import { Channel, ProductChannelListing } from "./../types";
import { ProductChannelListing } from "./../types";
import { ChannelsListItem } from "./ChannelsListItem";
import CardContainer from "./VariantDetailsChannelsAvailabilityCardContainer";

interface AvailabilityCardProps {
items: Channel[];
allAvailableListings: FormsetData<
ChannelPriceAndPreorderData,
IChannelPriceAndPreorderArgs
>;
productChannelListings: ProductChannelListing;
}

export const AvailabilityCard: React.FC<AvailabilityCardProps> = ({
items,
allAvailableListings,
productChannelListings,
children,
}) => {
if (items.length === 0) {
if (allAvailableListings.length === 0) {
return <CardContainer cardTitle={children}>{}</CardContainer>;
}

const listingIds = allAvailableListings.map(lst => lst.id);
const filteredListings: ProductChannelListing =
productChannelListings?.filter((channel: ProductChannelListing[0]) =>
listingIds.includes(channel.channel.id),
);

return (
<CardContainer cardTitle={children}>
{items.map(channel => (
{filteredListings.map((listing: ProductChannelListing[0]) => (
<ChannelsListItem
{...channel}
listings={productChannelListings}
key={channel.id}
{...listing}
id={listing.channel.id}
name={listing.channel.name}
key={listing.channel.id}
/>
))}
<Divider />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@ import React from "react";
import { useIntl } from "react-intl";

import { variantDetailsChannelsAvailabilityCardMessages as messages } from "./../messages";
import { Channel, ProductChannelListing } from "./../types";

type ChannelsListItemProps = Pick<Channel, "id" | "name"> & {
listings: ProductChannelListing;
};
interface ChannelsListItemProps {
id: string;
name: string;
isPublished: boolean;
publicationDate: string;
}

export const ChannelsListItem: React.FC<ChannelsListItemProps> = ({
id,
name,
listings,
isPublished,
publicationDate,
}) => {
const intl = useIntl();
const localizeDate = useDateLocalize();

const getItemSubtitle = (channelId: string) => {
const channelListing = listings.find(
({ channel }) => channel.id === channelId,
);

const { isPublished, publicationDate } = channelListing;

const getItemSubtitle = () => {
if (!isPublished) {
return intl.formatMessage(messages.itemSubtitleHidden);
}
Expand All @@ -53,7 +50,7 @@ export const ChannelsListItem: React.FC<ChannelsListItemProps> = ({
size="small"
data-test-id={`channels-variant-availability-item-subtitle-${id}`}
>
{getItemSubtitle(id)}
{getItemSubtitle()}
</Text>
</DashboardCard.Content>
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { variantDetailsChannelsAvailabilityCardMessages as messages } from "./..
interface CreateVariantTitleProps {
onManageClick: () => void;
disabled: boolean;
availabilityCount: Record<string, number>;
availabilityCount: Record<string, number | undefined>;
isEmpty: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import {
ChannelPriceAndPreorderData,
IChannelPriceAndPreorderArgs,
} from "@dashboard/channels/utils";
import {
ProductVariantCreateDataQuery,
ProductVariantFragment,
} from "@dashboard/graphql";
import { FormsetData } from "@dashboard/hooks/useFormset";

import {
getAvailabilityCountForProduct,
getAvailabilityCountForVariant,
} from "./availabilityCount";

const mockedListings = [
{
id: "1",
label: "Channel-PLN",
},
{
id: "2",
label: "Channel-USD",
},
] as unknown as FormsetData<
ChannelPriceAndPreorderData,
IChannelPriceAndPreorderArgs
>;

const mockedVariant = {
product: {
channelListings: [
{
channel: { id: "1" },
isPublished: true,
},
{
channel: { id: "2" },
isPublished: true,
},
],
},
} as unknown as ProductVariantFragment;

const mockedProduct = {
channelListings: [
{
channel: { id: "1" },
isPublished: true,
},
{
channel: { id: "2" },
isPublished: true,
},
],
} as unknown as ProductVariantCreateDataQuery["product"];

describe("getAvailabilityCountForVariant", () => {
it("should return correct counts when all channels are selected", () => {
// Arrange
const item = mockedVariant;
const listings = mockedListings;

// Act
const result = getAvailabilityCountForVariant(item, listings);

// Assert
expect(result).toEqual({
publishedInChannelsCount: 2,
availableChannelsCount: 2,
});
});

it("should return correct counts when some channels are selected", () => {
// Arrange
const item = mockedVariant;
const listings = mockedListings.slice(0, 1);

// Act
const result = getAvailabilityCountForVariant(item, listings);

// Assert
expect(result).toEqual({
publishedInChannelsCount: 1,
availableChannelsCount: 2,
});
});

it("should return correct counts when no channels are available", () => {
// Arrange
const item = mockedVariant;
const listings = [] as FormsetData<
ChannelPriceAndPreorderData,
IChannelPriceAndPreorderArgs
>;

// Act
const result = getAvailabilityCountForVariant(item, listings);

// Assert
expect(result).toEqual({
publishedInChannelsCount: 0,
availableChannelsCount: 2,
});
});
});

describe("getAvailabilityCountForProduct", () => {
it("should return correct counts when all channels are selected", () => {
// Arrange
const item = mockedProduct;
const listings = mockedListings;

// Act
const result = getAvailabilityCountForProduct(item, listings);

// Assert
expect(result).toEqual({
publishedInChannelsCount: 2,
availableChannelsCount: 2,
});
});

it("should return correct counts when some channels are selected", () => {
// Arrange
const item = mockedProduct;
const listings = mockedListings.slice(0, 1);

// Act
const result = getAvailabilityCountForProduct(item, listings);

// Assert
expect(result).toEqual({
publishedInChannelsCount: 1,
availableChannelsCount: 2,
});
});

it("should return correct counts when no channels are available", () => {
// Arrange
const item = mockedProduct;
const listings = [] as FormsetData<
ChannelPriceAndPreorderData,
IChannelPriceAndPreorderArgs
>;

// Act
const result = getAvailabilityCountForProduct(item, listings);

// Assert
expect(result).toEqual({
publishedInChannelsCount: 0,
availableChannelsCount: 2,
});
});
});
Loading

0 comments on commit 9c68092

Please sign in to comment.