Fetch banner.txt from public URL instead of config (#1216)

This commit is contained in:
Tilman Vatteroth 2021-05-03 21:57:55 +02:00 committed by GitHub
parent e1d096ba1d
commit 0264e9a420
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 161 additions and 87 deletions

View file

@ -4,31 +4,77 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { banner } from '../support/config'
const BANNER_LOCAL_STORAGE_KEY = 'banner.lastModified'
const MOCK_LAST_MODIFIED = 'mockETag'
const bannerMockContent = 'This is the mock banner call'
describe('Banner', () => {
beforeEach(() => {
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')
cy.visit('/')
expect(localStorage.getItem('bannerTimeStamp')).to.be.null
localStorage.removeItem(BANNER_LOCAL_STORAGE_KEY)
expect(localStorage.getItem(BANNER_LOCAL_STORAGE_KEY)).to.be.null
})
it('shows the correct alert banner text', () => {
cy.get('.alert-primary.show')
.contains(banner.text)
cy.get('[data-cy="motd-banner"]')
.contains(bannerMockContent)
})
it('can be dismissed', () => {
cy.get('.alert-primary.show')
.contains(banner.text)
cy.get('.alert-primary.show')
.find('.fa-times')
cy.get('[data-cy="motd-banner"]')
.contains(bannerMockContent)
cy.get('button[data-cy="motd-dismiss"]')
.click()
.then(() => {
expect(localStorage.getItem('bannerTimeStamp'))
expect(localStorage.getItem(BANNER_LOCAL_STORAGE_KEY))
.to
.equal(banner.timestamp)
.equal(MOCK_LAST_MODIFIED)
})
cy.get('.alert-primary.show')
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"]')
.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')
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"]')
.should('not.exist')
})
})