2020-11-22 15:50:07 -05:00
|
|
|
/*
|
2021-01-06 15:37:59 -05:00
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
2020-11-22 15:50:07 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2021-05-03 15:57:55 -04:00
|
|
|
const BANNER_LOCAL_STORAGE_KEY = 'banner.lastModified'
|
|
|
|
const MOCK_LAST_MODIFIED = 'mockETag'
|
|
|
|
const bannerMockContent = 'This is the mock banner call'
|
2020-07-16 05:22:53 -04:00
|
|
|
|
|
|
|
describe('Banner', () => {
|
|
|
|
beforeEach(() => {
|
2021-05-03 15:57:55 -04:00
|
|
|
cy.intercept({
|
|
|
|
method: 'GET',
|
|
|
|
url: '/mock-backend/public/banner.txt'
|
|
|
|
}, {
|
|
|
|
statusCode: 200,
|
|
|
|
headers: { 'Last-Modified': MOCK_LAST_MODIFIED },
|
|
|
|
body: bannerMockContent
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.intercept({
|
|
|
|
method: 'HEAD',
|
|
|
|
url: '/mock-backend/public/banner.txt'
|
|
|
|
}, {
|
|
|
|
statusCode: 200,
|
|
|
|
headers: { 'Last-Modified': MOCK_LAST_MODIFIED }
|
|
|
|
})
|
|
|
|
.as('headBanner')
|
|
|
|
|
2020-07-16 05:22:53 -04:00
|
|
|
cy.visit('/')
|
2021-05-03 15:57:55 -04:00
|
|
|
localStorage.removeItem(BANNER_LOCAL_STORAGE_KEY)
|
|
|
|
expect(localStorage.getItem(BANNER_LOCAL_STORAGE_KEY)).to.be.null
|
2020-07-16 05:22:53 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shows the correct alert banner text', () => {
|
2021-05-03 15:57:55 -04:00
|
|
|
cy.get('[data-cy="motd-banner"]')
|
|
|
|
.contains(bannerMockContent)
|
2020-07-16 05:22:53 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('can be dismissed', () => {
|
2021-05-03 15:57:55 -04:00
|
|
|
cy.get('[data-cy="motd-banner"]')
|
|
|
|
.contains(bannerMockContent)
|
|
|
|
cy.get('button[data-cy="motd-dismiss"]')
|
|
|
|
.click()
|
|
|
|
.then(() => {
|
|
|
|
expect(localStorage.getItem(BANNER_LOCAL_STORAGE_KEY))
|
|
|
|
.to
|
|
|
|
.equal(MOCK_LAST_MODIFIED)
|
|
|
|
})
|
|
|
|
cy.get('[data-cy="no-motd-banner"]')
|
|
|
|
.should('exist')
|
|
|
|
cy.get('[data-cy="motd-banner"]')
|
|
|
|
.should('not.exist')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('won\'t show again on reload', () => {
|
|
|
|
cy.get('[data-cy="motd-banner"]')
|
|
|
|
.contains(bannerMockContent)
|
|
|
|
cy.get('button[data-cy="motd-dismiss"]')
|
2020-07-16 05:22:53 -04:00
|
|
|
.click()
|
|
|
|
.then(() => {
|
2021-05-03 15:57:55 -04:00
|
|
|
expect(localStorage.getItem(BANNER_LOCAL_STORAGE_KEY))
|
2021-02-03 16:13:04 -05:00
|
|
|
.to
|
2021-05-03 15:57:55 -04:00
|
|
|
.equal(MOCK_LAST_MODIFIED)
|
2020-07-16 05:22:53 -04:00
|
|
|
})
|
2021-05-03 15:57:55 -04:00
|
|
|
cy.get('[data-cy="no-motd-banner"]')
|
|
|
|
.should('exist')
|
|
|
|
cy.get('[data-cy="motd-banner"]')
|
|
|
|
.should('not.exist')
|
|
|
|
cy.reload()
|
|
|
|
cy.get('main')
|
|
|
|
.should('exist')
|
|
|
|
cy.wait('@headBanner')
|
|
|
|
cy.get('[data-cy="no-motd-banner"]')
|
|
|
|
.should('exist')
|
|
|
|
cy.get('[data-cy="motd-banner"]')
|
2020-07-16 05:22:53 -04:00
|
|
|
.should('not.exist')
|
|
|
|
})
|
|
|
|
})
|