Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
feat(network-status): add tests to NetworkStatus component
Browse files Browse the repository at this point in the history
  • Loading branch information
alessioprestileo committed May 30, 2020
1 parent 9c0376f commit a3c5417
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { render, shallow } from 'enzyme'
import React from 'react'

import {
NetworkStatusMessage,
OFFLINE_MESSAGE,
ONLINE_MESSAGE,
} from '../../../components/network-status/NetworkStatusMessage'

describe('NetworkStatusMessage', () => {
it('returns null if the app has always been online', () => {
const wrapper = shallow(<NetworkStatusMessage online wasOffline={false} />)
expect(wrapper.equals(null as any)).toBe(true)
})
it(`shows the message "${OFFLINE_MESSAGE}" if the app goes offline`, () => {
const wrapper = render(<NetworkStatusMessage online={false} wasOffline={false} />)
expect(wrapper.text()).toContain(OFFLINE_MESSAGE)
})
it(`shows the message "${ONLINE_MESSAGE}" if the app goes back online after it was offline`, () => {
const wrapper = render(<NetworkStatusMessage online wasOffline />)
expect(wrapper.text()).toContain(ONLINE_MESSAGE)
})
})
6 changes: 3 additions & 3 deletions src/components/network-status/NetworkStatusMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useState } from 'react'

import './styles.css'
// import './styles.css'

interface Props {
online: boolean
wasOffline: boolean
}

const OFFLINE_MESSAGE = 'you are working in offline mode'
const ONLINE_MESSAGE = 'you are back online'
export const OFFLINE_MESSAGE = 'you are working in offline mode'
export const ONLINE_MESSAGE = 'you are back online'
const OPACITY_TRANSITION_TIME = 4000

export const NetworkStatusMessage = (props: Props) => {
Expand Down

0 comments on commit a3c5417

Please # to comment.