Coding task · JavaScript and React course · Module 13: Testing React
Practice: Alert System
role="alert" is an urgent message: a screen reader interrupts what it is reading and announces it at once. role="status" is a polite message, announced at the next pause. React Testing Library finds them with getByRole('alert') and getAllByRole('status'), and the close button inside a specific notification with within(notification).getByRole('button'). A button with only the × sign needs aria-label to have a meaningful name.
Task
Finish the AlertSystem mission notification centre. The buttons add notifications of three types (info, warning, danger), each with a close button, and Clear all removes the whole list. ___BLANK1___: a new notification goes to the end of the list in a new array (the earlier ones stay). ___BLANK2___: removeAlert(id) returns a new array without the notification with the given id, and the others stay, including those of the same type. ___BLANK3___: an alarm (type danger) has the alert role, and info and warning have the status role. The test clicks the buttons, counts the elements with the alert and status roles and closes a chosen notification with its button.