Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move store directory and fix lint errors #2029

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import Topics from "../Topics";

import platforms from "../../data/platforms";
import packageTypes from "../../data/package-types";
import { Category } from "../../types";
import { Package, Publisher } from "../../../publisher-admin/types";

function Packages() {
const ITEMS_PER_PAGE = 12;

const getData = async () => {
const response = await fetch(`/store.json${search}`);
const data = await response.json();
const packagesWithId = data.packages.map((item: any) => {
const packagesWithId = data.packages.map((item: string[]) => {
return {
...item,
id: crypto.randomUUID(),
Expand All @@ -48,6 +50,8 @@ function Packages() {
const [hideFilters, setHideFilters] = useState(true);
const currentPage = searchParams.get("page") || "1";
const { data, status, refetch, isFetching } = useQuery("data", getData);
console.log(data);
console.log(typeof data);

const topicsQuery = searchParams ? searchParams.get("categories") : null;

Expand Down Expand Up @@ -110,7 +114,7 @@ function Packages() {
selectedCategories={
searchParams.get("categories")?.split(",") || []
}
setSelectedCategories={(items: any) => {
setSelectedCategories={(items: string[]) => {
if (items.length > 0) {
searchParams.set("categories", items.join(","));
} else {
Expand Down Expand Up @@ -182,19 +186,27 @@ function Packages() {
{!isFetching &&
status === "success" &&
data.packages.length > 0 &&
data.packages.map((packageData: any) => (
<Col
size={3}
style={{ marginBottom: "1.5rem" }}
key={packageData.id}
>
{packageData.package.type === "bundle" ? (
<BundleCard data={packageData} />
) : (
<CharmCard data={packageData} />
)}
</Col>
))}
data.packages.map(
(packageData: {
categories: Category[];
package: Package;
publisher: Publisher;
ratings: { count: string; value: string };
id: string;
}) => (
<Col
size={3}
style={{ marginBottom: "1.5rem" }}
key={packageData.id}
>
{packageData.package.type === "bundle" ? (
<BundleCard data={packageData} />
) : (
<CharmCard data={packageData} />
)}
</Col>
)
)}

{status === "success" && data.packages.length === 0 && (
<h1 className="p-heading--2">No packages match this filter</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import Packages from "../Packages";
import "@testing-library/jest-dom";

jest.mock("@canonical/store-components", () => ({
CharmCard: ({ data }: { data: any }) => <div>{data.name}</div>,
BundleCard: ({ data }: { data: any }) => <div>{data.name}</div>,
CharmCard: ({ data }: { data: { name: string } }) => <div>{data.name}</div>,
BundleCard: ({ data }: { data: { name: string } }) => <div>{data.name}</div>,
Filters: ({
setSelectedCategories,
setSelectedPlatform,
setSelectedPackageType,
}: any) => (
}: {
setSelectedCategories: (categories: string[]) => void;
setSelectedPlatform: (platform: string) => void;
setSelectedPackageType: (packageType: string) => void;
}) => (
<div>
<button onClick={() => setSelectedCategories(["category1"])}>
Set Categories
Expand Down Expand Up @@ -44,7 +48,7 @@ const renderPackages = () => {

describe("Packages component", () => {
beforeEach(() => {
jest.clearAllMocks();
jest.clearAllMocks();
});

test("renders Banner and Topics components", async () => {
Expand All @@ -63,7 +67,7 @@ describe("Packages component", () => {
});

test("renders no packages message when there are no results", async () => {
(global as any).fetch = jest.fn(() =>
(global.fetch as jest.Mock) = jest.fn(() =>
Promise.resolve({
json: () =>
Promise.resolve({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Topics from "../Topics";
import { QueryClient, QueryClientProvider } from "react-query";
import "@testing-library/jest-dom";

(global as any).fetch = jest.fn(() =>
(global.fetch as jest.Mock) = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve({ topics: [] }),
})
Expand Down Expand Up @@ -64,7 +64,7 @@ describe("Topics Component", () => {
},
];

(global as any).fetch = jest.fn(() =>
(global.fetch as unknown as jest.Mock) = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve({ topics: mockTopics }),
})
Expand All @@ -80,7 +80,7 @@ describe("Topics Component", () => {
});

test("renders empty state when no topics are available", async () => {
(global as any).fetch = jest.fn(() =>
(global.fetch as jest.Mock) = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve({ topics: [] }),
})
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion webpack.config.entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
"navigation-events": "./static/js/src/public/navigation-events.ts",
"icon-validator": "./static/js/src/public/icon-validator/index.tsx",
interfaces: "./static/js/src/interfaces/index.tsx",
store: "./static/js/store/index.tsx",
store: "./static/js/src/store/index.tsx",
publisher: "./static/js/src/publisher-admin/index.tsx",
search: "./static/js/src/search/App.tsx",
};
Loading