Skip to content

Commit

Permalink
Update tests to reflect changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ju committed Jul 22, 2019
1 parent b059800 commit 4b7b272
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions spec/javascripts/components/cookie-banner-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ describe('Cookie banner', function () {
var element = document.querySelector('[data-module="cookie-banner"]')
new GOVUK.Modules.CookieBanner().start($(element))

var newCookieBanner = document.querySelector('.gem-c-cookie-banner')
var cookieBannerMain = document.querySelector('.gem-c-cookie-banner__wrapper')
var cookieBannerConfirmation = document.querySelector('.gem-c-cookie-banner__confirmation')

expect(newCookieBanner).toBeVisible()
expect(element).toBeVisible()
expect(cookieBannerMain).toBeVisible()
expect(cookieBannerConfirmation).not.toBeVisible()
})
Expand Down Expand Up @@ -93,11 +92,10 @@ describe('Cookie banner', function () {
var element = document.querySelector('[data-module="cookie-banner"]')
new GOVUK.Modules.CookieBanner().start($(element))

var banner = document.querySelector('[data-module="cookie-banner"]')
var link = document.querySelector('button[data-hide-cookie-banner="true"]')
link.dispatchEvent(new window.Event('click'))

expect(banner).toBeHidden()
expect(element).toBeHidden()
expect(GOVUK.setCookie).toHaveBeenCalledWith('seen_cookie_message', 'true', { days: 365 })
expect(GOVUK.getCookie('seen_cookie_message')).toBeTruthy()
})
Expand All @@ -109,8 +107,25 @@ describe('Cookie banner', function () {
var element = document.querySelector('[data-module="cookie-banner"]')
new GOVUK.Modules.CookieBanner().start($(element))

var newCookieBanner = document.querySelector('.gem-c-cookie-banner')
expect(element).not.toBeVisible()
})

describe('when rendered inside an iframe', function () {
var windowParent = window.parent
var mockWindowParent = {} // window.parent would be different than window when used inside an iframe

beforeEach(function () {
window.parent = mockWindowParent
})

afterEach(function () {
window.parent = windowParent
})

expect(newCookieBanner).not.toBeVisible()
it('should hide the cookie banner', function () {
var element = document.querySelector('[data-module="cookie-banner"]')
new GOVUK.Modules.CookieBanner().start($(element))
expect(element).toBeHidden()
})
})
})

0 comments on commit 4b7b272

Please sign in to comment.