fixednav.spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { config, DOMWrapper, mount } from '@vue/test-utils';
  2. import FixedNav from '../index.vue';
  3. import { nextTick } from 'vue';
  4. import NutIcon from '../../icon/index.vue';
  5. import nutOverlay from '../../overlay/index.vue';
  6. beforeAll(() => {
  7. config.global.components = {
  8. NutIcon,
  9. nutOverlay
  10. };
  11. });
  12. afterAll(() => {
  13. config.global.components = {};
  14. });
  15. describe('FixedNav', () => {
  16. test('base nut-fixednav', () => {
  17. const wrapper = mount(FixedNav);
  18. const rate = wrapper.find('.nut-fixednav');
  19. expect(rate.exists()).toBe(true);
  20. });
  21. test('should be displayed after setting the visible', () => {
  22. const wrapper = mount(FixedNav, {
  23. props: {
  24. visible: true,
  25. overlay: true
  26. }
  27. });
  28. const _html: DOMWrapper<Element> = wrapper.find('.nut-fixednav__list');
  29. expect(_html.exists()).toBe(true);
  30. });
  31. test('should be displayed after setting the type', () => {
  32. const wrapper = mount(FixedNav, {
  33. props: {
  34. type: 'left'
  35. }
  36. });
  37. const _html: DOMWrapper<Element> = wrapper.find('.left');
  38. expect(_html.exists()).toBe(true);
  39. });
  40. test('should be displayed after setting the un-active-text', async () => {
  41. const wrapper = mount(FixedNav, {
  42. props: {
  43. 'un-active-text': '展开',
  44. 'active-text': '收起'
  45. }
  46. });
  47. const _html1 = wrapper.find('.nut-overlay');
  48. expect(_html1.exists()).toBe(true);
  49. const _html = wrapper.find('.nut-fixednav__btn');
  50. expect(_html.html()).toContain('展开');
  51. wrapper.find('.nut-fixednav__btn').trigger('click');
  52. await nextTick();
  53. // expect(_html.html()).toContain('收起');
  54. });
  55. test('should be displayed after setting the position', () => {
  56. const wrapper = mount(FixedNav, {
  57. props: {
  58. position: { top: '210px' }
  59. }
  60. });
  61. const _html = wrapper.find('.nut-fixednav');
  62. expect((_html.element as HTMLElement).style.top).toBe('210px');
  63. });
  64. });