Skip to content

Commit

Permalink
Move all tests to separate folder
Browse files Browse the repository at this point in the history
  • Loading branch information
kielbasa-elp committed Feb 24, 2024
1 parent aa6e267 commit 702b158
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 85 deletions.
26 changes: 7 additions & 19 deletions apps/web-remix/app/tests/handlers/collection.handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, IKnowledgeBaseCollection> = 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)
);
}

Expand All @@ -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 },
Expand Down Expand Up @@ -85,15 +80,8 @@ export class CollectionHandlers {
export class CollectionMemoriesHandlers {
private collectionMemories: Map<number, IKnowledgeBaseFile> = 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() {
Expand Down
22 changes: 6 additions & 16 deletions apps/web-remix/app/tests/handlers/model.handlers.ts
Original file line number Diff line number Diff line change
@@ -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<string | number, IAsyncSelectItem> = 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)
);
}

Expand All @@ -38,12 +32,8 @@ export class EmbeddingsHandlers {
export class ModelsHandlers {
private models: Map<string | number, IFixtureAsyncSelectModel> = 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() {
Expand Down
7 changes: 4 additions & 3 deletions apps/web-remix/app/tests/handlers/secret.handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { secretFixture } from "~/tests/fixtures/secrets.fixtures";
export class SecretsHandlers {
private secrets: Map<string | number, IAsyncSelectItem> = 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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" }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 702b158

Please sign in to comment.