Add markdown renderer for motd (#1840)

* Add markdown renderer for motd

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2022-02-10 09:27:09 +01:00 committed by GitHub
parent 21c12fafba
commit 57cb6f5b15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 102 additions and 55 deletions

View file

@ -6,17 +6,18 @@
const MOTD_LOCAL_STORAGE_KEY = 'motd.lastModified'
const MOCK_LAST_MODIFIED = 'mockETag'
const motdMockContent = 'This is the mock Motd call'
const motdMockContent = 'This is the **mock** Motd call'
const motdMockHtml = 'This is the <strong>mock</strong> Motd call'
describe('Motd', () => {
const mockExistingMotd = (useEtag?: boolean) => {
cy.intercept('GET', '/mock-backend/public/motd.txt', {
const mockExistingMotd = (useEtag?: boolean, content = motdMockContent) => {
cy.intercept('GET', '/mock-backend/public/motd.md', {
statusCode: 200,
headers: { [useEtag ? 'etag' : 'Last-Modified']: MOCK_LAST_MODIFIED },
body: motdMockContent
body: content
})
cy.intercept('HEAD', '/mock-backend/public/motd.txt', {
cy.intercept('HEAD', '/mock-backend/public/motd.md', {
statusCode: 200,
headers: { [useEtag ? 'etag' : 'Last-Modified']: MOCK_LAST_MODIFIED }
})
@ -29,13 +30,19 @@ describe('Motd', () => {
it('shows the correct alert Motd text', () => {
mockExistingMotd()
cy.visitHome()
cy.getByCypressId('motd').contains(motdMockContent)
cy.getByCypressId('motd').find('.markdown-body').should('contain.html', motdMockHtml)
})
it("doesn't allow html in the motd", () => {
mockExistingMotd(false, '<iframe></iframe>')
cy.visitHome()
cy.getByCypressId('motd').find('.markdown-body').should('have.html', '<p>&lt;iframe&gt;&lt;/iframe&gt;</p>\n')
})
it('can be dismissed using etag', () => {
mockExistingMotd(true)
cy.visitHome()
cy.getByCypressId('motd').contains(motdMockContent)
cy.getByCypressId('motd').find('.markdown-body').should('contain.html', motdMockHtml)
cy.getByCypressId('motd-dismiss')
.click()
.then(() => {
@ -47,7 +54,7 @@ describe('Motd', () => {
it('can be dismissed', () => {
mockExistingMotd()
cy.visitHome()
cy.getByCypressId('motd').contains(motdMockContent)
cy.getByCypressId('motd').find('.markdown-body').should('contain.html', motdMockHtml)
cy.getByCypressId('motd-dismiss')
.click()
.then(() => {
@ -59,7 +66,7 @@ describe('Motd', () => {
it("won't show again after dismiss and reload", () => {
mockExistingMotd()
cy.visitHome()
cy.getByCypressId('motd').contains(motdMockContent)
cy.getByCypressId('motd').find('.markdown-body').should('contain.html', motdMockHtml)
cy.getByCypressId('motd-dismiss')
.click()
.then(() => {
@ -74,16 +81,16 @@ describe('Motd', () => {
it('will show again after reload without dismiss', () => {
mockExistingMotd()
cy.visitHome()
cy.getByCypressId('motd').contains(motdMockContent)
cy.getByCypressId('motd').find('.markdown-body').should('contain.html', motdMockHtml)
cy.reload()
cy.get('main').should('exist')
cy.getByCypressId('motd').contains(motdMockContent)
cy.getByCypressId('motd').find('.markdown-body').should('contain.html', motdMockHtml)
})
it("won't show again after dismiss and page navigation", () => {
mockExistingMotd()
cy.visitHome()
cy.getByCypressId('motd').contains(motdMockContent)
cy.getByCypressId('motd').find('.markdown-body').should('contain.html', motdMockHtml)
cy.getByCypressId('motd-dismiss')
.click()
.then(() => {

View file

@ -68,11 +68,11 @@ Cypress.Commands.add('loadConfig', (additionalConfig?: Partial<typeof config>) =
beforeEach(() => {
cy.loadConfig()
cy.intercept('GET', '/mock-backend/public/motd.txt', {
cy.intercept('GET', '/mock-backend/public/motd.md', {
body: '404 Not Found!',
statusCode: 404
})
cy.intercept('HEAD', '/mock-backend/public/motd.txt', {
cy.intercept('HEAD', '/mock-backend/public/motd.md', {
statusCode: 404
})
})