label.test.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isWeb = platformInfo.startsWith('web')
  3. const isHarmony = platformInfo.startsWith('harmony')
  4. let page;
  5. describe('label.uvue', () => {
  6. if (!isWeb && !isHarmony) {
  7. it('app', () => {
  8. expect(1).toBe(1)
  9. })
  10. return
  11. }
  12. beforeAll(async () => {
  13. page = await program.reLaunch('/pages/component/label/label')
  14. await page.waitFor('view');
  15. });
  16. afterEach(async() => {
  17. await page.setData({
  18. checkboxValue: [],
  19. radioValue:''
  20. })
  21. });
  22. function getData(key = '') {
  23. return new Promise(async (resolve, reject) => {
  24. const data = await page.data()
  25. resolve(key ? data[key] : data)
  26. })
  27. }
  28. it('表单组件在label内', async () => {
  29. expect(await getData('checkboxValue')).toEqual([])
  30. const checkboxItems = await page.$$('.checkboxItemsTest')
  31. await checkboxItems[0].tap()
  32. expect(await getData('checkboxValue')).toEqual(['USA', 'CHN'])
  33. })
  34. it('label用for标识表单组件', async () => {
  35. const radioItems = await page.$$('.label-2-text')
  36. await radioItems[0].tap()
  37. expect(await getData('radioValue')).toEqual('USA')
  38. await radioItems[1].tap()
  39. expect(await getData('radioValue')).toEqual('CHN')
  40. })
  41. it('label内有多个时选中第一个', async () => {
  42. const labelText = await page.$('.uni-center')
  43. await labelText.tap()
  44. expect(await getData('checkboxForValue')).toEqual(['for1'])
  45. })
  46. })