Fullcalendar.io 显示更多链接(dayMaxEvents) 测试在 vue 测试库中不起作用

发布于 2025-01-14 18:46:43 字数 1893 浏览 2 评论 0原文

我使用完整日历 v5 和testing-library/vue 进行测试。我尝试测试在弹出窗口中显示更多事件。但是,尽管我提供的事件超过 4 个,但显示更多链接并未加载到日历上,并且 moreLinkDidMount 函数永远无法工作。 当我将 daymaxEvents 属性设置为零时,它会显示链接并且 moreLinkDidMount 函数可以工作。我缺少什么?

这是我的代码;

import FullCalendar from '@fullcalendar/vue';
import dayGridPlugin from '@fullcalendar/daygrid';
import trLocale from '@fullcalendar/core/locales/tr';

<FullCalendar :options="calendarOptions" />

  data () {
    return {
      calendarOptions: {
        eventDisplay: 'block',
        headerToolbar: false,
        dayHeaders: false,
        locales: [trLocale],
        plugins: [ dayGridPlugin ],
        initialView: 'dayGridMonth',
        weekends: true,
        dayMaxEvents: 4,
        dayPopoverFormat: { day: 'numeric' },
        displayEventTime: false,
        events: [],  
        moreLinkDidMount: (arg) => {
         console.log(arg);
        },
      },
    };   
  },
    
async mounted () {
   await this.getAllEvents();
},
    
async getAllEvents () {
  const startDate = this.currentStartDate;
  const endDate = this.currentEndDate;
  await this.getEvents({ startDate, endDate }); // Data that comes from API are added in 
  calendar options events
},

这是我的测试代码;

import { screen, waitFor,render } from '@testing-library/vue';
import FullCalendar from '@/views/Calendar/FullCalendar';
import { getMockEventItem } from '../../../mocks/eventItem.mock';

it('should show more link when event count is bigger than 4', async () => {
  // given
  const events = [
    getMockEventItem(),
    getMockEventItem(),
    getMockEventItem(),
    getMockEventItem(),
    getMockEventItem(),
   ];
    
  calendarService.getEvents.mockResolvedValue(events);
  render(FullCalendar);

  await waitFor(() => {
    expect(document.querySelector('.fc-daygrid-more-link.fc-more-link')).toBeInTheDocument();
  });
});

I am using full calendar v5 and testing-library/vue for tests. I try to test show more events in the popover. But although I am giving events more than 4 the show more link isn't being loaded on the calendar and it never works the moreLinkDidMount function.
When I set the daymaxEvents prop as zero it shows the link and the moreLinkDidMount function works. What am I missing?

Here are my codes;

import FullCalendar from '@fullcalendar/vue';
import dayGridPlugin from '@fullcalendar/daygrid';
import trLocale from '@fullcalendar/core/locales/tr';

<FullCalendar :options="calendarOptions" />

  data () {
    return {
      calendarOptions: {
        eventDisplay: 'block',
        headerToolbar: false,
        dayHeaders: false,
        locales: [trLocale],
        plugins: [ dayGridPlugin ],
        initialView: 'dayGridMonth',
        weekends: true,
        dayMaxEvents: 4,
        dayPopoverFormat: { day: 'numeric' },
        displayEventTime: false,
        events: [],  
        moreLinkDidMount: (arg) => {
         console.log(arg);
        },
      },
    };   
  },
    
async mounted () {
   await this.getAllEvents();
},
    
async getAllEvents () {
  const startDate = this.currentStartDate;
  const endDate = this.currentEndDate;
  await this.getEvents({ startDate, endDate }); // Data that comes from API are added in 
  calendar options events
},

Here are my test codes;

import { screen, waitFor,render } from '@testing-library/vue';
import FullCalendar from '@/views/Calendar/FullCalendar';
import { getMockEventItem } from '../../../mocks/eventItem.mock';

it('should show more link when event count is bigger than 4', async () => {
  // given
  const events = [
    getMockEventItem(),
    getMockEventItem(),
    getMockEventItem(),
    getMockEventItem(),
    getMockEventItem(),
   ];
    
  calendarService.getEvents.mockResolvedValue(events);
  render(FullCalendar);

  await waitFor(() => {
    expect(document.querySelector('.fc-daygrid-more-link.fc-more-link')).toBeInTheDocument();
  });
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文