Skip to content

Commit

Permalink
23 testfaelle ci und produktion (#32)
Browse files Browse the repository at this point in the history
* feat(test): add setupTest function for prod and ci

* feat(test): e2e use the setupTest function

* test: fixed typo

* feat(test): add login for the prod through the .env

* fix: fixed a error from user info block

* test: minor change

* fix(test): fixed logging in on the login site

* test: testing workflow on github

* fix: fixing workflow in github

* fix: added the login to ci

* test: testing the workflow in ci env

* fix: testing wait for ci

* test: testing ci by intercepting login

* feat(test): test if both ci and prod run in workflows

* test: workflow test for ci only
  • Loading branch information
bryanlewicki authored May 23, 2024
1 parent 887f0e7 commit ac69f35
Show file tree
Hide file tree
Showing 6 changed files with 4,753 additions and 3,891 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
VITE_LOGIN_URL: https://openai.ki.fh-swf.de/api/login
VITE_API_BASE_URL: https://openai.ki.fh-swf.de/api/v1
VITE_USER_URL: https://openai.ki.fh-swf.de/api/user
CYPRESS_USER_NAME: "${{ secrets.CYPRESS_USER_NAME }}"
CYPRESS_USER_PASSWORD: "${{ secrets.CYPRESS_USER_PASSWORD }}"
LANGUAGE: de
container:
image: cypress/browsers:node-20.9.0-chrome-118.0.5993.88-1-ff-118.0.2-edge-118.0.2088.46-1
Expand Down
7 changes: 7 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { defineConfig } from "cypress";
import * as dotenv from 'dotenv';

dotenv.config();

export default defineConfig({
video: true,
Expand All @@ -7,4 +10,8 @@ export default defineConfig({
// implement node event listeners here
},
},
env: {
"CYPRESS_USER_NAME": process.env.CYPRESS_USER_NAME,
"CYPRESS_USER_PASSWORD": process.env.CYPRESS_USER_PASSWORD
}
});
275 changes: 151 additions & 124 deletions cypress/e2e/e2eTest.cy.js
Original file line number Diff line number Diff line change
@@ -1,138 +1,165 @@
describe("Chat", () => {
beforeEach(() => {
cy.intercept('GET', 'https://openai.ki.fh-swf.de/api/user', { fixture: 'testUser.json' }).as('getUser');
cy.visit("http://localhost:5173/");
cy.wait('@getUser');
cy.wait(2000)
function setupTest(){
if(Cypress.env('TESTENV') === "PROD"){
describe("Login Test", () => {
beforeEach(() => {
cy.visit("https://openai.ki.fh-swf.de");
});

it("Login", () => {
cy.get("button").contains("Cluster Login").click()
cy.get('input').eq(0).type("hier_username_eintragen");
cy.get('input').eq(1).type("hier_passwort_eintragen");
cy.get("input").contains("Login Cluster").click();
// Der Code kann noch nicht einloggen, da hier keine Daten reingeschrieben werden
// Diese werden noch von einem Secret in Github kommen.
});
});
}
else{
cy.intercept('GET', "https://www.gravatar.com/8e596ec8846c54f583994b3773e0c4afc16414733b9640b29b546a41b169dcd1");
cy.intercept('GET', "https://de.gravatar.com/8e596ec8846c54f583994b3773e0c4afc16414733b9640b29b546a41b169dcd1");
cy.intercept('GET', 'https://openai.ki.fh-swf.de/api/user', { fixture: 'testUser.json' }).as('getUser');
cy.intercept('GET', "https://openai.ki.fh-swf.de/api/login")
.then((req) => {
console.log(req);
});
cy.visit("http://localhost:5173/");
cy.intercept('POST', 'https://openai.ki.fh-swf.de/api/v1/chat/completions', (req) => {
const fakeResponseData = [
{
"id": "chatcmpl-9FNy2VTHzcWXJUkKXOholEKFNV5MO",
"object": "chat.completion.chunk",
"created": 1713454078,
"model": "gpt-4-0125-preview",
"system_fingerprint": "fp_1d2ae78ab7",
"choices": [
{ "index": 0, "delta": { "role":"assistant", "content": "" }, "logprobs": null, "finish_reason": null }
]
},
{
"id": "chatcmpl-9FNy2VTHzcWXJUkKXOholEKFNV5MO",
"object": "chat.completion.chunk",
"created": 1713454078,
"model": "gpt-4-0125-preview",
"system_fingerprint": "fp_1d2ae78ab7",
"choices": [
{ "index": 0, "delta": { "content": "It" }, "logprobs": null, "finish_reason": null }
]
},
{
"id": "chatcmpl-9FNy2VTHzcWXJUkKXOholEKFNV5MO",
"object": "chat.completion.chunk",
"created": 1713454078,
"model": "gpt-4-0125-preview",
"system_fingerprint": "fp_1d2ae78ab7",
"choices": [
{ "index": 0, "delta": { "content": "looks" }, "logprobs": null, "finish_reason": "stop" }
]
},
];

cy.intercept('POST', 'https://openai.ki.fh-swf.de/api/v1/chat/completions', (req) => {
const fakeResponseData = [
{
"id": "chatcmpl-9FNy2VTHzcWXJUkKXOholEKFNV5MO",
"object": "chat.completion.chunk",
"created": 1713454078,
"model": "gpt-4-0125-preview",
"system_fingerprint": "fp_1d2ae78ab7",
"choices": [
{ "index": 0, "delta": { "role":"assistant", "content": "" }, "logprobs": null, "finish_reason": null }
]
},
{
"id": "chatcmpl-9FNy2VTHzcWXJUkKXOholEKFNV5MO",
"object": "chat.completion.chunk",
"created": 1713454078,
"model": "gpt-4-0125-preview",
"system_fingerprint": "fp_1d2ae78ab7",
"choices": [
{ "index": 0, "delta": { "content": "It" }, "logprobs": null, "finish_reason": null }
]
},
{
"id": "chatcmpl-9FNy2VTHzcWXJUkKXOholEKFNV5MO",
"object": "chat.completion.chunk",
"created": 1713454078,
"model": "gpt-4-0125-preview",
"system_fingerprint": "fp_1d2ae78ab7",
"choices": [
{ "index": 0, "delta": { "content": "looks" }, "logprobs": null, "finish_reason": "stop" }
]
},
];
fakeResponseData.push("data: [DONE]");

fakeResponseData.push("data: [DONE]");
req.reply({
statusCode: 200,
body: fakeResponseData
});
}).as("messageResponse");
cy.wait('@getUser', { timeout: 15000 });
}
}

req.reply({
statusCode: 200,
body: fakeResponseData
});
}).as("messageResponse");
describe("Chat", () => {
beforeEach(() => {
setupTest();
cy.getDataTestId("ChatTextArea").click().type("Cypress wrote this!").should("have.text", "Cypress wrote this!");
});

cy.getDataTestId("ChatTextArea").click().type("Cypress wrote this!").should("have.text", "Cypress wrote this!");
it("Sending a message with the send button", () => {
cy.getDataTestId("SendMessageBtn").click();
cy.wait("@messageResponse");
cy.getDataTestId("ChatTextArea").should("have.text", "");
cy.getDataTestId("ChatListContainer").should("be.visible");
cy.getDataTestId("ChatMessage").each((message) => {
cy.wrap(message).should("contain.text", "Cypress wrote this!");
});
});

it("Sending a message with the send button", () => {
cy.getDataTestId("SendMessageBtn").click();
cy.wait("@messageResponse");
cy.getDataTestId("ChatTextArea").should("have.text", "");
cy.getDataTestId("ChatListContainer").should("be.visible");
cy.getDataTestId("ChatMessage").each((message) => {
cy.wrap(message).should("contain.text", "Cypress wrote this!");
});
it("Sending 2 messages and checking if both are in the chat", () => {
cy.getDataTestId("SendMessageBtn").click();
//cy.getDataTestId("ChatTextArea").should("have.text", "");
cy.getDataTestId("ChatListContainer").should("be.visible");
cy.getDataTestId("ChatMessage").each((message) => {
cy.wrap(message).should("contain.text", "Cypress wrote this!");
});
cy.getDataTestId("ChatTextArea").click().type("Cypress also wrote this!");
cy.getDataTestId("ChatTextArea").should(
"have.text",
"Cypress also wrote this!"
);
cy.getDataTestId("SendMessageBtn").click();
cy.getDataTestId("ChatTextArea").should("have.text", "");
cy.getDataTestId("ChatListContainer").should("be.visible");

it("Sending 2 messages and checking if both are in the chat", () => {
cy.getDataTestId("SendMessageBtn").click();
//cy.getDataTestId("ChatTextArea").should("have.text", "");
cy.wait(2000);
cy.getDataTestId("ChatListContainer").should("be.visible");
cy.getDataTestId("ChatMessage").each((message) => {
cy.wrap(message).should("contain.text", "Cypress wrote this!");
});
cy.getDataTestId("ChatTextArea").click().type("Cypress also wrote this!");
cy.getDataTestId("ChatTextArea").should(
"have.text",
"Cypress also wrote this!"
);
cy.getDataTestId("SendMessageBtn").click();
cy.getDataTestId("ChatTextArea").should("have.text", "");
cy.getDataTestId("ChatListContainer").should("be.visible");

cy.getDataTestId("ChatListContainer").within(() => {
// Überprüfe die erste Nachricht
cy.getDataTestId("ChatMessage")
.eq(0)
.should("contain", "Cypress wrote this!");

// Überprüfe die zweite Nachricht
cy.getDataTestId("ChatMessage")
.eq(1)
.should("contain", "Cypress also wrote this!");
});
cy.getDataTestId("ChatListContainer").within(() => {
// Überprüfe die erste Nachricht
cy.getDataTestId("ChatMessage")
.eq(0)
.should("contain", "Cypress wrote this!");

// Überprüfe die zweite Nachricht
cy.getDataTestId("ChatMessage")
.eq(1)
.should("contain", "Cypress also wrote this!");
});
});

it("Sending a message with enter", () => {
cy.getDataTestId("ChatTextArea").click().type("{enter}");
//cy.getDataTestId("ChatTextArea").should("have.text", "");
cy.wait(2000);
cy.getDataTestId("ChatListContainer").should("be.visible");
cy.getDataTestId("ChatMessage").each((message) => {
cy.wrap(message).should("contain.text", "Cypress wrote this!");
});
it("Sending a message with enter", () => {
cy.getDataTestId("ChatTextArea").click().type("{enter}");
//cy.getDataTestId("ChatTextArea").should("have.text", "");
cy.wait(2000);
cy.getDataTestId("ChatListContainer").should("be.visible");
cy.getDataTestId("ChatMessage").each((message) => {
cy.wrap(message).should("contain.text", "Cypress wrote this!");
});

it("Changing the message sending to ctrl+enter and sending it", () => {
// Change message sending method to use ctrl+enter
cy.getDataTestId("BottomLeftSideBar").find("i").eq(3).click();
cy.getDataTestId("SendMessageSelect").select("COMMAND_ENTER");
cy.getDataTestId("SettingsCloseBtn").click();

// Try sending message using Enter
cy.getDataTestId("ChatTextArea").click().type("{enter}").should("have.text", "Cypress wrote this!");

// Send message using ctrl+Enter
cy.getDataTestId("ChatTextArea").click().type("{ctrl}{enter}").should("have.text", "");

// Check if the message has been sent
cy.getDataTestId("ChatMessage").each((message) => {
cy.wrap(message).should("contain.text", "Cypress wrote this!");
});
});

it("Changing the message sending to ctrl+enter and sending it", () => {
// Change message sending method to use ctrl+enter
cy.getDataTestId("BottomLeftSideBar").find("i").eq(3).click();
cy.getDataTestId("SendMessageSelect").select("COMMAND_ENTER");
cy.getDataTestId("SettingsCloseBtn").click();

// Try sending message using Enter
cy.getDataTestId("ChatTextArea").click().type("{enter}").should("have.text", "Cypress wrote this!");

// Send message using ctrl+Enter
cy.getDataTestId("ChatTextArea").click().type("{ctrl}{enter}").should("have.text", "");

// Check if the message has been sent
cy.getDataTestId("ChatMessage").each((message) => {
cy.wrap(message).should("contain.text", "Cypress wrote this!");
});
});

it("Sending a message and clearing the chatlog", () => {
// Send message
cy.getDataTestId("SendMessageBtn").click();
cy.getDataTestId("ChatListContainer").find('[data-testid="ChatMessage"]').should('exist');

// Clear chatlog
cy.getDataTestId("ClearMessageBtn").click();
cy.getDataTestId("ChatListContainer").should('not.exist');

// Check if message can be sent again
const message = "Cypress wrote this!";
cy.getDataTestId("ChatTextArea").type(message).should("have.value", message);
cy.getDataTestId("SendMessageBtn").click();
cy.getDataTestId("ChatListContainer").should('exist');
});

it.only("Sending a message and clearing the chatlog", () => {
cy.intercept('POST', "https://openai.ki.fh-swf.de/api/v1/chat/completions", { fixture: 'testCompletion.json' }).as('getCompletion');
// Send message
const message = "Cypress wrote this!";
cy.getDataTestId("ChatTextArea").clear().type(message).should("have.value", message);
cy.getDataTestId("SendMessageBtn").click();
cy.wait('@getCompletion');
cy.getDataTestId("ChatListContainer").find('[data-testid="ChatMessage"]').should('exist');

// TODO: This triggers an exception in the client code
// Clear chatlog
//cy.getDataTestId("ClearChatBtn").click();
//cy.getDataTestId("ChatListContainer").should('not.exist');

// Check if message can be sent again
cy.getDataTestId("ChatTextArea").clear().type(message).should("have.value", message);
cy.getDataTestId("SendMessageBtn").click();
cy.getDataTestId("ChatListContainer").should('exist');
});


});
Loading

0 comments on commit ac69f35

Please sign in to comment.