-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd438a1
commit c4b433d
Showing
11 changed files
with
2,688 additions
and
2,814 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,37 @@ on: | |
pull_request: | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
|
||
- name: Set up Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
cache: 'yarn' | ||
|
||
- name: Install Dependencies | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Test | ||
run: yarn run test --coverage | ||
|
||
- name: Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-20.04 | ||
needs: [test] | ||
strategy: | ||
matrix: | ||
node-version: ['12', '14', '16'] | ||
node-version: [ '12', '14', '16' ] | ||
|
||
steps: | ||
- name: Checkout | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
react-app-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React from 'react' | ||
import App from './App' | ||
import { render, screen } from '@testing-library/react' | ||
import * as api from './lib/api' | ||
import { Settings, Ticker } from './lib/types' | ||
|
||
describe('App', function () { | ||
const initSettings = { | ||
refresh_interval: 1000, | ||
inactive_settings: { | ||
author: 'Systemli Ticker Team', | ||
email: '[email protected]', | ||
homepage: '', | ||
twitter: '', | ||
headline: 'The ticker is currently inactive.', | ||
sub_headline: 'Please contact us if you want to use it.', | ||
description: '...', | ||
}, | ||
} as Settings | ||
const ticker = { | ||
id: '1', | ||
active: true, | ||
creation_date: new Date(), | ||
title: 'Ticker Title', | ||
description: 'Ticker Description', | ||
domain: 'example.com', | ||
information: { | ||
author: 'Systemli Ticker Team', | ||
url: '', | ||
email: '', | ||
twitter: '', | ||
facebook: '', | ||
}, | ||
} as Ticker | ||
|
||
test('renders OfflineView', async function () { | ||
jest.spyOn(api, 'getInit').mockRejectedValue(new TypeError()) | ||
render(<App />) | ||
|
||
expect(screen.getByText('Loading')).toBeInTheDocument() | ||
|
||
expect( | ||
await screen.findByText('It seems that you are offline.') | ||
).toBeInTheDocument() | ||
}) | ||
|
||
test('renders InactiveView', async function () { | ||
jest.spyOn(api, 'getInit').mockResolvedValue({ | ||
data: { | ||
settings: initSettings, | ||
ticker: null, | ||
}, | ||
}) | ||
render(<App />) | ||
|
||
expect(screen.getByText('Loading')).toBeInTheDocument() | ||
|
||
expect( | ||
await screen.findByText('The ticker is currently inactive.') | ||
).toBeInTheDocument() | ||
}) | ||
|
||
test('renders ActiveView', async function () { | ||
jest.spyOn(api, 'getInit').mockResolvedValue({ | ||
data: { | ||
settings: initSettings, | ||
ticker: ticker, | ||
}, | ||
}) | ||
jest.spyOn(api, 'getTimeline').mockResolvedValue({ | ||
data: { | ||
messages: [], | ||
}, | ||
}) | ||
const intersectionObserverMock = () => ({ | ||
observe: () => null, | ||
}) | ||
window.IntersectionObserver = jest | ||
.fn() | ||
.mockImplementation(intersectionObserverMock) | ||
render(<App />) | ||
|
||
expect(screen.getByText('Loading')).toBeInTheDocument() | ||
|
||
expect( | ||
await screen.findByText( | ||
'The messages update automatically. There is no need to reload the entire page.' | ||
) | ||
).toBeInTheDocument() | ||
|
||
expect( | ||
screen.getByText('We dont have any messages at the moment.') | ||
).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react' | ||
import * as api from '../lib/api' | ||
import MessageList from './MessageList' | ||
import { render, screen } from '@testing-library/react' | ||
|
||
describe('MessageList', function () { | ||
test('renders empty Messages', async function () { | ||
jest.spyOn(api, 'getTimeline').mockResolvedValue({ | ||
data: { messages: [] }, | ||
}) | ||
const intersectionObserverMock = () => ({ | ||
observe: () => null, | ||
}) | ||
window.IntersectionObserver = jest | ||
.fn() | ||
.mockImplementation(intersectionObserverMock) | ||
|
||
render(<MessageList refreshInterval={10} />) | ||
|
||
expect(screen.getByText('Loading messages')).toBeInTheDocument() | ||
expect( | ||
await screen.findByText('We dont have any messages at the moment.') | ||
).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Message, Settings, Ticker } from './types' | ||
|
||
const apiUrl = process.env.REACT_APP_API_URL || 'http://localhost:8080/v1' | ||
|
||
type InitResponseData = { | ||
settings: Settings | ||
ticker: Ticker | null | ||
} | ||
|
||
export type InitResponse = { | ||
data: InitResponseData | ||
} | ||
|
||
type TimelineResponseData = { | ||
messages: Message[] | ||
} | ||
|
||
export type TimelineResponse = { | ||
data: TimelineResponseData | ||
} | ||
|
||
async function get<T>(path: string, config?: RequestInit): Promise<T> { | ||
const init = { method: 'get', ...config } | ||
const request = new Request(path, init) | ||
const response = await fetch(request) | ||
|
||
if (!response.ok) { | ||
throw new Error( | ||
`The server responses with an error: ${response.statusText} (${response.status})` | ||
) | ||
} | ||
|
||
return response.json().catch(() => ({})) | ||
} | ||
|
||
export async function getInit(): Promise<InitResponse> { | ||
return get(`${apiUrl}/init`) | ||
} | ||
|
||
export type TimelineOpts = { | ||
after?: string | null | ||
before?: string | null | ||
} | ||
|
||
export async function getTimeline( | ||
opts: TimelineOpts | ||
): Promise<TimelineResponse> { | ||
if (opts.after != null) { | ||
return get(`${apiUrl}/timeline?after=${opts.after}`) | ||
} | ||
|
||
if (opts.before != null) { | ||
return get(`${apiUrl}/timeline?before=${opts.before}`) | ||
} | ||
|
||
return get(`${apiUrl}/timeline`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// jest-dom adds custom jest matchers for asserting on DOM nodes. | ||
// allows you to do things like: | ||
// expect(element).toHaveTextContent(/react/i) | ||
// learn more: https://github.com/testing-library/jest-dom | ||
import '@testing-library/jest-dom' |
Oops, something went wrong.