button.test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isMP = platformInfo.startsWith('mp')
  3. const PAGE_PATH = '/pages/component/button/button'
  4. describe('Button.uvue', () => {
  5. let page
  6. beforeAll(async () => {
  7. page = await program.reLaunch(PAGE_PATH)
  8. await page.waitFor('view')
  9. })
  10. it('click', async () => {
  11. // TODO 待测试框架支持text的dispatchEvent
  12. // const btn = await page.$('.btn')
  13. // expect((await page.data())['count']).toEqual(0)
  14. // await btn.tap()
  15. // expect((await page.data())['count']).toEqual(1)
  16. // await page.setData({
  17. // disabled_boolean: true,
  18. // })
  19. // await btn.tap()
  20. // expect((await page.data())['count']).toEqual(1)
  21. // await page.setData({
  22. // disabled_boolean: false,
  23. // })
  24. // await btn.tap()
  25. // expect((await page.data())['count']).toEqual(2)
  26. })
  27. it('length', async () => {
  28. const elements = await page.$$('.btn')
  29. expect(elements.length).toBe(1)
  30. })
  31. it('text', async () => {
  32. const textBtn = await page.$('.btn')
  33. expect(await textBtn.text()).toEqual('uni-app-x')
  34. await page.setData({
  35. text: 'uni-app-x button',
  36. })
  37. expect(await textBtn.text()).toEqual('uni-app-x button')
  38. })
  39. it('type', async () => {
  40. const btn = await page.$('.btn')
  41. expect(await btn.property('type')).toBe('default')
  42. await page.setData({
  43. type_enum_current: 1,
  44. })
  45. expect(await btn.property('type')).toBe('primary')
  46. await page.setData({
  47. type_enum_current: 2,
  48. })
  49. expect(await btn.property('type')).toBe('warn')
  50. })
  51. it('size', async () => {
  52. const btn = await page.$('.btn')
  53. expect(await btn.property('size')).toBe('default')
  54. await page.setData({
  55. size_enum_current: 1,
  56. })
  57. expect(await btn.property('size')).toBe('mini')
  58. })
  59. it('plain', async () => {
  60. const btn = await page.$('.btn')
  61. // TODO
  62. const newValue1 = await btn.property('plain')
  63. expect(newValue1.toString()).toBe(false + '')
  64. await page.setData({
  65. plain_boolean: true,
  66. })
  67. const newValue2 = await btn.property('plain')
  68. expect(newValue2.toString()).toBe(true + '')
  69. })
  70. it('disabled', async () => {
  71. const btn = await page.$('.btn')
  72. // TODO
  73. const newValue1 = await btn.property('disabled')
  74. expect(newValue1.toString()).toBe(false + '')
  75. await page.setData({
  76. disabled_boolean: true,
  77. })
  78. const newValue2 = await btn.property('disabled')
  79. expect(newValue2.toString()).toBe(true + '')
  80. })
  81. it("checkUniButtonElement", async () => {
  82. if (isMP) {
  83. expect(1).toBe(1)
  84. return
  85. }
  86. const value = await page.callMethod('checkUniButtonElement')
  87. expect(value).toBe(true)
  88. })
  89. it("setbuttonEmpty", async () => {
  90. const textBtn = await page.$('.btn')
  91. await page.setData({
  92. text: '',
  93. })
  94. expect(await textBtn.text()).toEqual('')
  95. })
  96. })