diff --git a/cypress/e2e/motd.spec.ts b/cypress/e2e/motd.spec.ts index 085491c27..3799ab9cb 100644 --- a/cypress/e2e/motd.spec.ts +++ b/cypress/e2e/motd.spec.ts @@ -10,101 +10,28 @@ const motdMockContent = 'This is the **mock** Motd call' const motdMockHtml = 'This is the mock Motd call' describe('Motd', () => { - const mockExistingMotd = (useEtag?: boolean, content = motdMockContent) => { + it("shows, dismisses and won't show again a motd modal", () => { + localStorage.removeItem(MOTD_LOCAL_STORAGE_KEY) cy.intercept('GET', 'public/motd.md', { statusCode: 200, - headers: { [useEtag ? 'etag' : 'Last-Modified']: MOCK_LAST_MODIFIED }, - body: content + headers: { 'Last-Modified': MOCK_LAST_MODIFIED }, + body: motdMockContent }) cy.intercept('HEAD', 'public/motd.md', { statusCode: 200, - headers: { [useEtag ? 'etag' : 'Last-Modified']: MOCK_LAST_MODIFIED } + headers: { 'Last-Modified': MOCK_LAST_MODIFIED } }) - } - - beforeEach(() => { - localStorage.removeItem(MOTD_LOCAL_STORAGE_KEY) - }) - - it('shows the correct alert Motd text', () => { - mockExistingMotd() cy.visitHome() - cy.getByCypressId('motd').find('.markdown-body').should('contain.html', motdMockHtml) - }) - - it("doesn't allow html in the motd", () => { - mockExistingMotd(false, '') - cy.visitHome() - cy.getByCypressId('motd').find('.markdown-body').should('have.html', '
<iframe></iframe>
\n') - }) - - it('can be dismissed using etag', () => { - mockExistingMotd(true) - cy.visitHome() - cy.getByCypressId('motd').find('.markdown-body').should('contain.html', motdMockHtml) + cy.getByCypressId('motd-modal').find('.markdown-body').should('contain.html', motdMockHtml) cy.getByCypressId('motd-dismiss') .click() .then(() => { expect(localStorage.getItem(MOTD_LOCAL_STORAGE_KEY)).to.equal(MOCK_LAST_MODIFIED) }) - cy.getByCypressId('motd').should('not.exist') - }) - - it('can be dismissed', () => { - mockExistingMotd() - cy.visitHome() - cy.getByCypressId('motd').find('.markdown-body').should('contain.html', motdMockHtml) - cy.getByCypressId('motd-dismiss') - .click() - .then(() => { - expect(localStorage.getItem(MOTD_LOCAL_STORAGE_KEY)).to.equal(MOCK_LAST_MODIFIED) - }) - cy.getByCypressId('motd').should('not.exist') - }) - - it("won't show again after dismiss and reload", () => { - mockExistingMotd() - cy.visitHome() - cy.getByCypressId('motd').find('.markdown-body').should('contain.html', motdMockHtml) - cy.getByCypressId('motd-dismiss') - .click() - .then(() => { - expect(localStorage.getItem(MOTD_LOCAL_STORAGE_KEY)).to.equal(MOCK_LAST_MODIFIED) - }) - cy.getByCypressId('motd').should('not.exist') + cy.getByCypressId('motd-modal').should('not.exist') cy.reload() cy.get('main').should('exist') - cy.getByCypressId('motd').should('not.exist') - }) - - it('will show again after reload without dismiss', () => { - mockExistingMotd() - cy.visitHome() - cy.getByCypressId('motd').find('.markdown-body').should('contain.html', motdMockHtml) - cy.reload() - cy.get('main').should('exist') - 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').find('.markdown-body').should('contain.html', motdMockHtml) - cy.getByCypressId('motd-dismiss') - .click() - .then(() => { - expect(localStorage.getItem(MOTD_LOCAL_STORAGE_KEY)).to.equal(MOCK_LAST_MODIFIED) - }) - cy.getByCypressId('motd').should('not.exist') - cy.getByCypressId('navLinkHistory').click() - cy.get('main').should('exist') - cy.getByCypressId('motd').should('not.exist') - }) - - it("won't show if no file exists", () => { - cy.visitHome() - cy.get('main').should('exist') - cy.getByCypressId('motd').should('not.exist') + cy.getByCypressId('motd-modal').should('not.exist') }) }) diff --git a/src/components/application-loader/initializers/index.ts b/src/components/application-loader/initializers/index.ts index 6df08575d..b0331fccc 100644 --- a/src/components/application-loader/initializers/index.ts +++ b/src/components/application-loader/initializers/index.ts @@ -6,7 +6,6 @@ import { setUpI18n } from './setupI18n' import { refreshHistoryState } from '../../../redux/history/methods' -import { fetchMotd } from './fetch-motd' import { fetchAndSetUser } from '../../login-page/auth/utils' import { fetchFrontendConfig } from './fetch-frontend-config' import { loadDarkMode } from './load-dark-mode' @@ -65,10 +64,6 @@ export const createSetUpTaskList = (): InitTask[] => { name: 'Fetch user information', task: fetchUserInformation }, - { - name: 'Motd', - task: fetchMotd - }, { name: 'Load history state', task: refreshHistoryState diff --git a/src/components/common/motd-modal/__snapshots__/motd-modal.test.tsx.snap b/src/components/common/motd-modal/__snapshots__/motd-modal.test.tsx.snap new file mode 100644 index 000000000..d339358b7 --- /dev/null +++ b/src/components/common/motd-modal/__snapshots__/motd-modal.test.tsx.snap @@ -0,0 +1,88 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`motd modal doesn't allow html in the motd 1`] = ` +