Files
oil-formula-calculator/frontend/cypress/e2e/recipe-search.cy.js
Hera Zhao f34dd49dcb
All checks were successful
Test / unit-test (push) Successful in 6s
PR Preview / teardown-preview (pull_request) Has been skipped
Test / build-check (push) Successful in 9s
Test / e2e-test (push) Successful in 3m1s
PR Preview / test (pull_request) Successful in 6s
PR Preview / deploy-preview (pull_request) Successful in 20s
feat: 配方查询支持按精油名搜索
输入精油中文名/英文名会返回含该精油的所有配方。
中文查询 ≥2 字才匹配精油,避免「草」这样的单字噪音。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 20:47:59 +00:00

53 lines
1.9 KiB
JavaScript

describe('Recipe Search', () => {
beforeEach(() => {
cy.visit('/')
// Wait for recipes to load
cy.get('.recipe-card, .empty-hint', { timeout: 10000 }).should('exist')
})
it('displays recipe cards in the grid', () => {
cy.get('.recipe-card').should('have.length.gte', 1)
})
it('each recipe card shows name and oils', () => {
cy.get('.recipe-card').first().within(() => {
cy.get('.recipe-card-name').should('not.be.empty')
cy.get('.recipe-card-oils').should('not.be.empty')
})
})
it('filters recipes by search input', () => {
cy.get('.recipe-card').then($cards => {
const initialCount = $cards.length
cy.get('input[placeholder*="搜索"]').type('薰衣草')
// Should filter, possibly fewer results
cy.wait(500)
cy.get('.recipe-card').should('have.length.lte', initialCount)
})
})
it('searching by oil name returns recipes containing that oil', () => {
cy.get('input[placeholder*="搜索"]').type('薰衣草')
cy.wait(500)
cy.get('.search-results-section, .recipe-card', { timeout: 5000 }).should('exist')
// At least one result card should exist (any recipe using 薰衣草)
cy.get('.recipe-card').should('have.length.gte', 1)
})
it('clears search and restores all recipes', () => {
cy.get('.recipe-card', { timeout: 10000 }).should('have.length.gte', 1)
cy.get('input[placeholder*="搜索"]').type('薰衣草')
cy.wait(500)
cy.get('.recipe-card, .empty-hint', { timeout: 10000 }).should('exist')
cy.get('input[placeholder*="搜索"]').clear()
cy.wait(500)
cy.get('.recipe-card', { timeout: 10000 }).should('have.length.gte', 1)
})
it('opens recipe detail when clicking a card', () => {
cy.get('.recipe-card').first().click()
// Should show detail overlay or panel
cy.get('[class*="overlay"], [class*="detail"]', { timeout: 5000 }).should('be.visible')
})
})