diff --git a/src/components/UpdateMessage.test.tsx b/src/components/UpdateMessage.test.tsx new file mode 100644 index 0000000..a2892d6 --- /dev/null +++ b/src/components/UpdateMessage.test.tsx @@ -0,0 +1,45 @@ +import React from 'react' +import { render, screen } from '@testing-library/react' +import { UpdateMessage } from './index' + +describe('UpdateMessage', function () { + const original = window.location + + beforeAll(() => { + Object.defineProperty(window, 'location', { + configurable: true, + value: { reload: jest.fn() }, + }) + }) + + afterAll(() => { + Object.defineProperty(window, 'location', { + configurable: true, + value: original, + }) + }) + + test('renders correctly when active', function () { + const { asFragment } = render() + + expect(asFragment()).toMatchSnapshot() + }) + + test('renders nothing when dismissed', function () { + const { asFragment } = render() + + expect(asFragment()).toMatchSnapshot() + }) + + test('triggers reload correctly', function () { + render() + + expect( + screen.findByText('An update is available. Click here to update the App.') + ) + + screen.getByText('here').click() + + expect(window.location.reload).toHaveBeenCalled() + }) +}) diff --git a/src/components/UpdateMessage.tsx b/src/components/UpdateMessage.tsx index 58b3298..982afc5 100644 --- a/src/components/UpdateMessage.tsx +++ b/src/components/UpdateMessage.tsx @@ -8,7 +8,7 @@ const Wrapper = styled.div` left: ${spacing.normal}; bottom: ${spacing.normal}; right: ${spacing.normal}; - text-aling: center; + text-align: center; z-index: ${zIndex.updateMessage}; ` diff --git a/src/components/__snapshots__/UpdateMessage.test.tsx.snap b/src/components/__snapshots__/UpdateMessage.test.tsx.snap new file mode 100644 index 0000000..aa1420c --- /dev/null +++ b/src/components/__snapshots__/UpdateMessage.test.tsx.snap @@ -0,0 +1,23 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`UpdateMessage renders correctly when active 1`] = ` + +
+
+ An update is available. Click + + here + + to update the App. +
+
+
+`; + +exports[`UpdateMessage renders nothing when dismissed 1`] = ``;