官术网_书友最值得收藏!

Initial selection of data

Let's start by asserting that each li element has a button element:

  1. First up, let's display a message to the user if there are no appointments scheduled for today. In the AppointmentsDayView describe block, add this test:
it('initially shows a message saying there are no appointments today', () => {
render(<AppointmentsDayView appointments={[]} />);
expect(container.textContent).toMatch(
'There are no appointments scheduled for today.'
);
});
  1. Make that pass by adding in a message at the bottom of rendered output. We don't need a check for an empty appointments array just yet; we'll need another test to triangulate to that:
return (
<div id="appointmentsDayView">
...
<p>There are no appointments scheduled for today.</p>
</div>
);
  1. If there are appointments scheduled, then we start off by showing the first one of the day. We can check for a rendered customer firstName to determine whether the right customer is shown:
it('selects the first appointment by default', () => {
render(<AppointmentsDayView appointments={appointments} />);
expect(container.textContent).toMatch('Ashley');
});
  1. Since we're looking for the customer name, we'll need to make sure that's available in the appointments array. Update it now to include the customer firstName:
  const appointments = [
{
startsAt: today.setHours(12, 0),
customer: { firstName: 'Ashley' }
},
{
startsAt: today.setHours(13, 0),
customer: { firstName: 'Jordan' }
}
];
  1. Let's make that pass by using our Appointment component. Modify the last line of the div component to read as follows:
<div id="appointmentsDayView">
// ... existing code here ...
{appointments.length === 0 ? (
<p>There are no appointments scheduled for today.</p>
) : (
<Appointment {...appointments[0]} />
)}
</div>

Now, we're ready to let the user make a selection.

主站蜘蛛池模板: 健康| 德惠市| 黄平县| 长葛市| 安岳县| 西和县| 兰州市| 萍乡市| 湘潭县| 龙江县| 怀集县| 渭南市| 静安区| 明光市| 武强县| 科技| 环江| 历史| 兴海县| 广灵县| 德庆县| 阳新县| 梁平县| 双辽市| 辛集市| 石河子市| 叶城县| 台中县| 绩溪县| 德州市| 巫溪县| 秦安县| 筠连县| 斗六市| 敦煌市| 隆安县| 德惠市| 南陵县| 兴文县| 南开区| 大名县|