11import { render , screen } from '@testing-library/react' ;
2- import App from './App ' ;
3- import Demo from './Demo ' ;
2+ import Popup from './popup/Popup ' ;
3+ import { APP_INITIAL_POPUP_MSG } from './utility/constants ' ;
44
5- // test('renders learn react link', () => {
6- // render(<App />);
7- // const linkElement = screen.getByText(/learn react/i);
8- // expect(linkElement).toBeInTheDocument();
9- // });
5+ //clear local storage
6+ beforeEach ( ( ) => {
7+ localStorage . clear ( ) ;
8+ } ) ;
109
11-
12- // test('demo state test', () => {
13- // render(<Demo />);
14- // expect().toBeInTheDocument();
15- // });
10+ describe ( 'App component' , ( ) => {
11+ test ( 'renders popup with image, message, and button' , ( ) => {
12+ const mockSetShowPopup = jest . fn ( ) ; //mock function
13+
14+ // Render the Popup component
15+ render ( < Popup setShowPopup = { mockSetShowPopup } /> ) ;
16+
17+ const popupImage = screen . getByRole ( 'img' ) ;
18+ expect ( popupImage ) . toBeInTheDocument ( ) ;
19+ expect ( popupImage ) . toHaveAttribute ( 'src' , 'favicon1.ico' ) ;
20+
21+ const message = screen . getByText ( APP_INITIAL_POPUP_MSG ) ;
22+ expect ( message ) . toBeInTheDocument ( ) ;
23+
24+ //check ok button
25+ const button = screen . getByRole ( 'button' , { name :/ O K / i} ) ;
26+ expect ( button ) . toBeInTheDocument ( ) ;
27+ } ) ;
28+ } )
0 commit comments