{"size": 1649, "ext": "js", "max_stars_repo_path": "src/Components/PresentationalComponents/Filters/PrimaryToolbarFilters/PublishDateFilter.test.js", "max_stars_repo_name": "bastilian/vulnerability-ui", "max_stars_repo_stars_event_min_datetime": "2018-07-10T17:03:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-23T03:41:35.000Z", "max_issues_repo_path": "src/Components/PresentationalComponents/Filters/PrimaryToolbarFilters/PublishDateFilter.test.js", "max_issues_repo_name": "bastilian/vulnerability-ui", "max_issues_repo_issues_event_min_datetime": "2018-07-10T19:46:51.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:04:21.000Z", "max_forks_repo_path": "src/Components/PresentationalComponents/Filters/PrimaryToolbarFilters/PublishDateFilter.test.js", "max_forks_repo_name": "bastilian/vulnerability-ui", "max_forks_repo_forks_event_min_datetime": "2018-07-09T21:16:01.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T16:53:54.000Z"}
{"max_stars_count": 9, "max_issues_count": 1492, "max_forks_count": 31, "avg_line_length": 33.6530612245, "max_line_length": 78, "alphanum_fraction": 0.587628866}
import publishDateFilter from './PublishDateFilter'

describe('PublishDateFilter', () => {
    const applyMock = jest.fn();

    it('Should render the date option items', () => {
        const options = [ 
            { label: 'All', value: 'all' },
            { label: 'Last 7 days', value: 'last7' },
            { label: 'Last 30 days', value: 'last30' },
            { label: 'Last 90 days', value: 'last90' },
            { label: 'Last year', value: 'lastYear' },
            { label: 'More than 1 year ago', value: 'MoreThanYear' } 
        ]
  
        const comp = publishDateFilter(applyMock, '')
        expect(comp.filterValues.items).toStrictEqual(options)
    })

    it('Should use default currentValue 0', () => {
        let comp = publishDateFilter(applyMock, '')
        expect(comp.filterValues.value).toBe('0')

        comp = publishDateFilter(applyMock, undefined)
        expect(comp.filterValues.value).toBe('0')

        comp = publishDateFilter(applyMock, '5')
        expect(comp.filterValues.value).toBe('0')

    })

    it('Should use the passed currentValue ', () => {
        let currentFilter = { publish_date: 'last7' }
        let comp = publishDateFilter(applyMock, currentFilter)
        expect(comp.filterValues.value).toBe('last7')
    })

    it('Should call apply with params', () => {
        let comp = publishDateFilter(applyMock, '1')
        comp.filterValues.onChange('event', 'last7')
        expect(applyMock).toBeCalledWith({"page": 1, "publish_date": "last7"})

        comp.filterValues.onChange('event', '')
        expect(applyMock).toBeCalledWith({"page": 1, "publish_date": ""})

    })

})
