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

Dev #54

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Dev #54

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
33 changes: 33 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"globals": {
"$": false
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2015,
"sourceType": "module"
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
25 changes: 25 additions & 0 deletions .hermione.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
browsers: {
// Для тестирования на MacOS -- поменять закомменченные и раскомменченные браузеры
// safari: {
// desiredCapabilities: {
// browserName: 'safari'
// }
// },
chrome: {
desiredCapabilities: {
browserName: 'chrome'
}
},
firefox: {
desiredCapabilities: {
browserName: 'firefox'
}
}
},
plugins: {
'html-reporter/hermione': {
path: 'hermione-html-report'
}
}
};
51 changes: 48 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,51 @@ npm start

## Модульные тесты

- нужно добавить в README список логических блоков системы и их сценариев
- для каждого блока нужно написать модульные тесты
- если необходимо, выполните рефакторинг, чтобы реорганизовать логические блоки или добавить точки расширения
### Cписок логических блоков системы и их сценариев

#### Контроллеры
- Контроллер контента
- Контроллер файлов
- Контроллер индекса

### utils
- git
_приватные_
-- Парсинг истории
-- Парсинг файлового дерева
_публичные_
-- Сборка истории
-- Сборка файлового дерева
-- Сборка контента

- навигация
-- Сборка URL папки
-- Сборка URL файла
-- Сборка хлебных крошек

# Сборка тестов

## Модульные тесты
Для запуска модульных тестов выполните последовательность команд
```
npm i
npm run test
```

## Интеграционные тесты
Для запуска интеграционных тестов выполните последовательность команд
```
npm i -g selenium-standalone
selenium-standalone install
npm i -D hermione

# Вкладка консоли 1
npm run selen
# Вкладка консоли 2
npm start
# Вкладка консоли 3
npm run hermi
```

*Note:* для работы гермионы на Windows требуется установка Python 2 и MS VisualStudio.
*Note 2:* наблюдаются баги в работе assertView на OS Windows, оптимально тестирование на Unix платформах
52 changes: 34 additions & 18 deletions controllers/contentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,43 @@ 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);
const { hash } = req ? req.params : '';
const path = req ? 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', {
this.gitFileTree = gitFileTree;
this.gitFileContent = gitFileContent;
this.buildBreadcrumbs = buildBreadcrumbs;

this.buildRenderData = (hash, path) => {
path = path ? path.join('/') : '';

return new Promise ((res, rej) => {
this.gitFileTree(hash, path)
.then(([file]) => {
if (file && file.type === 'blob') {
return this.gitFileContent(file.hash);
}
})
.then(content => {
res({
title: 'content',
breadcrumbs: buildBreadcrumbs(hash, path.join('/')),
breadcrumbs: this.buildBreadcrumbs(hash, path),
content
});
} else {
next();
}
},
err => next(err)
);
);
});
};

if (req && res) {
this.buildRenderData(hash, path).then(data => {
if (data && res) {
res.render('content', data);
} else {
next();
}
},
err => next(err));
}

};
82 changes: 52 additions & 30 deletions controllers/filesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,59 @@ const {
buildBreadcrumbs
} = require('../utils/navigation');

function buildObjectUrl(parentHash, { path, type }) {
switch (type) {
case 'tree':
return buildFolderUrl(parentHash, path);
case 'blob':
return buildFileUrl(parentHash, path);
default:
return '#';
module.exports = function(req, res, next) {
const { hash } = req ? req.params : '';
const pathParam = req ? (req.params[0] || '').split('/').filter(Boolean) : '';

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

this.gitFileTree = gitFileTree;
this.buildFolderUrl = buildFolderUrl;
this.buildFileUrl = buildFileUrl;
this.buildBreadcrumb = buildBreadcrumbs;

this.buildObjectUrl = (parentHash, { path, type }) => {
switch (type) {
case 'tree':
return this.buildFolderUrl(parentHash, path);
case 'blob':
return this.buildFileUrl(parentHash, path);
default:
return '#';
}
}
}

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

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()
}));

res.render('files', {
title: 'files',
breadcrumbs: buildBreadcrumbs(hash, pathParam.join('/')),
files
});
this.buildRenderData = () => {
return new Promise((res) => {
this.gitFileTree(hash, path).then(
list => {
const files = list.map(item => ({
...item,
href: this.buildObjectUrl(hash, item),
name: item.path.split('/').pop()
}));

thisPathParam = pathParam && pathParam.length ? pathParam.join('/') : '';

res({
title: 'files',
breadcrumbs: this.buildBreadcrumb(hash, thisPathParam),
files
});
},
err => next(err)
);
});
}

if (req && res) {
this.buildRenderData(hash, path).then(data => {
if (data && res) {
res.render('files', data);
} else {
next();
}
},
err => next(err)
);
err => next(err));
}
};
42 changes: 31 additions & 11 deletions controllers/indexController.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
const { gitHistory } = 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, '')
}));
module.exports = function (req, res) {
this.gitHistory = gitHistory;
this.buildFolderUrl = buildFolderUrl;

this.buildList = () => {
const thisGitHistory = this.gitHistory;
const thisBuildFolderUrl = this.buildFolderUrl;

return thisGitHistory(1, 20).then(
history => {
return history.map(item => ({
...item,
href: thisBuildFolderUrl(item.hash, '')
}));
},
/**
* в рамках данного задания не предполагалось исправления существующего кода,
* только реорганизация, да и исходная задумка автора неизвестна.
* Потому это неопределённое next оставлю без изменений,
* хотя по-хорошему его тоже можно было бы протестировать.
*/
err => next(err)
);
}

this.render = list => {
if (res) {
res.render('index', {
title: 'history',
breadcrumbs: buildBreadcrumbs(),
list
});
},
err => next(err)
);
};
}
}

this.buildList().then(list => this.render(list));
};
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.
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.
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.

Loading