Skip to content

Commit

Permalink
✨ feat(file_upload): add new file upload feature in main.py and corre…
Browse files Browse the repository at this point in the history
…sponding tests in spec.cy.ts

This commit introduces a new feature that allows users to upload files. The main.py file contains the implementation of the file upload feature, while the spec.cy.ts file contains the tests for this feature.
  • Loading branch information
alimtunc committed Aug 24, 2023
1 parent b028075 commit 8897d28
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cypress/e2e/file_upload/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import chainlit as cl


@cl.on_file_upload(accept={"text/plain": [".py"]})
async def upload_file(files: any):
for file_data in files:
await cl.Message(
content=f"`{file_data['name']}` uploaded, it contains {len(file_data['content'])} characters!"
).send()


@cl.on_chat_start
async def start():
await cl.Message(content=f"Try to upload a file").send()
31 changes: 31 additions & 0 deletions cypress/e2e/file_upload/spec.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { runTestServer } from "../../support/testUtils";

describe("Upload file", () => {
before(() => {
runTestServer();
});

it("should be able to upload and decode files", () => {
cy.get("#upload-button").should("exist");

// Upload a text file
cy.fixture("state_of_the_union.txt", "utf-8").as("txtFile");
cy.get("input[type=file]").selectFile("@txtFile", { force: true });

cy.get(".message")
.eq(1)
.should("contain", "state_of_the_union.txt uploaded, it contains");

// Expecting a python file, cpp file upload should be rejected
cy.fixture("hello.cpp", "utf-8").as("cppFile");
cy.get("input[type=file]").selectFile("@cppFile", { force: true });

// Upload a python file
cy.fixture("hello.py", "utf-8").as("pyFile");
cy.get("input[type=file]").selectFile("@pyFile", { force: true });

cy.get(".message")
.eq(2)
.should("contain", "hello.py uploaded, it contains");
});
});

0 comments on commit 8897d28

Please sign in to comment.