From 702b158cb7596f8d9ba0c9fca948809192d8521c Mon Sep 17 00:00:00 2001 From: kielbasa-elp Date: Sat, 24 Feb 2024 16:16:51 +0100 Subject: [PATCH] Move all tests to separate folder --- .../app/tests/handlers/collection.handlers.ts | 26 +++-------- .../app/tests/handlers/model.handlers.ts | 22 +++------ .../app/tests/handlers/secret.handlers.ts | 7 +-- .../integrations/auth}/login.handlers.ts | 0 .../integrations/auth}/login.test.tsx | 6 +-- .../integrations/auth}/register.handlers.ts | 0 .../integrations/auth}/register.test.tsx | 8 ++-- .../knowledge}/knowledgeBase.test.tsx | 46 +++++++++++++------ .../organizations}/onboarding.test.tsx | 20 ++++---- .../integrations/pipelines}/build.test.tsx | 38 ++++++++++----- .../pipelines}/pipelines.test.tsx | 12 ++--- 11 files changed, 100 insertions(+), 85 deletions(-) rename apps/web-remix/app/{components/pages/auth/login/__tests__ => tests/integrations/auth}/login.handlers.ts (100%) rename apps/web-remix/app/{components/pages/auth/login/__tests__ => tests/integrations/auth}/login.test.tsx (93%) rename apps/web-remix/app/{components/pages/auth/register/__tests__ => tests/integrations/auth}/register.handlers.ts (100%) rename apps/web-remix/app/{components/pages/auth/register/__tests__ => tests/integrations/auth}/register.test.tsx (90%) rename apps/web-remix/app/{components/pages/knowledgeBase/__tests__ => tests/integrations/knowledge}/knowledgeBase.test.tsx (70%) rename apps/web-remix/app/{components/pages/home/__tests__ => tests/integrations/organizations}/onboarding.test.tsx (81%) rename apps/web-remix/app/{components/pages/pipelines/__tests__ => tests/integrations/pipelines}/build.test.tsx (91%) rename apps/web-remix/app/{components/pages/pipelines/__tests__ => tests/integrations/pipelines}/pipelines.test.tsx (89%) diff --git a/apps/web-remix/app/tests/handlers/collection.handlers.ts b/apps/web-remix/app/tests/handlers/collection.handlers.ts index 3462c0bdb..7b2f221e7 100644 --- a/apps/web-remix/app/tests/handlers/collection.handlers.ts +++ b/apps/web-remix/app/tests/handlers/collection.handlers.ts @@ -3,18 +3,13 @@ import { IKnowledgeBaseCollection, IKnowledgeBaseFile, } from "~/components/pages/knowledgeBase/knowledgeBase.types"; -import { collectionFixture } from "~/tests/fixtures/collection.fixtures"; import { ICreateCollectionSchema } from "~/api/knowledgeBase/knowledgeApi.contracts"; -import { collectionMemoryFixtures } from "~/tests/fixtures/collectionMemory.fixtures"; - export class CollectionHandlers { private collections: Map = new Map(); - constructor() { - this.collections.set(collectionFixture().id, collectionFixture()); - this.collections.set( - 2, - collectionFixture({ id: 2, name: "super-collection" }) + constructor(initials: IKnowledgeBaseCollection[] = []) { + initials.forEach((collection) => + this.collections.set(collection.id, collection) ); } @@ -40,10 +35,10 @@ export class CollectionHandlers { const newCollection = { ...data, - id: 3, + id: this.collections.size + 1, name: data.collection_name, }; - this.collections.set(3, newCollection); + this.collections.set(newCollection.id, newCollection); return HttpResponse.json( { data: newCollection }, @@ -85,15 +80,8 @@ export class CollectionHandlers { export class CollectionMemoriesHandlers { private collectionMemories: Map = new Map(); - constructor() { - this.collectionMemories.set( - collectionMemoryFixtures().id, - collectionMemoryFixtures() - ); - this.collectionMemories.set( - 2, - collectionMemoryFixtures({ id: 2, file_name: "test_file" }) - ); + constructor(initials: IKnowledgeBaseFile[] = []) { + initials.forEach((file) => this.collectionMemories.set(file.id, file)); } getCollectionMemories() { diff --git a/apps/web-remix/app/tests/handlers/model.handlers.ts b/apps/web-remix/app/tests/handlers/model.handlers.ts index 13cffb65c..4c1ae720c 100644 --- a/apps/web-remix/app/tests/handlers/model.handlers.ts +++ b/apps/web-remix/app/tests/handlers/model.handlers.ts @@ -1,20 +1,14 @@ import { http, HttpResponse } from "msw"; import { IAsyncSelectItem, IAsyncSelectItemList } from "~/api/AsyncSelectApi"; -import { - IFixtureAsyncSelectModel, - modelFixture, -} from "~/tests/fixtures/models.fixtures"; -import { embeddingFixture } from "~/tests/fixtures/embedding.fixtures"; +import { IFixtureAsyncSelectModel } from "~/tests/fixtures/models.fixtures"; //@todo handle filtering by api type export class EmbeddingsHandlers { private embeddings: Map = new Map(); - constructor() { - this.embeddings.set(embeddingFixture().id, embeddingFixture()); - this.embeddings.set( - "embedding", - embeddingFixture({ name: "embedding", id: "embedding" }) + constructor(initials: IAsyncSelectItem[] = []) { + initials.forEach((embedding) => + this.embeddings.set(embedding.id, embedding) ); } @@ -38,12 +32,8 @@ export class EmbeddingsHandlers { export class ModelsHandlers { private models: Map = new Map(); - constructor() { - this.models.set(embeddingFixture().id, modelFixture()); - this.models.set( - "Test", - modelFixture({ name: "Test", id: "Test", type: "google" }) - ); + constructor(initials: IFixtureAsyncSelectModel[] = []) { + initials.forEach((model) => this.models.set(model.id, model)); } getModelsHandler() { diff --git a/apps/web-remix/app/tests/handlers/secret.handlers.ts b/apps/web-remix/app/tests/handlers/secret.handlers.ts index a8d6ecb57..70d212df0 100644 --- a/apps/web-remix/app/tests/handlers/secret.handlers.ts +++ b/apps/web-remix/app/tests/handlers/secret.handlers.ts @@ -5,9 +5,10 @@ import { secretFixture } from "~/tests/fixtures/secrets.fixtures"; export class SecretsHandlers { private secrets: Map = new Map(); - constructor() { - this.secrets.set(secretFixture().id, secretFixture()); - this.secrets.set("Test", secretFixture({ name: "Test", id: "Test" })); + constructor(initials: IAsyncSelectItem[] = []) { + initials.forEach((secret) => this.secrets.set(secret.id, secret)); + // this.secrets.set(secretFixture().id, secretFixture()); + // this.secrets.set("Test", secretFixture({ name: "Test", id: "Test" })); } getSecretsHandler() { diff --git a/apps/web-remix/app/components/pages/auth/login/__tests__/login.handlers.ts b/apps/web-remix/app/tests/integrations/auth/login.handlers.ts similarity index 100% rename from apps/web-remix/app/components/pages/auth/login/__tests__/login.handlers.ts rename to apps/web-remix/app/tests/integrations/auth/login.handlers.ts diff --git a/apps/web-remix/app/components/pages/auth/login/__tests__/login.test.tsx b/apps/web-remix/app/tests/integrations/auth/login.test.tsx similarity index 93% rename from apps/web-remix/app/components/pages/auth/login/__tests__/login.test.tsx rename to apps/web-remix/app/tests/integrations/auth/login.test.tsx index 3ce9ee121..f0b88303c 100644 --- a/apps/web-remix/app/components/pages/auth/login/__tests__/login.test.tsx +++ b/apps/web-remix/app/tests/integrations/auth/login.test.tsx @@ -5,9 +5,9 @@ import { ButtonHandle } from "~/tests/handles/Button.handle"; import { InputHandle } from "~/tests/handles/Input.handle"; import { render, screen, waitFor, act } from "~/tests/render"; import { server } from "~/tests/server.mock"; -import { LoginPage } from "../page"; -import { loader } from "../loader.server"; -import { action } from "../action.server"; +import { LoginPage } from "~/components/pages/auth/login/page"; +import { loader } from "~/components/pages/auth/login/loader.server"; +import { action } from "~/components/pages/auth/login/action.server"; import { errorHandlers, handlers } from "./login.handlers"; describe(LoginPage.name, () => { diff --git a/apps/web-remix/app/components/pages/auth/register/__tests__/register.handlers.ts b/apps/web-remix/app/tests/integrations/auth/register.handlers.ts similarity index 100% rename from apps/web-remix/app/components/pages/auth/register/__tests__/register.handlers.ts rename to apps/web-remix/app/tests/integrations/auth/register.handlers.ts diff --git a/apps/web-remix/app/components/pages/auth/register/__tests__/register.test.tsx b/apps/web-remix/app/tests/integrations/auth/register.test.tsx similarity index 90% rename from apps/web-remix/app/components/pages/auth/register/__tests__/register.test.tsx rename to apps/web-remix/app/tests/integrations/auth/register.test.tsx index f7680d3c9..1b6f48abc 100644 --- a/apps/web-remix/app/components/pages/auth/register/__tests__/register.test.tsx +++ b/apps/web-remix/app/tests/integrations/auth/register.test.tsx @@ -3,11 +3,11 @@ import { test, describe } from "vitest"; import { RoutesProps, setupRoutes } from "~/tests/setup.tests"; import { ButtonHandle } from "~/tests/handles/Button.handle"; import { InputHandle } from "~/tests/handles/Input.handle"; -import { render, screen, waitFor, act } from "~/tests/render"; +import { render, screen } from "~/tests/render"; import { server } from "~/tests/server.mock"; -import { RegisterPage } from "../page"; -import { loader } from "../loader.server"; -import { action } from "../action.server"; +import { RegisterPage } from "~/components/pages/auth/register/page"; +import { loader } from "~/components/pages/auth/register/loader.server"; +import { action } from "~/components/pages/auth/register/action.server"; import { errorHandlers, handlers } from "./register.handlers"; describe(RegisterPage.name, () => { diff --git a/apps/web-remix/app/components/pages/knowledgeBase/__tests__/knowledgeBase.test.tsx b/apps/web-remix/app/tests/integrations/knowledge/knowledgeBase.test.tsx similarity index 70% rename from apps/web-remix/app/components/pages/knowledgeBase/__tests__/knowledgeBase.test.tsx rename to apps/web-remix/app/tests/integrations/knowledge/knowledgeBase.test.tsx index 2a822f065..16dd630dc 100644 --- a/apps/web-remix/app/components/pages/knowledgeBase/__tests__/knowledgeBase.test.tsx +++ b/apps/web-remix/app/tests/integrations/knowledge/knowledgeBase.test.tsx @@ -8,8 +8,8 @@ import { } from "~/tests/setup.tests"; import { render, screen, waitFor } from "~/tests/render"; import { server } from "~/tests/server.mock"; -import { loader as listLoader } from "../list/loader.server"; -import { action as listAction } from "../list/action.server"; +import { loader as listLoader } from "~/components/pages/knowledgeBase/list/loader.server"; +import { action as listAction } from "~/components/pages/knowledgeBase/list/action.server"; import { ListHandle } from "~/tests/handles/List.handle"; import { InputHandle } from "~/tests/handles/Input.handle"; import { ButtonHandle } from "~/tests/handles/Button.handle"; @@ -19,24 +19,44 @@ import { CollectionHandlers, CollectionMemoriesHandlers, } from "~/tests/handlers/collection.handlers"; -import { NewKnowledgeBasePage } from "../newKnowledgeBase/page"; -import { loader as newCollectionLoader } from "../newKnowledgeBase/loader.server"; -import { action as newCollectionAction } from "../newKnowledgeBase/action.server"; -import { KnowledgeBaseCollectionPage } from "../collection/page"; -import { loader as collectionLoader } from "../collection/loader.server"; -import { action as collectionAction } from "../collection/action.server"; +import { NewKnowledgeBasePage } from "~/components/pages/knowledgeBase/newKnowledgeBase/page"; +import { loader as newCollectionLoader } from "~/components/pages/knowledgeBase/newKnowledgeBase/loader.server"; +import { action as newCollectionAction } from "~/components/pages/knowledgeBase/newKnowledgeBase/action.server"; +import { KnowledgeBaseCollectionPage } from "~/components/pages/knowledgeBase/collection/page"; +import { loader as collectionLoader } from "~/components/pages/knowledgeBase/collection/loader.server"; +import { action as collectionAction } from "~/components/pages/knowledgeBase/collection/action.server"; import { EmbeddingsHandlers, ModelsHandlers, } from "~/tests/handlers/model.handlers"; import { SelectHandle } from "~/tests/handles/SelectHandle"; +import { collectionFixture } from "~/tests/fixtures/collection.fixtures"; +import { collectionMemoryFixtures } from "~/tests/fixtures/collectionMemory.fixtures"; +import { embeddingFixture } from "~/tests/fixtures/embedding.fixtures"; +import { modelFixture } from "~/tests/fixtures/models.fixtures"; +import { secretFixture } from "~/tests/fixtures/secrets.fixtures"; const handlers = () => [ - ...new CollectionHandlers().handlers, - ...new SecretsHandlers().handlers, - ...new EmbeddingsHandlers().handlers, - ...new ModelsHandlers().handlers, - ...new CollectionMemoriesHandlers().handlers, + ...new SecretsHandlers([ + secretFixture(), + secretFixture({ name: "Test", id: "Test" }), + ]).handlers, + ...new ModelsHandlers([ + modelFixture(), + modelFixture({ name: "Test", id: "Test", type: "google" }), + ]).handlers, + ...new EmbeddingsHandlers([ + embeddingFixture(), + embeddingFixture({ name: "embedding", id: "embedding" }), + ]).handlers, + ...new CollectionMemoriesHandlers([ + collectionMemoryFixtures(), + collectionMemoryFixtures({ id: 2, file_name: "test_file" }), + ]).handlers, + ...new CollectionHandlers([ + collectionFixture(), + collectionFixture({ id: 2, name: "super-collection" }), + ]).handlers, ]; describe("KnowledgeBase", () => { diff --git a/apps/web-remix/app/components/pages/home/__tests__/onboarding.test.tsx b/apps/web-remix/app/tests/integrations/organizations/onboarding.test.tsx similarity index 81% rename from apps/web-remix/app/components/pages/home/__tests__/onboarding.test.tsx rename to apps/web-remix/app/tests/integrations/organizations/onboarding.test.tsx index 6a80c93ef..3ceefecbf 100644 --- a/apps/web-remix/app/components/pages/home/__tests__/onboarding.test.tsx +++ b/apps/web-remix/app/tests/integrations/organizations/onboarding.test.tsx @@ -9,19 +9,19 @@ import { import { Outlet } from "@remix-run/react"; import { render, screen } from "~/tests/render"; import { server } from "~/tests/server.mock"; -import { PipelinesPage } from "../../pipelines/list/page"; -import { loader as pipelinesLoader } from "../../pipelines/list/loader.server"; -import { action as pipelinesAction } from "../../pipelines/list/action.server"; -import { NewOrganizationPage } from "../../organizations/new/page"; -import { loader as newOrganizationLoader } from "../../organizations/new/loader.server"; -import { action as newOrganizationAction } from "../../organizations/new/action.server"; -import { loader as organizationLoader } from "../../organizations/show/loader.server"; -import { loader as homeLoader } from "../loader.server"; +import { loader as pipelinesLoader } from "~/components/pages/pipelines/list/loader.server"; +import { action as pipelinesAction } from "~/components/pages/pipelines/list/action.server"; +import { loader as newOrganizationLoader } from "~/components/pages/organizations/new/loader.server"; +import { action as newOrganizationAction } from "~/components/pages/organizations/new/action.server"; +import { loader as organizationLoader } from "~/components/pages/organizations/show/loader.server"; +import { NewOrganizationPage } from "~/components/pages/organizations/new/page"; import { OrganizationHandlers } from "~/tests/handlers/organization.handlers"; +import { loader as homeLoader } from "~/components/pages/home/loader.server"; +import { organizationFixture } from "~/tests/fixtures/organization.fixtures"; import { PipelineHandlers } from "~/tests/handlers/pipelines.handlers"; -import { InputHandle } from "~/tests/handles/Input.handle"; +import { PipelinesPage } from "~/components/pages/pipelines/list/page"; import { ButtonHandle } from "~/tests/handles/Button.handle"; -import { organizationFixture } from "~/tests/fixtures/organization.fixtures"; +import { InputHandle } from "~/tests/handles/Input.handle"; const handlers = () => [ ...new PipelineHandlers().handlers, diff --git a/apps/web-remix/app/components/pages/pipelines/__tests__/build.test.tsx b/apps/web-remix/app/tests/integrations/pipelines/build.test.tsx similarity index 91% rename from apps/web-remix/app/components/pages/pipelines/__tests__/build.test.tsx rename to apps/web-remix/app/tests/integrations/pipelines/build.test.tsx index 2f479fd84..6c2994044 100644 --- a/apps/web-remix/app/components/pages/pipelines/__tests__/build.test.tsx +++ b/apps/web-remix/app/tests/integrations/pipelines/build.test.tsx @@ -18,17 +18,17 @@ import { RoutesProps, setupRoutes, } from "~/tests/setup.tests"; -import { loader as editBlockLoader } from "../build/editBlock/loader.server"; +import { loader as editBlockLoader } from "~/components/pages/pipelines/build/editBlock/loader.server"; import { handlers as blockTypesHandlers } from "~/tests/handlers/blockTypes.handlers"; -import { action as buildAction } from "../build/action.server"; -import { loader as buildLoader } from "../build/loader.server"; -import { EditBlockPage } from "../build/editBlock/page"; -import { PipelineBuilder } from "../build/page"; -import { PipelineLayout } from "../pipelineLayout/page"; +import { action as buildAction } from "~/components/pages/pipelines/build/action.server"; +import { loader as buildLoader } from "~/components/pages/pipelines/build/loader.server"; +import { EditBlockPage } from "~/components/pages/pipelines/build/editBlock/page"; +import { PipelineBuilder } from "~/components/pages/pipelines/build/page"; +import { PipelineLayout } from "~/components/pages/pipelines/pipelineLayout/page"; import { loader as layoutLoader, action as layoutAction, -} from "../pipelineLayout/index.server"; +} from "~/components/pages/pipelines/pipelineLayout/index.server"; import { PipelineHandlers, pipelineFixtureWithUnfilledBlock, @@ -48,13 +48,29 @@ import { RadioHandle } from "~/tests/handles/Radio.handle"; import { CollectionHandlers } from "~/tests/handlers/collection.handlers"; import { pipelineFixture } from "~/tests/fixtures/pipeline.fixtures"; import { aliasFixture } from "~/tests/fixtures/alias.fixtures"; +import { collectionFixture } from "~/tests/fixtures/collection.fixtures"; +import { embeddingFixture } from "~/tests/fixtures/embedding.fixtures"; +import { modelFixture } from "~/tests/fixtures/models.fixtures"; +import { secretFixture } from "~/tests/fixtures/secrets.fixtures"; const handlers = () => [ ...blockTypesHandlers(), - ...new SecretsHandlers().handlers, - ...new ModelsHandlers().handlers, - ...new CollectionHandlers().handlers, - ...new EmbeddingsHandlers().handlers, + ...new SecretsHandlers([ + secretFixture(), + secretFixture({ name: "Test", id: "Test" }), + ]).handlers, + ...new ModelsHandlers([ + modelFixture(), + modelFixture({ name: "Test", id: "Test", type: "google" }), + ]).handlers, + ...new EmbeddingsHandlers([ + embeddingFixture(), + embeddingFixture({ name: "embedding", id: "embedding" }), + ]).handlers, + ...new CollectionHandlers([ + collectionFixture(), + collectionFixture({ id: 2, name: "super-collection" }), + ]).handlers, ...new PipelineHandlers([ pipelineFixture(), pipelineFixture({ id: 2, name: "sample-workflow" }), diff --git a/apps/web-remix/app/components/pages/pipelines/__tests__/pipelines.test.tsx b/apps/web-remix/app/tests/integrations/pipelines/pipelines.test.tsx similarity index 89% rename from apps/web-remix/app/components/pages/pipelines/__tests__/pipelines.test.tsx rename to apps/web-remix/app/tests/integrations/pipelines/pipelines.test.tsx index b5b7726a9..e9a7be268 100644 --- a/apps/web-remix/app/components/pages/pipelines/__tests__/pipelines.test.tsx +++ b/apps/web-remix/app/tests/integrations/pipelines/pipelines.test.tsx @@ -7,15 +7,15 @@ import { setupRoutes, } from "~/tests/setup.tests"; import { ButtonHandle } from "~/tests/handles/Button.handle"; -import { render, screen, waitFor, act } from "~/tests/render"; +import { render, screen, waitFor } from "~/tests/render"; import { server } from "~/tests/server.mock"; -import { PipelinesPage } from "../list/page"; -import { loader as listLoader } from "../list/loader.server"; -import { action as listAction } from "../list/action.server"; -import { action as newPipelineAction } from "../new/action.server"; +import { PipelinesPage } from "~/components/pages/pipelines/list/page"; +import { loader as listLoader } from "~/components/pages/pipelines/list/loader.server"; +import { action as listAction } from "~/components/pages/pipelines/list/action.server"; +import { action as newPipelineAction } from "~/components/pages/pipelines/new/action.server"; import { PipelineHandlers } from "~/tests/handlers/pipelines.handlers"; import { ListHandle } from "~/tests/handles/List.handle"; -import { NewPipelinePage } from "../new/page"; +import { NewPipelinePage } from "~/components/pages/pipelines/new/page"; import { LinkHandle } from "~/tests/handles/Link.handle"; import { InputHandle } from "~/tests/handles/Input.handle"; import { pipelineFixture } from "~/tests/fixtures/pipeline.fixtures";