Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 12s
Test / e2e-test (push) Failing after 7m5s
- manage-recipes: 展开公共配方库section后再查找recipe-row - pr27-features: /#/manage改为/manage(HTML5 history模式) - performance: 搜索后接受empty-hint作为有效结果 - recipe-search: .empty-state改为.empty-hint - demo-walkthrough: 超时从15s加到20s - diary-flow: 默认tab是brand不是diary,改为验证brand内容 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
224 lines
6.7 KiB
JavaScript
224 lines
6.7 KiB
JavaScript
describe('Diary Flow', () => {
|
|
let adminToken
|
|
let authHeaders
|
|
let testDiaryId = null
|
|
|
|
before(() => {
|
|
cy.getAdminToken().then(token => {
|
|
adminToken = token
|
|
authHeaders = { Authorization: `Bearer ${token}` }
|
|
})
|
|
})
|
|
|
|
describe('API: full diary lifecycle', () => {
|
|
it('creates a diary entry via API', () => {
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/api/diary',
|
|
headers: authHeaders,
|
|
body: {
|
|
name: 'Cypress_Diary_Test_日记',
|
|
ingredients: [
|
|
{ oil: '薰衣草', drops: 3 },
|
|
{ oil: '茶树', drops: 2 }
|
|
],
|
|
note: '这是E2E测试创建的日记'
|
|
}
|
|
}).then(res => {
|
|
expect(res.status).to.be.oneOf([200, 201])
|
|
testDiaryId = res.body.id || res.body._id
|
|
expect(testDiaryId).to.exist
|
|
})
|
|
})
|
|
|
|
it('verifies diary entry appears in GET /api/diary', () => {
|
|
cy.request({
|
|
url: '/api/diary',
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
expect(res.body).to.be.an('array')
|
|
const found = res.body.find(d => d.name === 'Cypress_Diary_Test_日记')
|
|
expect(found).to.exist
|
|
expect(found.ingredients).to.have.length(2)
|
|
expect(found.note).to.eq('这是E2E测试创建的日记')
|
|
testDiaryId = found.id || found._id
|
|
})
|
|
})
|
|
|
|
it('updates the diary entry via PUT', () => {
|
|
cy.request({
|
|
url: '/api/diary',
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
const found = res.body.find(d => d.name === 'Cypress_Diary_Test_日记')
|
|
testDiaryId = found.id || found._id
|
|
cy.request({
|
|
method: 'PUT',
|
|
url: `/api/diary/${testDiaryId}`,
|
|
headers: authHeaders,
|
|
body: {
|
|
name: 'Cypress_Diary_Updated_日记',
|
|
ingredients: [
|
|
{ oil: '薰衣草', drops: 5 },
|
|
{ oil: '乳香', drops: 3 }
|
|
],
|
|
note: '已更新的日记'
|
|
}
|
|
}).then(res => {
|
|
expect(res.status).to.eq(200)
|
|
})
|
|
})
|
|
})
|
|
|
|
it('verifies the update took effect', () => {
|
|
cy.request({
|
|
url: '/api/diary',
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
const found = res.body.find(d => d.name === 'Cypress_Diary_Updated_日记')
|
|
expect(found).to.exist
|
|
expect(found.note).to.eq('已更新的日记')
|
|
expect(found.ingredients).to.have.length(2)
|
|
testDiaryId = found.id || found._id
|
|
})
|
|
})
|
|
|
|
it('adds a journal entry to the diary', () => {
|
|
cy.request({
|
|
url: '/api/diary',
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
const found = res.body.find(d => d.name === 'Cypress_Diary_Updated_日记')
|
|
testDiaryId = found.id || found._id
|
|
cy.request({
|
|
method: 'POST',
|
|
url: `/api/diary/${testDiaryId}/entries`,
|
|
headers: authHeaders,
|
|
body: {
|
|
content: 'Cypress测试日志: 使用后感觉很好'
|
|
}
|
|
}).then(res => {
|
|
expect(res.status).to.be.oneOf([200, 201])
|
|
})
|
|
})
|
|
})
|
|
|
|
it('verifies journal entry exists in diary', () => {
|
|
cy.request({
|
|
url: '/api/diary',
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
const found = res.body.find(d => d.name === 'Cypress_Diary_Updated_日记')
|
|
expect(found).to.exist
|
|
expect(found.entries).to.be.an('array')
|
|
expect(found.entries.length).to.be.gte(1)
|
|
const entry = found.entries.find(e =>
|
|
(e.text || e.content || '').includes('Cypress测试日志')
|
|
)
|
|
expect(entry).to.exist
|
|
})
|
|
})
|
|
|
|
it('deletes the journal entry', () => {
|
|
cy.request({
|
|
url: '/api/diary',
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
const found = res.body.find(d => d.name === 'Cypress_Diary_Updated_日记')
|
|
const entry = found.entries.find(e =>
|
|
(e.text || e.content || '').includes('Cypress测试日志')
|
|
)
|
|
const entryId = entry.id || entry._id
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `/api/diary/entries/${entryId}`,
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
expect(res.status).to.eq(200)
|
|
})
|
|
})
|
|
})
|
|
|
|
it('deletes the diary entry', () => {
|
|
cy.request({
|
|
url: '/api/diary',
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
const found = res.body.find(d => d.name === 'Cypress_Diary_Updated_日记')
|
|
if (found) {
|
|
const id = found.id || found._id
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `/api/diary/${id}`,
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
expect(res.status).to.eq(200)
|
|
})
|
|
}
|
|
})
|
|
})
|
|
|
|
it('verifies diary entry is gone', () => {
|
|
cy.request({
|
|
url: '/api/diary',
|
|
headers: authHeaders
|
|
}).then(res => {
|
|
const found = res.body.find(d =>
|
|
d.name === 'Cypress_Diary_Updated_日记' || d.name === 'Cypress_Diary_Test_日记'
|
|
)
|
|
expect(found).to.not.exist
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('UI: diary page renders', () => {
|
|
it('visits /mydiary and verifies page renders', () => {
|
|
cy.visit('/mydiary', {
|
|
onBeforeLoad(win) {
|
|
win.localStorage.setItem('oil_auth_token', adminToken)
|
|
}
|
|
})
|
|
cy.get('.my-diary', { timeout: 10000 }).should('exist')
|
|
// Should show sub-tabs (品牌 and 账户)
|
|
cy.get('.sub-tab').should('have.length.gte', 2)
|
|
cy.contains('我的品牌').should('be.visible')
|
|
cy.contains('我的账户').should('be.visible')
|
|
})
|
|
|
|
it('brand tab content is visible by default', () => {
|
|
cy.visit('/mydiary', {
|
|
onBeforeLoad(win) {
|
|
win.localStorage.setItem('oil_auth_token', adminToken)
|
|
}
|
|
})
|
|
cy.get('.my-diary', { timeout: 10000 }).should('exist')
|
|
// Default tab is brand; section card with upload areas should be present
|
|
cy.get('.section-card, .sub-tab.active', { timeout: 10000 }).should('exist')
|
|
cy.get('.sub-tab.active').should('contain', '我的品牌')
|
|
})
|
|
})
|
|
|
|
// Safety cleanup in case tests fail mid-way
|
|
after(() => {
|
|
cy.request({
|
|
url: '/api/diary',
|
|
headers: authHeaders,
|
|
failOnStatusCode: false
|
|
}).then(res => {
|
|
if (res.status === 200 && Array.isArray(res.body)) {
|
|
const testEntries = res.body.filter(d =>
|
|
d.name && (d.name.includes('Cypress_Diary_Test') || d.name.includes('Cypress_Diary_Updated'))
|
|
)
|
|
testEntries.forEach(entry => {
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `/api/diary/${entry.id || entry._id}`,
|
|
headers: authHeaders,
|
|
failOnStatusCode: false
|
|
})
|
|
})
|
|
}
|
|
})
|
|
})
|
|
})
|