uiSmokeHelpers.test.mjs 1.16 KB
import assert from 'node:assert/strict'
import test from 'node:test'
import {
  findExactIndex,
  waitForListData
} from './uiSmokeHelpers.mjs'

test('IT-OL-UI-005: exact context match ignores partial names', () => {
  const items = [
    { merchantName: '流程测试园区门店-备选' },
    { merchantName: '流程测试园区门店' }
  ]

  assert.equal(
    findExactIndex(items, 'merchantName', '流程测试园区门店', 'park'),
    1
  )
})

test('IT-OL-UI-006: duplicate exact context is rejected', () => {
  assert.throws(
    () =>
      findExactIndex(
        [{ sceneName: '精品升级' }, { sceneName: '精品升级' }],
        'sceneName',
        '精品升级',
        'scene'
      ),
    /count=2/
  )
})

test('IT-OL-UI-007: page list polling returns once data is available', async () => {
  let reads = 0
  const page = {
    async data(field) {
      assert.equal(field, 'sceneList')
      reads += 1
      return reads === 1 ? [] : [{ sceneName: '精品升级' }]
    }
  }

  const result = await waitForListData(page, 'sceneList', {
    timeoutMs: 100,
    intervalMs: 1
  })

  assert.equal(reads, 2)
  assert.equal(result[0].sceneName, '精品升级')
})