basic.test.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * basic.test.ts
  3. * @author: oldj
  4. * @homepage: https://oldj.net
  5. */
  6. import assert = require('assert')
  7. import { clearData } from '@_t/_base'
  8. import {
  9. getBasicData,
  10. getHostsContent,
  11. getList,
  12. setHostsContent,
  13. setList,
  14. } from '@root/main/actions'
  15. import { swhdb } from '@root/main/data'
  16. describe('basic test', () => {
  17. beforeEach(async () => {
  18. await clearData()
  19. })
  20. it('add hosts', async () => {
  21. let basic_data = await getBasicData()
  22. assert(basic_data.list.length === 0)
  23. assert(basic_data.trashcan.length === 0)
  24. assert(basic_data.version.length === 4)
  25. await swhdb.collection.hosts.insert({ id: '1' })
  26. let items = await swhdb.collection.hosts.all()
  27. assert(items.length === 1)
  28. await setHostsContent('1', '# 111')
  29. assert(await getHostsContent('1') === '# 111')
  30. let list = await getList()
  31. assert(list.length === 0)
  32. await setList([ { id: '1' } ])
  33. list = await getList()
  34. assert(list.length === 1)
  35. assert(list[0].id === '1')
  36. })
  37. it('group hosts', async () => {
  38. await setList([
  39. { id: '1' },
  40. { id: '2' },
  41. { id: '3', type: 'group', include: [ '1', '2' ] },
  42. ])
  43. let c1 = '# 425748244153'
  44. let c2 = '# 642156457548'
  45. await setHostsContent('1', c1)
  46. await setHostsContent('2', c2)
  47. assert(await getHostsContent('1') === c1)
  48. assert(await getHostsContent('2') === c2)
  49. let c3 = await getHostsContent('3')
  50. assert(c3.indexOf(c1) > -1)
  51. assert(c3.indexOf(c2) > c3.indexOf(c1))
  52. await setList([
  53. { id: '1' },
  54. { id: '2' },
  55. {
  56. id: '4', type: 'folder', children: [
  57. { id: '5', type: 'group', include: [ '1', '2' ] },
  58. ],
  59. },
  60. ])
  61. let c5 = await getHostsContent('5')
  62. assert(c3 === c5)
  63. })
  64. })