Permalink
Browse files

Split up tests to files matching implementation file name

  • Loading branch information...
Siilwyn committed Feb 5, 2019
1 parent 5e5b6a4 commit d54f27393e23ec46f7f85f1a02916d441b09eee5
Showing with 211 additions and 205 deletions.
  1. +1 −1 package.json
  2. +1 −1 readme.md
  3. +86 −0 src/generate-sidebar.test.js
  4. +34 −0 src/main.test.js
  5. +0 −203 src/test.js
  6. +89 −0 src/url-matchers.test.js
@@ -3,7 +3,7 @@
"description": "Voorhoede playbook based on Dropbox Paper.",
"scripts": {
"start": "npm run docs:content && npm run docs:dev",
"test": "ava ./src/test.js",
"test": "ava ./src/*.test.js",
"test:ci": "npm run test -- --verbose && npm run lint -- --max-warnings 0",
"test:watch": "npm run test -- --watch --verbose",
"docs:dev": "vuepress dev docs",
@@ -43,7 +43,7 @@ npm run docs:build
Because Vuepress does not support asynchronous configuration the fetching content and building the website is seperated. Which means the needed sidebar data is written to a temporary file so it can be synchronously read from [docs/.vuepress/config.js](docs/.vuepress/config.js).

#### Testing
Unit tests are present in [src/test.js](src/test.js) and are ran with: `npm test`.
Unit tests are present in each file matching the implementation filename ending with `.test.js` and are ran with: `npm test`.

#### Style
The code is written in a functional style using [Sanctuary](https://sanctuary.js.org/) to provide simple, pure functions with no need for `null` checks.
@@ -0,0 +1,86 @@
'use strict';

const test = require('ava');
const generateSidebar = require('./generate-sidebar.js');

test('generateSidebar', t => {
const files = [
{
folders: [
{ id: '', name: 'Playbook' },
{ id: '', name: 'Scrum' },
],
location: 'docs/playbook/scrum/one.md',
content: { metaData: { title: 'one' } },
},
{
folders: [
{ id: '', name: 'Playbook' },
{ id: '', name: 'Scrum' },
],
location: 'docs/playbook/scrum/two.md',
content: { metaData: { title: 'two' } },
},
{
folders: [
{ id: '', name: 'Playbook' },
{ id: '', name: 'Team' },
],
location: 'docs/playbook/team/uno',
content: { metaData: { title: 'uno' } },
},
{
folders: [
{ id: '', name: 'Playbook' },
],
location: 'docs/playbook/something',
content: { metaData: { title: 'something' } },
},
];

t.deepEqual(
generateSidebar(files),
[
{
title: 'Scrum',
children: ['playbook/scrum/one.md','playbook/scrum/two.md'],
},
{
title: 'Team',
children: ['playbook/team/uno'],
},
{
title: 'Playbook',
children: ['playbook/something'],
},
]
);
});

test('generateSidebar ignores readme files', t => {
const files = [
{
folders: [
{ id: '', name: 'Playbook' },
],
location: 'docs/playbook/readme',
content: { metaData: { title: 'readme' } },
},
];

t.deepEqual(generateSidebar(files), []);
});

test('generateSidebar ignores double nested files', t => {
const files = [
{
folders: [
{ id: '', name: 'Playbook' },
{ id: '', name: 'Scrum' },
{ id: '', name: 'nope' },
],
},
];

t.deepEqual(generateSidebar(files), []);
});
@@ -0,0 +1,34 @@
'use strict';

const test = require('ava');
const { Nothing, isJust } = require('sanctuary');
const {
isPermissionError,
foldersToPath,
} = require('./main.js')();

test('isPermissionError', t => {
t.is(isPermissionError({}), Nothing);
t.is(isPermissionError({ body: { error_summary: 'nope' } }), Nothing);

t.true(isJust(isPermissionError(
{ body: { error_summary: 'insufficient_permissions' } }
)));
});

test('foldersToPath', t => {
const folders = [
{
id: 'e.1gg8YzoPEhbTkrhvQwJ2zzxMxerM1EJ5G5cIAQCUvtk08l5Miut8',
name: 'Playbook',
},
{
id: 'e.1gg8YzoPEhbTkrhvQwJ2zzxMxerM4LNUzL5DSGyTOTXGxKnnDyWb',
name: 'This is a category',
},
];

t.is(foldersToPath(folders), 'playbook/this-is-a-category');
t.is(foldersToPath([ folders[0] ]), 'playbook');
t.is(foldersToPath([]), '');
});

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit d54f273

Please sign in to comment.