Skip to content

Commit

Permalink
test slider (#12)
Browse files Browse the repository at this point in the history
* test slider

* update

* update
  • Loading branch information
swuecho authored Mar 21, 2023
1 parent 31bde6f commit 5b21a08
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 18 deletions.
28 changes: 17 additions & 11 deletions api/chat_session_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"database/sql"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -132,17 +133,22 @@ func (h *ChatSessionHandler) GetChatSessionsByUserID(w http.ResponseWriter, r *h
func (h *ChatSessionHandler) GetChatSessionByUUID(w http.ResponseWriter, r *http.Request) {
uuid := mux.Vars(r)["uuid"]
session, err := h.service.GetChatSessionByUUID(r.Context(), uuid)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
session_resp := &ChatSessionResponse{
Uuid: session.Uuid,
Topic: session.Topic,
MaxLength: session.MaxLength,
CreatedAt: session.CreatedAt,
UpdatedAt: session.UpdatedAt,
}
session_resp := &ChatSessionResponse{}
if err != nil {
if err == sql.ErrNoRows {
session_resp.Uuid = session.Uuid
session_resp.MaxLength = 10
json.NewEncoder(w).Encode(session_resp)
} else {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
}
session_resp.Uuid = session.Uuid
session_resp.Topic = session.Topic
session_resp.MaxLength = session.MaxLength
session_resp.CreatedAt = session.CreatedAt
session_resp.UpdatedAt = session.UpdatedAt
json.NewEncoder(w).Encode(session_resp)
}

Expand Down
1 change: 1 addition & 0 deletions e2e/tests/01_register.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ test('test', async ({ page }) => {
await page.getByTestId('password').locator('input').click();
await page.getByTestId('password').locator('input').fill('@WuHao5');
await page.getByTestId('signup').click();

});

38 changes: 38 additions & 0 deletions e2e/tests/07_set_session_max_len.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { test, expect } from '@playwright/test';

//generate a random email address
function randomEmail() {
const random = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
return `${random}@test.com`;
}
const test_email = randomEmail();

test('test', async ({ page }) => {
await page.goto('/');
await page.getByTestId('email').click();
await page.getByTestId('email').locator('input').fill(test_email);
await page.getByTestId('password').locator('input').click();
await page.getByTestId('password').locator('input').fill('@WuHao5');
await page.getByTestId('signup').click();

await page.waitForTimeout(1000);

await page.getByRole('contentinfo').getByRole('button').nth(2).click();
// change the value of the slider
// Find the slider element and adjust its value
const sliderRailFill = await page.$('.n-slider-rail__fill')
expect(sliderRailFill).toBeTruthy()
await sliderRailFill?.evaluate((element) => {
element.setAttribute('style', 'width: 25%;')
}
)
// sliderRailFill?.setAttribute('style', 'width: 25%;')
await page.waitForTimeout(1000);
await page.locator('.n-slider-handles').click();
await page.locator('.n-slider').click();
await page.locator('.n-slider').click();
await page.locator('.n-slider-handles').click();
await page.locator('.n-slider-handles').click();
await page.locator('.n-slider').click();

});
9 changes: 2 additions & 7 deletions web/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,8 @@ export const clearSessionChatMessages = async (sessionUuid: string) => {
}

export const getChatSessionMaxContextLength = async (sessionUuid: string) => {
try {
const response = await request.get(`/uuid/chat_sessions/${sessionUuid}`)
return response.data.maxLength
}
catch (error) {
console.error(error)
}
const response = await request.get(`/uuid/chat_sessions/${sessionUuid}`)
return response.data.maxLength
}

export const setChatSessionMaxContextLength = async (uuid: string, maxLength: number) => {
Expand Down

0 comments on commit 5b21a08

Please sign in to comment.