{"size": 2448, "ext": "js", "max_stars_repo_path": "src/lib/__tests__/prevent-body-scroll.test.js", "max_stars_repo_name": "Shinigami92/evergreen", "max_stars_repo_stars_event_min_datetime": "2022-02-27T20:11:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T20:11:59.000Z", "max_issues_repo_path": "src/lib/__tests__/prevent-body-scroll.test.js", "max_issues_repo_name": "Shinigami92/evergreen", "max_issues_repo_issues_event_min_datetime": "2022-03-04T22:27:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T02:06:40.000Z", "max_forks_repo_path": "src/lib/__tests__/prevent-body-scroll.test.js", "max_forks_repo_name": "Auti0/evergreen", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 38.8571428571, "max_line_length": 96, "alphanum_fraction": 0.7136437908}
import preventBodyScroll from '../prevent-body-scroll'

describe('preventBodyScroll', () => {
  it('Should change body overflow to hidden on true and reset overflow on false', async () => {
    expect(document.body.style.overflow).toEqual('')
    preventBodyScroll(true)
    expect(document.body.style.overflow).toEqual('hidden')
    preventBodyScroll(false)
    expect(document.body.style.overflow).toEqual('')
  })
  it('Should be able to handle changes from other scripts changing body overflow', async () => {
    // Repeat logic of first test
    expect(document.body.style.overflow).toEqual('')
    preventBodyScroll(true)
    expect(document.body.style.overflow).toEqual('hidden')
    preventBodyScroll(false)
    expect(document.body.style.overflow).toEqual('')

    // Outside source changes overflow to hidden
    document.body.style.overflow = 'hidden'
    // Restores 'hidden' as expected
    expect(document.body.style.overflow).toEqual('hidden')
    preventBodyScroll(true)
    expect(document.body.style.overflow).toEqual('hidden')
    preventBodyScroll(false)
    expect(document.body.style.overflow).toEqual('hidden')
    // 'hidden' should no longer be apart of the history
    preventBodyScroll(false)
    expect(document.body.style.overflow).toEqual('')

    // Outside source changes overflow to ''
    document.body.style.overflow = ''
    // Repeat steps from first test to ensure it is not affected
    expect(document.body.style.overflow).toEqual('')
    preventBodyScroll(true)
    expect(document.body.style.overflow).toEqual('hidden')
    preventBodyScroll(false)
    expect(document.body.style.overflow).toEqual('')
  })
  it('Should be able to restore multiple layers of overflow values', async () => {
    document.body.style.overflow = ''
    // First overlay
    preventBodyScroll(true)
    expect(document.body.style.overflow).toEqual('hidden')
    // Second overlay
    preventBodyScroll(true)
    expect(document.body.style.overflow).toEqual('hidden')
    // Third overlay
    preventBodyScroll(true)
    expect(document.body.style.overflow).toEqual('hidden')

    // Remove third overlay
    preventBodyScroll(false)
    expect(document.body.style.overflow).toEqual('hidden')
    // Remove second overlay
    preventBodyScroll(false)
    expect(document.body.style.overflow).toEqual('hidden')
    // Remove first overlay
    preventBodyScroll(false)
    expect(document.body.style.overflow).toEqual('')
  })
})
