Skip to content

Commit

Permalink
Added tests and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophNiehoff committed Aug 4, 2023
1 parent 7564a0f commit 4ae7c0d
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 57 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ To build both the client and the server, just run
npm run build
```

#### Imprint and privacy notices

Links to imprint and privacy notices can be included into the client, if the environment variable

```bash
export REACT_APP_EOP_IMPRINT="https://example.tld/imprint/"
export REACT_APP_EOP_PRIVACY="https://example.tld/privacy/"
```

are set when building the app.
When building the client via docker these env vars can be set by defining `build-args`

```bash
docker build --build-arg "EOP_IMPRINT=https://example.tld/imprint/" --build-arg "EOP_PRIVACY=https://example.tld/privacy/" -f docker/client.dockerfile . -t "some-tag"
```

### Using MongoDB

As of boardgame.io v0.39.0, MongoDB is no longer supported as a database connector. There is currently no external library providing this functionality, however there is an [implementation](https://github.com/boardgameio/boardgame.io/issues/6#issuecomment-656144940) posted on github. This class implements the abstract functions in [this base class](https://github.com/boardgameio/boardgame.io/blob/ce8ef4a16bcc420b05c5e0751b41f168352bce7d/src/server/db/base.ts#L49-L111).
Expand Down
47 changes: 0 additions & 47 deletions src/client/components/board/board.test.js

This file was deleted.

110 changes: 110 additions & 0 deletions src/client/components/board/board.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import '@testing-library/jest-dom';
import React from 'react';
import { render, screen } from '@testing-library/react';
import Board from './board';
import { DEFAULT_TURN_DURATION } from '../../../utils/constants';
import { DEFAULT_GAME_MODE } from '../../../utils/GameMode';

jest.mock('../model/model.jsx');

const G = {
dealt: [],
players: {
0: ['T3', 'T4', 'T5'],
},
order: [0, 1, 2],
scores: [0, 0, 0],
identifiedThreats: {},
selectedDiagram: 0,
selectedComponent: '',
threat: {
modal: false,
},
passed: [],
suit: 'T',
round: 1,
startingCard: 'T3',
gameMode: DEFAULT_GAME_MODE,
turnDuration: DEFAULT_TURN_DURATION,
turnFinishTargetTime: Date.now() + DEFAULT_TURN_DURATION * 1000,
};
const ctx = {
actionPlayers: [0, 1, 2],
};
Board.prototype.componentDidMount = jest.fn();


describe('Board', () => {
it('renders without crashing', async () => {

// when
render(<Board G={G} ctx={ctx} matchID="123" moves={{}} events={{}} playerID="0" />);

// then
await screen.getByRole(`button`, {
name: `Download Threats`
});

});

it('should render imprint link if env var is defined', async () => {
// given
process.env.REACT_APP_EOP_IMPRINT = 'https://example.tld/imprint/'

// when
render(<Board G={G} ctx={ctx} matchID="123" moves={{}} events={{}} playerID="0" />);

// when

// then
const links = await screen.queryAllByRole('link', {
name: `Imprint`
});
expect(links.length).toBe(1);
});

it('should not render imprint link if env var is not defined', async () => {
// given
process.env.REACT_APP_EOP_IMPRINT = "";

// when
render(<Board G={G} ctx={ctx} matchID="123" moves={{}} events={{}} playerID="0" />);

// then
const links = await screen.queryAllByRole('link', {
name: `Imprint`
});
expect(links.length).toBe(0);
});

it('should render privacy link if env var is defined', async () => {
// given
process.env.REACT_APP_EOP_PRIVACY = 'https://example.tld/privacy/'

// when
render(<Board G={G} ctx={ctx} matchID="123" moves={{}} events={{}} playerID="0" />);

// when

// then
const links = await screen.queryAllByRole('link', {
name: `Privacy`
});
expect(links.length).toBe(1);
});

it('should not render privacy link if env var is not defined', async () => {
// given
process.env.REACT_APP_EOP_PRIVACY = "";

// when
render(<Board G={G} ctx={ctx} matchID="123" moves={{}} events={{}} playerID="0" />);

// then
const links = await screen.queryAllByRole('link', {
name: `Privacy`
});
expect(links.length).toBe(0);
});

});
30 changes: 30 additions & 0 deletions src/client/components/footer/imprint.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import '@testing-library/jest-dom';
import React from 'react';
import { render, screen } from '@testing-library/react';
import Imprint from './imprint';

describe('Imprint', () => {
it('should render link if env var is defined', async () => {
// given
process.env.REACT_APP_EOP_IMPRINT = 'https://example.tld/imprint/'
render(<Imprint />);

// when
const links = await screen.queryAllByRole('link');

// then
expect(links.length).toBe(1);
});

it('should not render link if env var is not defined', async () => {
// given
process.env.REACT_APP_EOP_IMPRINT = "";
render(<Imprint />);

// when
const links = await screen.queryAllByRole('link');

// then
expect(links.length).toBe(0);
});
});
30 changes: 30 additions & 0 deletions src/client/components/footer/privacy.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import '@testing-library/jest-dom';
import React from 'react';
import { render, screen } from '@testing-library/react';
import Privacy from './privacy';

describe('Privacy', () => {
it('should render link if env var is defined', async () => {
// given
process.env.REACT_APP_EOP_PRIVACY = 'https://example.tld/privacy/'
render(<Privacy />);

// when
const links = await screen.queryAllByRole('link');

// then
expect(links.length).toBe(1);
});

it('should not render link if env var is not defined', async () => {
// given
process.env.REACT_APP_EOP_PRIVACY = "";
render(<Privacy />);

// when
const links = await screen.queryAllByRole('link');

// then
expect(links.length).toBe(0);
});
});
81 changes: 71 additions & 10 deletions src/client/pages/__tests__/create.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,76 @@
import '@testing-library/jest-dom';
import React from 'react';
import ReactDOM from 'react-dom';
import { render, screen } from '@testing-library/react';
import Create from '../create';
import { BrowserRouter as Router } from 'react-router-dom';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(
<Router>
<Create />
</Router>,
div,
);
ReactDOM.unmountComponentAtNode(div);
describe('<Create />', () => {
it('renders without crashing', async () => {
render(<Router><Create /></Router>);

await screen.getAllByRole('button', {
name: 'Proceed'
});
});

it('should render imprint link if env var is defined', async () => {
// given
process.env.REACT_APP_EOP_IMPRINT = 'https://example.tld/imprint/'

// when
render(<Router><Create /></Router>);

// when

// then
const links = await screen.queryAllByRole('link', {
name: `Imprint`
});
expect(links.length).toBe(1);
});

it('should not render imprint link if env var is not defined', async () => {
// given
process.env.REACT_APP_EOP_IMPRINT = "";

// when
render(<Router><Create /></Router>);

// then
const links = await screen.queryAllByRole('link', {
name: `Imprint`
});
expect(links.length).toBe(0);
});

it('should render privacy link if env var is defined', async () => {
// given
process.env.REACT_APP_EOP_PRIVACY = 'https://example.tld/privacy/'

// when
render(<Router><Create /></Router>);

// when

// then
const links = await screen.queryAllByRole('link', {
name: `Privacy`
});
expect(links.length).toBe(1);
});

it('should not render privacy link if env var is not defined', async () => {
// given
process.env.REACT_APP_EOP_PRIVACY = "";

// when
render(<Router><Create /></Router>);

// then
const links = await screen.queryAllByRole('link', {
name: `Privacy`
});
expect(links.length).toBe(0);
});

});

0 comments on commit 4ae7c0d

Please sign in to comment.