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

Testing #43

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions .hermione.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
baseUrl: 'http://localhost:3000',
compositeImage: true,

sets: {
desktop: {
files: 'hermione/test/desktop'
}
},

browsers: {
chrome: {
desiredCapabilities: {
browserName: 'chrome'
}
}
},

plugins: {
'html-reporter/hermione': {
path: 'hermione/html-report'
},
'hermione-expect-location': true,
'hermione-link-traversal': true
}
};
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ npm start
- нужно добавить в README список логических блоков системы и их сценариев
- для каждого блока нужно написать модульные тесты
- если необходимо, выполните рефакторинг, чтобы реорганизовать логические блоки или добавить точки расширения

## Логические блоки системы
1. Навигация — составление url и хлебных крошек. Методы `buildFolderUrl`, `buildFileUrl`, `buildBreadcrumbs`
1. Гит — получение и обработка данных git. Методы: `gitHistory`, `gitFileTree`, `gitFileContent`
1. Контроллеры — обработка и передча данных на view. Методы, экспортируемые из файлов в папке `controllers`
19 changes: 16 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@ const express = require('express');
const PORT = 3000;
const HOST = '::';

const {
gitHistoryFactory,
gitFileTreeFactory,
gitFileContentFactory
} = require('./utils/git');

const gitHistory = gitHistoryFactory();
const gitFileTree = gitFileTreeFactory();
const gitFileContent = gitFileContentFactory();

// controllers
const indexController = require('./controllers/indexController');
const filesController = require('./controllers/filesController');
const contentController = require('./controllers/contentController');
const indexController = require('./controllers/indexController')();
const filesController = require('./controllers/filesController')();
const contentController = require('./controllers/contentController')({
gitFileTree,
gitFileContent
});

const app = express();

Expand Down
47 changes: 24 additions & 23 deletions controllers/contentController.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
const { gitFileContent, gitFileTree } = require('../utils/git');
const { buildFolderUrl, buildBreadcrumbs } = require('../utils/navigation');

module.exports = function(req, res, next) {
const { hash } = req.params;
const path = req.params[0].split('/').filter(Boolean);
module.exports = function({ gitFileTree, gitFileContent }) {
return function(req, res, next) {
const { hash } = req.params;
const path = req.params[0].split('/').filter(Boolean);

gitFileTree(hash, path.join('/'))
.then(function([file]) {
if (file && file.type === 'blob') {
return gitFileContent(file.hash);
}
})
.then(
content => {
if (content) {
res.render('content', {
title: 'content',
breadcrumbs: buildBreadcrumbs(hash, path.join('/')),
content
});
} else {
next();
gitFileTree(hash, path.join('/'))
.then(function([file]) {
if (file && file.type === 'blob') {
return gitFileContent(file.hash);
}
},
err => next(err)
);
})
.then(
content => {
if (content) {
res.render('content', {
title: 'content',
breadcrumbs: buildBreadcrumbs(hash, path.join('/')),
content
});
} else {
next();
}
},
err => next(err)
);
};
};
44 changes: 24 additions & 20 deletions controllers/filesController.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { gitFileTree } = require('../utils/git');
const { gitFileTreeFactory } = require('../utils/git');
const {
buildFolderUrl,
buildFileUrl,
buildBreadcrumbs
} = require('../utils/navigation');

const gitFileTree = gitFileTreeFactory();

function buildObjectUrl(parentHash, { path, type }) {
switch (type) {
case 'tree':
Expand All @@ -16,26 +18,28 @@ function buildObjectUrl(parentHash, { path, type }) {
}
}

module.exports = function(req, res, next) {
const { hash } = req.params;
const pathParam = (req.params[0] || '').split('/').filter(Boolean);
module.exports = function(getFileTree = gitFileTree) {
return function(req, res, next) {
const { hash } = req.params;
const pathParam = (req.params[0] || '').split('/').filter(Boolean);

const path = pathParam.length ? pathParam.join('/') + '/' : '';
const path = pathParam.length ? pathParam.join('/') + '/' : '';

return gitFileTree(hash, path).then(
list => {
const files = list.map(item => ({
...item,
href: buildObjectUrl(hash, item),
name: item.path.split('/').pop()
}));
return getFileTree(hash, path).then(
list => {
const files = list.map(item => ({
...item,
href: buildObjectUrl(hash, item),
name: item.path.split('/').pop()
}));

res.render('files', {
title: 'files',
breadcrumbs: buildBreadcrumbs(hash, pathParam.join('/')),
files
});
},
err => next(err)
);
res.render('files', {
title: 'files',
breadcrumbs: buildBreadcrumbs(hash, pathParam.join('/')),
files
});
},
err => next(err)
);
};
};
36 changes: 20 additions & 16 deletions controllers/indexController.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
const { gitHistory } = require('../utils/git');
const { gitHistoryFactory } = require('../utils/git');
const { buildFolderUrl, buildBreadcrumbs } = require('../utils/navigation');

module.exports = function(req, res) {
gitHistory(1, 20).then(
history => {
const list = history.map(item => ({
...item,
href: buildFolderUrl(item.hash, '')
}));
const gitHistory = gitHistoryFactory();

res.render('index', {
title: 'history',
breadcrumbs: buildBreadcrumbs(),
list
});
},
err => next(err)
);
module.exports = function(getHistory = gitHistory) {
return function(req, res) {
getHistory(1, 20).then(
history => {
const list = history.map(item => ({
...item,
href: buildFolderUrl(item.hash, '')
}));

res.render('index', {
title: 'history',
breadcrumbs: buildBreadcrumbs(),
list
});
},
err => next(err)
);
};
};
2 changes: 2 additions & 0 deletions hermione/html-report/data.js

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions hermione/html-report/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>HTML report</title>
<meta charset="utf-8">
<link href="report.min.css" rel="stylesheet"></head>
<body class="report">
<div id="app"></div>
<script type="text/javascript" src="data.js"></script><script type="text/javascript" src="report.min.js"></script></body>
</html>
1 change: 1 addition & 0 deletions hermione/html-report/report.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions hermione/html-report/report.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions hermione/plugins/hermione-expect-location/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const expect = require('chai').expect;

module.exports = function expectLocation(hermione, opts) {
hermione.on(hermione.events.NEW_BROWSER, (browser) => {
browser.addCommand('expectLocation', (selector, expected) => {
return browser.getLocation(selector)
.then(location => {
expect(location).to.deep.equal(expected);
});
});
});
};

5 changes: 5 additions & 0 deletions hermione/plugins/hermione-expect-location/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions hermione/plugins/hermione-expect-location/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "hermione-expect-location",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
16 changes: 16 additions & 0 deletions hermione/plugins/hermione-link-traversal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const expect = require('chai').expect;

module.exports = function traverseLink(hermione, opts) {
hermione.on(hermione.events.NEW_BROWSER, (browser) => {
browser.addCommand('traverseLink', (params) => {
return browser.url(params.fromUrl)
.click(params.linkEl)
.waitForExist(params.waitForEl)
.getUrl()
.then(url => {
expect(url).to.equal(`${hermione.config.baseUrl}${params.toUrl}`);
});
});
});
};

5 changes: 5 additions & 0 deletions hermione/plugins/hermione-link-traversal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions hermione/plugins/hermione-link-traversal/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "hermione-link-traversal",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Binary file added hermione/screens/246c90b/chrome/commit list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hermione/screens/2651b79/chrome/breadcrumbs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hermione/screens/3d45595/chrome/breadcrubbs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hermione/screens/3d45595/chrome/breadcrumbs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hermione/screens/4ce4ca1/chrome/breadcrumbs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hermione/screens/8325a2f/chrome/commit list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hermione/screens/8465644/chrome/file content.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hermione/screens/a957080/chrome/file tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hermione/screens/c5d00a0/chrome/breadcrumbs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hermione/screens/d260a8d/chrome/breadcrumbs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hermione/screens/e9f737e/chrome/file tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hermione/screens/fc46820/chrome/breadcrubbs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions hermione/test/desktop/file.hermione.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const expect = require('chai').expect;
const pageUrl = '/content/999bfb1ec309158f4c86edee76fa5630a3aba565/README.md';

describe('File', function() {
describe('screenshot testing', function() {
it('has breadcrumbs', function() {
return this.browser
.url(pageUrl)
.assertView('breadcrumbs', '.breadcrumbs');
});

it('has file tree', function() {
return this.browser
.url(pageUrl)
.assertView('file content', '.content');
});
});

describe('position', function() {
it('renders breadcrumbs in proper location', function() {
return this.browser.url(pageUrl)
.expectLocation('.breadcrumbs', { x: 200, y: 28 });
});

it('renders file content in proper location', function() {
return this.browser.url(pageUrl)
.expectLocation('.content', { x: 200, y: 88 });
});
});
});
30 changes: 30 additions & 0 deletions hermione/test/desktop/filesystem.hermione.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const expect = require('chai').expect;
const pageUrl = '/files/999bfb1ec309158f4c86edee76fa5630a3aba565/';

describe('Files', function() {
describe('screenshot testing', function() {
it('has breadcrumbs', function() {
return this.browser
.url(pageUrl)
.assertView('breadcrumbs', '.breadcrumbs');
});

it('has file tree', function() {
return this.browser
.url(pageUrl)
.assertView('file tree', '.content');
});
});

describe('position', function() {
it('renders breadcrumbs in proper location', function() {
return this.browser.url(pageUrl)
.expectLocation('.breadcrumbs', { x: 200, y: 28 });
});

it('renders file tree in proper location', function() {
return this.browser.url(pageUrl)
.expectLocation('.content', { x: 200, y: 88 });
});
});
});
Loading