forked from ninasaul/chat-gpt-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
23 testfaelle ci und produktion (#32)
* 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
1 parent
887f0e7
commit ac69f35
Showing
6 changed files
with
4,753 additions
and
3,891 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
|
||
|
||
}); |
Oops, something went wrong.