2021-10-09 13:09:29 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
const MOTD_LOCAL_STORAGE_KEY = 'motd.lastModified'
|
|
|
|
const MOCK_LAST_MODIFIED = 'mockETag'
|
|
|
|
const motdMockContent = 'This is the mock Motd call'
|
|
|
|
|
|
|
|
describe('Motd', () => {
|
2021-12-31 03:30:12 -05:00
|
|
|
const mockExistingMotd = (useEtag?: boolean) => {
|
2021-10-09 13:09:29 -04:00
|
|
|
cy.intercept('GET', '/mock-backend/public/motd.txt', {
|
|
|
|
statusCode: 200,
|
2021-12-31 03:30:12 -05:00
|
|
|
headers: { [useEtag ? 'etag' : 'Last-Modified']: MOCK_LAST_MODIFIED },
|
2021-10-09 13:09:29 -04:00
|
|
|
body: motdMockContent
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.intercept('HEAD', '/mock-backend/public/motd.txt', {
|
|
|
|
statusCode: 200,
|
2021-12-31 03:30:12 -05:00
|
|
|
headers: { [useEtag ? 'etag' : 'Last-Modified']: MOCK_LAST_MODIFIED }
|
2021-10-09 13:09:29 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localStorage.removeItem(MOTD_LOCAL_STORAGE_KEY)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows the correct alert Motd text', () => {
|
|
|
|
mockExistingMotd()
|
|
|
|
cy.visit('/')
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('motd').contains(motdMockContent)
|
2021-10-09 13:09:29 -04:00
|
|
|
})
|
|
|
|
|
2021-12-31 03:30:12 -05:00
|
|
|
it('can be dismissed using etag', () => {
|
|
|
|
mockExistingMotd(true)
|
|
|
|
cy.visit('/')
|
|
|
|
cy.getByCypressId('motd').contains(motdMockContent)
|
|
|
|
cy.getByCypressId('motd-dismiss')
|
|
|
|
.click()
|
|
|
|
.then(() => {
|
|
|
|
expect(localStorage.getItem(MOTD_LOCAL_STORAGE_KEY)).to.equal(MOCK_LAST_MODIFIED)
|
|
|
|
})
|
|
|
|
cy.getByCypressId('motd').should('not.exist')
|
|
|
|
})
|
|
|
|
|
2021-10-09 13:09:29 -04:00
|
|
|
it('can be dismissed', () => {
|
|
|
|
mockExistingMotd()
|
|
|
|
cy.visit('/')
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('motd').contains(motdMockContent)
|
|
|
|
cy.getByCypressId('motd-dismiss')
|
2021-10-09 13:09:29 -04:00
|
|
|
.click()
|
|
|
|
.then(() => {
|
|
|
|
expect(localStorage.getItem(MOTD_LOCAL_STORAGE_KEY)).to.equal(MOCK_LAST_MODIFIED)
|
|
|
|
})
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('motd').should('not.exist')
|
2021-10-09 13:09:29 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it("won't show again after dismiss and reload", () => {
|
|
|
|
mockExistingMotd()
|
|
|
|
cy.visit('/')
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('motd').contains(motdMockContent)
|
|
|
|
cy.getByCypressId('motd-dismiss')
|
2021-10-09 13:09:29 -04:00
|
|
|
.click()
|
|
|
|
.then(() => {
|
|
|
|
expect(localStorage.getItem(MOTD_LOCAL_STORAGE_KEY)).to.equal(MOCK_LAST_MODIFIED)
|
|
|
|
})
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('motd').should('not.exist')
|
2021-10-09 13:09:29 -04:00
|
|
|
cy.reload()
|
|
|
|
cy.get('main').should('exist')
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('motd').should('not.exist')
|
2021-10-09 13:09:29 -04:00
|
|
|
})
|
|
|
|
|
2021-11-19 12:04:04 -05:00
|
|
|
it('will show again after reload without dismiss', () => {
|
2021-10-09 13:09:29 -04:00
|
|
|
mockExistingMotd()
|
|
|
|
cy.visit('/')
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('motd').contains(motdMockContent)
|
2021-10-09 13:09:29 -04:00
|
|
|
cy.reload()
|
|
|
|
cy.get('main').should('exist')
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('motd').contains(motdMockContent)
|
2021-10-09 13:09:29 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it("won't show again after dismiss and page navigation", () => {
|
|
|
|
mockExistingMotd()
|
|
|
|
cy.visit('/')
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('motd').contains(motdMockContent)
|
|
|
|
cy.getByCypressId('motd-dismiss')
|
2021-10-09 13:09:29 -04:00
|
|
|
.click()
|
|
|
|
.then(() => {
|
|
|
|
expect(localStorage.getItem(MOTD_LOCAL_STORAGE_KEY)).to.equal(MOCK_LAST_MODIFIED)
|
|
|
|
})
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('motd').should('not.exist')
|
|
|
|
cy.getByCypressId('navLinkHistory').click()
|
2021-10-09 13:09:29 -04:00
|
|
|
cy.get('main').should('exist')
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('motd').should('not.exist')
|
2021-10-09 13:09:29 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it("won't show if no file exists", () => {
|
|
|
|
cy.visit('/')
|
|
|
|
cy.get('main').should('exist')
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('motd').should('not.exist')
|
2021-10-09 13:09:29 -04:00
|
|
|
})
|
|
|
|
})
|