Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix UpdateMessage Component #265

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/components/UpdateMessage.test.tsx
Original file line number Diff line number Diff line change
@@ -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(<UpdateMessage update />)

expect(asFragment()).toMatchSnapshot()
})

test('renders nothing when dismissed', function () {
const { asFragment } = render(<UpdateMessage update={false} />)

expect(asFragment()).toMatchSnapshot()
})

test('triggers reload correctly', function () {
render(<UpdateMessage update />)

expect(
screen.findByText('An update is available. Click here to update the App.')
)

screen.getByText('here').click()

expect(window.location.reload).toHaveBeenCalled()
})
})
2 changes: 1 addition & 1 deletion src/components/UpdateMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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};
`

Expand Down
23 changes: 23 additions & 0 deletions src/components/__snapshots__/UpdateMessage.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`UpdateMessage renders correctly when active 1`] = `
<DocumentFragment>
<div
class="sc-iCfMLu iiqfvg"
>
<div
class="ui yellow negative message"
>
An update is available. Click
<a
class="sc-furwcr enHelU"
>
here
</a>
to update the App.
</div>
</div>
</DocumentFragment>
`;

exports[`UpdateMessage renders nothing when dismissed 1`] = `<DocumentFragment />`;