fix: 拖选文字时弹窗不再误关闭 #27

Merged
hera merged 16 commits from fix/next-batch into main 2026-04-12 14:11:46 +00:00
3 changed files with 166 additions and 1 deletions
Showing only changes of commit e0ee1cba8c - Show all commits

View File

@@ -51,7 +51,7 @@ _KEYWORDS = {
'预防': 'Prevention', '改善': 'Improve',
'祛湿': 'Dampness Relief', '驱寒': 'Warming',
'化痰': 'Phlegm Relief', '健脾': 'Spleen Wellness',
'化湿': 'Dampness Clear',
'化湿': 'Dampness Clear', '缓解': 'Relief',
# Beauty
'美容': 'Beauty', '美发': 'Hair Care', '美体': 'Body Care',

View File

@@ -175,6 +175,85 @@ describe('PR27 Feature Tests', () => {
})
})
// -------------------------------------------------------------------------
// API: rename recipe auto-retranslates en_name
// -------------------------------------------------------------------------
describe('API: rename recipe retranslates en_name', () => {
let recipeId
after(() => {
if (recipeId) {
cy.request({ method: 'DELETE', url: `/api/recipes/${recipeId}`, headers: authHeaders, failOnStatusCode: false })
}
})
it('creates recipe then renames it, en_name auto-updates', () => {
cy.request({
method: 'POST', url: '/api/recipes', headers: authHeaders,
body: { name: '头痛', ingredients: [{ oil_name: '薰衣草', drops: 3 }], tags: [] }
}).then(res => {
recipeId = res.body.id
// Verify initial en_name
cy.request('/api/recipes').then(list => {
const r = list.body.find(x => x.id === recipeId)
expect(r.en_name).to.include('Headache')
})
// Rename to 肩颈按摩
cy.request({
method: 'PUT', url: `/api/recipes/${recipeId}`, headers: authHeaders,
body: { name: '肩颈按摩' }
}).then(() => {
cy.request('/api/recipes').then(list => {
const r = list.body.find(x => x.id === recipeId)
expect(r.en_name).to.include('Neck')
expect(r.en_name).to.include('Massage')
})
})
})
})
})
// -------------------------------------------------------------------------
// API: delete user skips duplicate diary by ingredient content
// -------------------------------------------------------------------------
describe('API: delete user skips duplicate diary', () => {
const DUP_USER = 'cypress_pr27_dup'
it('creates user with duplicate diary, deletes, verifies skip', () => {
// Create user
cy.request({
method: 'POST', url: '/api/users', headers: authHeaders,
body: { username: DUP_USER, display_name: 'Dup Test', role: 'viewer' }
}).then(res => {
const userId = res.body.id
const userToken = res.body.token
const userAuth = { Authorization: `Bearer ${userToken}` }
// Get a public recipe's ingredients to create a duplicate
cy.request({ url: '/api/recipes', headers: authHeaders }).then(listRes => {
const pub = listRes.body[0]
const dupIngs = pub.ingredients.map(i => ({ oil: i.oil_name, drops: i.drops }))
// Add diary with same ingredients as public recipe (different name)
cy.request({
method: 'POST', url: '/api/diary', headers: userAuth,
body: { name: '我的重复方', ingredients: dupIngs, note: '' }
}).then(() => {
// Delete user
cy.request({ method: 'DELETE', url: `/api/users/${userId}`, headers: authHeaders }).then(delRes => {
expect(delRes.body.ok).to.eq(true)
// Verify duplicate was NOT transferred
cy.request({ url: '/api/diary', headers: authHeaders }).then(diaryRes => {
const transferred = diaryRes.body.find(d => d.name && d.name.includes('我的重复方'))
expect(transferred).to.not.exist
})
})
})
})
})
})
})
// -------------------------------------------------------------------------
// UI: 管理配方 login prompt when not logged in
// -------------------------------------------------------------------------

View File

@@ -1,4 +1,5 @@
import { describe, it, expect } from 'vitest'
import { recipeNameEn } from '../composables/useOilTranslation'
// ---------------------------------------------------------------------------
// EDITOR_ONLY_TAGS includes '已下架'
@@ -84,3 +85,88 @@ describe('已下架 tag filtering', () => {
expect(filterDelisted(all)).toHaveLength(0)
})
})
// ---------------------------------------------------------------------------
// recipeNameEn — front-end keyword translation
// ---------------------------------------------------------------------------
describe('recipeNameEn', () => {
it('translates 酸痛包 → Pain Relief Blend', () => {
expect(recipeNameEn('酸痛包')).toBe('Pain Relief Blend')
})
it('translates 助眠配方 → Sleep Aid Blend', () => {
expect(recipeNameEn('助眠配方')).toBe('Sleep Aid Blend')
})
it('translates 头痛 → Headache', () => {
expect(recipeNameEn('头痛')).toBe('Headache')
})
it('translates 肩颈按摩 → Neck & Shoulder Massage', () => {
expect(recipeNameEn('肩颈按摩')).toBe('Neck & Shoulder Massage')
})
it('translates 湿疹舒缓 → Eczema Soothing', () => {
expect(recipeNameEn('湿疹舒缓')).toBe('Eczema Soothing')
})
it('translates 淋巴排毒 → Lymph Detox', () => {
expect(recipeNameEn('淋巴排毒')).toBe('Lymph Detox')
})
it('translates 灰指甲 → Nail Fungus', () => {
expect(recipeNameEn('灰指甲')).toBe('Nail Fungus')
})
it('translates 缓解焦虑 → Relief Anxiety', () => {
expect(recipeNameEn('缓解焦虑')).toBe('Relief Anxiety')
})
it('returns original name for unknown text', () => {
expect(recipeNameEn('XYZXYZ')).toBe('XYZXYZ')
})
it('returns empty/null for empty/null input', () => {
expect(recipeNameEn('')).toBe('')
expect(recipeNameEn(null)).toBeNull()
})
it('does not duplicate keywords', () => {
// 酸痛 maps to Pain Relief; should not appear twice
const result = recipeNameEn('酸痛酸痛')
expect(result).toBe('Pain Relief')
})
})
// ---------------------------------------------------------------------------
// Duplicate oil prevention logic
// ---------------------------------------------------------------------------
describe('duplicate oil prevention', () => {
it('detects duplicate oil in ingredient list', () => {
const ings = [
{ oil: '薰衣草', drops: 3 },
{ oil: '茶树', drops: 2 },
]
const newOil = '薰衣草'
const isDup = ings.some(i => i.oil === newOil)
expect(isDup).toBe(true)
})
it('allows non-duplicate oil', () => {
const ings = [
{ oil: '薰衣草', drops: 3 },
{ oil: '茶树', drops: 2 },
]
const newOil = '乳香'
const isDup = ings.some(i => i.oil === newOil)
expect(isDup).toBe(false)
})
it('allows same oil for the same row (editing current)', () => {
const ing = { oil: '薰衣草', drops: 3 }
const ings = [ing, { oil: '茶树', drops: 2 }]
// When selecting for the same row, exclude self
const isDup = ings.some(i => i !== ing && i.oil === '薰衣草')
expect(isDup).toBe(false)
})
})