pagePopupLock.test.mjs
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
computePagePopupVisible,
shouldSyncPagePopup,
closePagePopupPatch,
mergeSetDataForPopupLock
} from '../services/pagePopupLock.js'
describe('pagePopupLock', () => {
it('computePagePopupVisible is false when no popup open', () => {
assert.equal(computePagePopupVisible({ customerInfoBox: false }), false)
})
it('computePagePopupVisible is true when any popup open', () => {
assert.equal(computePagePopupVisible({ customerInfoBox: true }), true)
assert.equal(
computePagePopupVisible({ minPriceApprovalPopup: { show: true } }),
true
)
})
it('shouldSyncPagePopup detects popup field updates', () => {
assert.equal(shouldSyncPagePopup({ customerInfoBox: true }), true)
assert.equal(shouldSyncPagePopup({ 'minPriceApprovalPopup.show': false }), true)
assert.equal(shouldSyncPagePopup({ orderObj: {} }), false)
assert.equal(shouldSyncPagePopup({ pagePopupVisible: true }), false)
})
it('closePagePopupPatch returns false patch for popup key', () => {
assert.deepEqual(closePagePopupPatch('customerInfoBox'), {
customerInfoBox: false
})
assert.deepEqual(closePagePopupPatch(''), {})
assert.deepEqual(closePagePopupPatch(null), {})
})
it('mergeSetDataForPopupLock applies dot-path nested popup updates', () => {
const data = {
customerInfoBox: true,
minPriceApprovalPopup: { show: true, currentPrice: '10' }
}
const merged = mergeSetDataForPopupLock(data, {
'minPriceApprovalPopup.show': false
})
assert.equal(merged.minPriceApprovalPopup.show, false)
assert.equal(merged.minPriceApprovalPopup.currentPrice, '10')
assert.equal(merged.customerInfoBox, true)
})
it('wrapper scenario: closing last popup sets pagePopupVisible false', () => {
const data = { customerInfoBox: true, goodsBox: false }
const updates = closePagePopupPatch('customerInfoBox')
assert.equal(shouldSyncPagePopup(updates), true)
const merged = mergeSetDataForPopupLock(data, updates)
assert.equal(computePagePopupVisible(merged), false)
})
it('closing subShopMerchantBox unlocks page when no other popup open', () => {
const data = { subShopMerchantBox: true, customerInfoBox: false }
const merged = mergeSetDataForPopupLock(
data,
closePagePopupPatch('subShopMerchantBox')
)
assert.equal(computePagePopupVisible(merged), false)
})
it('closing skuGoodsBox unlocks page when no other popup open', () => {
const data = { skuGoodsBox: true, goodsBox: false }
const merged = mergeSetDataForPopupLock(data, closePagePopupPatch('skuGoodsBox'))
assert.equal(computePagePopupVisible(merged), false)
})
})