<commit_before>import React from 'react';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import { IconMenu, MenuItem } from 'material-ui';
import OpenInNewIcon from 'material-ui/svg-icons/action/open-in-new';
import FlagIcon from 'material-ui/svg-icons/content/flag';
import CloseIcon from 'material-ui/svg-icons/navigation/close';
import { NotificationMenu } from '../../components/Notification/NotificationMenu';
import { getNotificationViewPath } from '../../utils/notificationUtils';

describe('NotificationMenu component', () => {
    function getProps() {
        return {
            notification: {
                id: '1',
                verb: 'run_completed',
                actor: {
                    details: {
                        job: {
                            name: 'Test',
                        },
                    },
                },
                timestamp: 1525299972716,
                unread: true,
            },
            router: {
                push: sinon.spy(),
            },
            markNotificationsAsRead: () => {},
            markNotificationsAsUnread: () => {},
            removeNotifications: () => {},
        };
    }

    function getShallowWrapper(props = getProps()) {
        return shallow(<NotificationMenu {...props} />);
    }

    it('should have the correct initial state', () => {
        const wrapper = getShallowWrapper();
        expect(wrapper.state().forceClose).toBe(false);
    });

    it('should render the basic elements', () => {
        const wrapper = getShallowWrapper();
        const instance = wrapper.instance();
        expect(wrapper.find(IconMenu)).toHaveLength(1);
        expect(wrapper.find(MenuItem)).toHaveLength(3);
        expect(wrapper.find(MenuItem).get(0).props.primaryText).toBe('View');
        expect(wrapper.find(MenuItem).get(0).props.leftIcon).toEqual(<OpenInNewIcon />);
        expect(wrapper.find(MenuItem).get(0).props.onClick).toBe(instance.handleView);
        expect(wrapper.find(MenuItem).get(1).props.primaryText).toBe('Mark As Read');
        expect(wrapper.find(MenuItem).get(1).props.leftIcon).toEqual(<FlagIcon />);
        expect(wrapper.find(MenuItem).get(1).props.onClick).toBe(instance.handleMarkAsRead);
        expect(wrapper.find(MenuItem).get(2).props.primaryText).toBe('Remove');
        expect(wrapper.find(MenuItem).get(2).props.leftIcon).toEqual(<CloseIcon />);
        expect(wrapper.find(MenuItem).get(2).props.onClick).toBe(instance.handleRemove);
    });

    it('should change second item to "Mark As Unread" when notification is read', () => {
        const props = getProps();
        props.notification = {
            ...props.notification,
            unread: false,
        };
        const wrapper = getShallowWrapper(props);
        const instance = wrapper.instance();
        expect(wrapper.find(MenuItem).get(1).props.primaryText).toBe('Mark As Unread');
        expect(wrapper.find(MenuItem).get(1).props.leftIcon).toEqual(<FlagIcon />);
        expect(wrapper.find(MenuItem).get(1).props.onClick).toBe(instance.handleMarkAsUnread);
    });

    // TODO: Menu item handlers
    it('should call onView() with notification', () => {
        const props = {<commit_msg>Remove unnecessary comment in NotificationMenu.spec.<commit_after>import React from 'react';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import { IconMenu, MenuItem } from 'material-ui';
import OpenInNewIcon from 'material-ui/svg-icons/action/open-in-new';
import FlagIcon from 'material-ui/svg-icons/content/flag';
import CloseIcon from 'material-ui/svg-icons/navigation/close';
import { NotificationMenu } from '../../components/Notification/NotificationMenu';
import { getNotificationViewPath } from '../../utils/notificationUtils';

describe('NotificationMenu component', () => {
    function getProps() {
        return {
            notification: {
                id: '1',
                verb: 'run_completed',
                actor: {
                    details: {
                        job: {
                            name: 'Test',
                        },
                    },
                },
                timestamp: 1525299972716,
                unread: true,
            },
            router: {
                push: sinon.spy(),
            },
            markNotificationsAsRead: () => {},
            markNotificationsAsUnread: () => {},
            removeNotifications: () => {},
        };
    }

    function getShallowWrapper(props = getProps()) {
        return shallow(<NotificationMenu {...props} />);
    }

    it('should have the correct initial state', () => {
        const wrapper = getShallowWrapper();
        expect(wrapper.state().forceClose).toBe(false);
    });

    it('should render the basic elements', () => {
        const wrapper = getShallowWrapper();
        const instance = wrapper.instance();
        expect(wrapper.find(IconMenu)).toHaveLength(1);
        expect(wrapper.find(MenuItem)).toHaveLength(3);
        expect(wrapper.find(MenuItem).get(0).props.primaryText).toBe('View');
        expect(wrapper.find(MenuItem).get(0).props.leftIcon).toEqual(<OpenInNewIcon />);
        expect(wrapper.find(MenuItem).get(0).props.onClick).toBe(instance.handleView);
        expect(wrapper.find(MenuItem).get(1).props.primaryText).toBe('Mark As Read');
        expect(wrapper.find(MenuItem).get(1).props.leftIcon).toEqual(<FlagIcon />);
        expect(wrapper.find(MenuItem).get(1).props.onClick).toBe(instance.handleMarkAsRead);
        expect(wrapper.find(MenuItem).get(2).props.primaryText).toBe('Remove');
        expect(wrapper.find(MenuItem).get(2).props.leftIcon).toEqual(<CloseIcon />);
        expect(wrapper.find(MenuItem).get(2).props.onClick).toBe(instance.handleRemove);
    });

    it('should change second item to "Mark As Unread" when notification is read', () => {
        const props = getProps();
        props.notification = {
            ...props.notification,
            unread: false,
        };
        const wrapper = getShallowWrapper(props);
        const instance = wrapper.instance();
        expect(wrapper.find(MenuItem).get(1).props.primaryText).toBe('Mark As Unread');
        expect(wrapper.find(MenuItem).get(1).props.leftIcon).toEqual(<FlagIcon />);
        expect(wrapper.find(MenuItem).get(1).props.onClick).toBe(instance.handleMarkAsUnread);
    });

    it('should call onView() with notification', () => {
        const props = {
{'fraction_non_alphanumeric': 0.1488508406601882, 'fraction_numerical': 0.008637976245565325, 'mean_word_length': 2.4599786552828173, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3874967', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1701, 'n_words': 286}