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

тесты #48

Open
wants to merge 6 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 @@
const path = require("path");

module.exports = {
baseUrl: "http://localhost:3000",
gridUrl: "http://0.0.0.0:4444/wd/hub",
compositeImage: true,

browsers: {
chrome: {
desiredCapabilities: {
browserName: "chrome"
}
},
firefox: {
desiredCapabilities: {
browserName: "firefox"
}
}
},
plugins: {
"html-reporter/hermione": {
path: "hermione/hermione-html-report"
},
[path.resolve(__dirname, "./hermione/custom-commands.js")]: true
}
};
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,33 @@ npm start
- нужно добавить в README список логических блоков системы и их сценариев
- для каждого блока нужно написать модульные тесты
- если необходимо, выполните рефакторинг, чтобы реорганизовать логические блоки или добавить точки расширения

## Список логических блоков и их сценариев

1. История коммитов

- получение списка коммитов в виде строки
- преобразование строки в массив с объектами
- добавление к каждому из объекту из массива ключ href
- запуск функции render с массивом коммитов в качестве аргумента

2. Файловая система

- получение файловой структуры в виде строки
- преобразование строки в массив с объектами
- добавляет к каждому объекту ключи href и name
- запуск функции render с массивом объектов в качестве аргумента

3. Содержимое файлов

- получение содержимого файла в виде строки
- запуск функции render с передачей в нее содержимого файла

4. Создание путей

- создание пути к папке
- создание пути к файлу

5. Хлебные крошки

- добавление новых элементов в соответствии с уровнем страницы
25 changes: 15 additions & 10 deletions controllers/contentController.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
const { gitFileContent, gitFileTree } = require('../utils/git');
const { buildFolderUrl, buildBreadcrumbs } = require('../utils/navigation');
const { gitFileContent, gitFileTree } = require("../utils/git");
const { buildBreadcrumbs } = require("../utils/navigation");

module.exports = function(req, res, next, ...rest) {
const stubs = (rest && rest[0]) || {};
const _gitFileTree = stubs.gitFileTree || gitFileTree;
const _gitFileContent = stubs.gitFileContent || gitFileContent;
const _buildBreadcrumbs = stubs.buildBreadcrumbs || buildBreadcrumbs;

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

gitFileTree(hash, path.join('/'))
return _gitFileTree(hash, path.join("/"))
.then(function([file]) {
if (file && file.type === 'blob') {
return gitFileContent(file.hash);
if (file && file.type === "blob") {
return _gitFileContent(file.hash);
}
})
.then(
content => {
if (content) {
res.render('content', {
title: 'content',
breadcrumbs: buildBreadcrumbs(hash, path.join('/')),
res.render("content", {
title: "content",
breadcrumbs: _buildBreadcrumbs(hash, path.join("/")),
content
});
} else {
Expand Down
20 changes: 20 additions & 0 deletions controllers/contentController.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const contentController = require("./contentController");

describe("Содержимое файлов", () => {
const req = { params: { hash: "", "0": "" } };
const res = { render: jest.fn() };
const stubs = {};
stubs.gitFileTree = jest.fn(() =>
Promise.resolve([{ type: "", hash: "", path: "" }])
);
stubs.gitFileContent = jest.fn();
stubs.buildBreadcrumbs = jest.fn();

test("в функцию render в качестве аргументов попадают заголовок, хлебные крошки и содержимого файла", () => {
contentController(req, res, () => {}, stubs).then(() => {
const keys = Object.keys(res.render.mock.calls[0][1]);

expect(keys.toEqual(["title", "breadcrumbs", "content"]));
});
});
});
33 changes: 19 additions & 14 deletions controllers/filesController.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
const { gitFileTree } = require('../utils/git');
const { gitFileTree } = require("../utils/git");
const {
buildFolderUrl,
buildFileUrl,
buildBreadcrumbs
} = require('../utils/navigation');
} = require("../utils/navigation");

function buildObjectUrl(parentHash, { path, type }) {
switch (type) {
case 'tree':
case "tree":
return buildFolderUrl(parentHash, path);
case 'blob':
case "blob":
return buildFileUrl(parentHash, path);
default:
return '#';
return "#";
}
}

module.exports = function(req, res, next) {
module.exports = function(req, res, next, ...rest) {
const stubs = (rest && rest[0]) || {};
const _gitFileTree = stubs.gitFileTree || gitFileTree;
const _buildObjectUrl = stubs.buildObjectUrl || buildObjectUrl;
const _buildBreadcrumbs = stubs.buildBreadcrumbs || buildBreadcrumbs;

const { hash } = req.params;
const pathParam = (req.params[0] || '').split('/').filter(Boolean);
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(
return _gitFileTree(hash, path).then(
list => {
const files = list.map(item => ({
...item,
href: buildObjectUrl(hash, item),
name: item.path.split('/').pop()
href: _buildObjectUrl(hash, item),
name: item.path.split("/").pop()
}));

res.render('files', {
title: 'files',
breadcrumbs: buildBreadcrumbs(hash, pathParam.join('/')),
res.render("files", {
title: "files",
breadcrumbs: _buildBreadcrumbs(hash, pathParam.join("/")),
files
});
},
Expand Down
28 changes: 28 additions & 0 deletions controllers/filesController.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const filesController = require("./filesController");

describe("Файловая система", () => {
const stubs = {};
stubs.gitFileTree = jest.fn(() =>
Promise.resolve([{ type: "", hash: "", path: "" }])
);
stubs.buildObjectUrl = jest.fn();
stubs.buildBreadcrumbs = jest.fn();

const req = { params: { hash: "" } };
const res = { render: jest.fn() };

test("добавляются ключи href и path к объектам файлов", () => {
filesController(req, res, () => {}, stubs).then(() => {
expect(res.render.mock.calls[0][1].files.toHaveProperty("href"));
expect(res.render.mock.calls[0][1].files.toHaveProperty("name"));
});
});

test("в функцию render в качестве аргументов попадают заголовок, хлебные крошки и объекты файлов", () => {
filesController(req, res, () => {}, stubs).then(() => {
const keys = Object.keys(res.render.mock.calls[0][1]);

expect(keys.toEqual(["title", "breadcrumbs", "files"]));
});
});
});
21 changes: 13 additions & 8 deletions controllers/indexController.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
const { gitHistory } = require('../utils/git');
const { buildFolderUrl, buildBreadcrumbs } = require('../utils/navigation');
const { gitHistory } = require("../utils/git");
const { buildFolderUrl, buildBreadcrumbs } = require("../utils/navigation");

module.exports = function(req, res) {
gitHistory(1, 20).then(
module.exports = function(req, res, next, ...rest) {
const stubs = (rest && rest[0]) || {};
const _gitHistory = stubs.gitHistory || gitHistory;
const _buildFolderUrl = stubs.buildFolderUrl || buildFolderUrl;
const _buildBreadcrumbs = stubs.buildBreadcrumbs || buildBreadcrumbs;

return _gitHistory(1, 20).then(
history => {
const list = history.map(item => ({
...item,
href: buildFolderUrl(item.hash, '')
href: _buildFolderUrl(item.hash, "")
}));

res.render('index', {
title: 'history',
breadcrumbs: buildBreadcrumbs(),
res.render("index", {
title: "history",
breadcrumbs: _buildBreadcrumbs(),
list
});
},
Expand Down
25 changes: 25 additions & 0 deletions controllers/indexController.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const indexController = require("./indexController");

describe("История коммитов", () => {
const stubs = {};
stubs.gitHistory = jest.fn(() =>
Promise.resolve([{ hash: "", author: "", timestamp: "", msg: "" }])
);
stubs.buildFolderUrl = jest.fn();
stubs.buildBreadcrumbs = jest.fn();
const res = { render: jest.fn() };

test("добавляется ключ href к объекту коммита", () => {
indexController(null, res, () => {}, stubs).then(() => {
expect(res.render.mock.calls[0][1].list.toHaveProperty("href"));
});
});

test("в функцию render в качестве аргументов попадают заголовок, хлебные крошки и объекты коммитов", () => {
indexController(null, res, () => {}, stubs).then(() => {
const keys = Object.keys(res.render.mock.calls[0][1]);

expect(keys.toEqual(["title", "breadcrumbs", "list"]));
});
});
});
113 changes: 113 additions & 0 deletions coverage/clover.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1540379584976" clover="3.2.0">
<project timestamp="1540379584979" name="All files">
<metrics statements="85" coveredstatements="72" conditionals="64" coveredconditionals="41" methods="26" coveredmethods="19" elements="175" coveredelements="132" complexity="0" loc="85" ncloc="85" packages="2" files="5" classes="5">
<package name="controllers">
<metrics statements="45" coveredstatements="36" conditionals="40" coveredconditionals="22" methods="13" coveredmethods="9"/>
<file name="contentController.js" path="C:\Peter\workspace\Yandex\homeworks\testing\controllers\contentController.js">
<metrics statements="16" coveredstatements="13" conditionals="15" coveredconditionals="9" methods="4" coveredmethods="3"/>
<line num="1" count="1" type="stmt"/>
<line num="2" count="1" type="stmt"/>
<line num="4" count="1" type="stmt"/>
<line num="5" count="1" type="cond" truecount="2" falsecount="1"/>
<line num="6" count="1" type="cond" truecount="1" falsecount="1"/>
<line num="7" count="1" type="cond" truecount="1" falsecount="1"/>
<line num="8" count="1" type="cond" truecount="1" falsecount="1"/>
<line num="10" count="1" type="stmt"/>
<line num="11" count="1" type="stmt"/>
<line num="13" count="1" type="stmt"/>
<line num="15" count="1" type="cond" truecount="3" falsecount="1"/>
<line num="16" count="0" type="stmt"/>
<line num="21" count="1" type="cond" truecount="1" falsecount="1"/>
<line num="22" count="0" type="stmt"/>
<line num="28" count="1" type="stmt"/>
<line num="31" count="0" type="stmt"/>
</file>
<file name="filesController.js" path="C:\Peter\workspace\Yandex\homeworks\testing\controllers\filesController.js">
<metrics statements="18" coveredstatements="13" conditionals="16" coveredconditionals="8" methods="5" coveredmethods="3"/>
<line num="1" count="1" type="stmt"/>
<line num="6" count="1" type="stmt"/>
<line num="9" count="0" type="cond" truecount="0" falsecount="3"/>
<line num="11" count="0" type="stmt"/>
<line num="13" count="0" type="stmt"/>
<line num="15" count="0" type="stmt"/>
<line num="19" count="1" type="stmt"/>
<line num="20" count="2" type="cond" truecount="2" falsecount="1"/>
<line num="21" count="2" type="cond" truecount="1" falsecount="1"/>
<line num="22" count="2" type="cond" truecount="1" falsecount="1"/>
<line num="23" count="2" type="cond" truecount="1" falsecount="1"/>
<line num="25" count="2" type="stmt"/>
<line num="26" count="2" type="cond" truecount="2" falsecount="0"/>
<line num="28" count="2" type="cond" truecount="1" falsecount="1"/>
<line num="30" count="2" type="stmt"/>
<line num="32" count="2" type="stmt"/>
<line num="38" count="2" type="stmt"/>
<line num="44" count="0" type="stmt"/>
</file>
<file name="indexController.js" path="C:\Peter\workspace\Yandex\homeworks\testing\controllers\indexController.js">
<metrics statements="11" coveredstatements="10" conditionals="9" coveredconditionals="5" methods="4" coveredmethods="3"/>
<line num="1" count="1" type="stmt"/>
<line num="2" count="1" type="stmt"/>
<line num="4" count="1" type="stmt"/>
<line num="5" count="2" type="cond" truecount="2" falsecount="1"/>
<line num="6" count="2" type="cond" truecount="1" falsecount="1"/>
<line num="7" count="2" type="cond" truecount="1" falsecount="1"/>
<line num="8" count="2" type="cond" truecount="1" falsecount="1"/>
<line num="10" count="2" type="stmt"/>
<line num="12" count="2" type="stmt"/>
<line num="17" count="2" type="stmt"/>
<line num="23" count="0" type="stmt"/>
</file>
</package>
<package name="utils">
<metrics statements="40" coveredstatements="36" conditionals="24" coveredconditionals="19" methods="13" coveredmethods="10"/>
<file name="git.js" path="C:\Peter\workspace\Yandex\homeworks\testing\utils\git.js">
<metrics statements="25" coveredstatements="21" conditionals="13" coveredconditionals="9" methods="10" coveredmethods="7"/>
<line num="1" count="4" type="stmt"/>
<line num="2" count="4" type="stmt"/>
<line num="4" count="4" type="stmt"/>
<line num="7" count="2" type="stmt"/>
<line num="8" count="2" type="stmt"/>
<line num="9" count="2" type="cond" truecount="2" falsecount="0"/>
<line num="10" count="1" type="stmt"/>
<line num="13" count="2" type="stmt"/>
<line num="19" count="1" type="stmt"/>
<line num="21" count="1" type="stmt"/>
<line num="30" count="0" type="stmt"/>
<line num="32" count="0" type="stmt"/>
<line num="41" count="0" type="stmt"/>
<line num="49" count="1" type="stmt"/>
<line num="50" count="1" type="stmt"/>
<line num="52" count="1" type="stmt"/>
<line num="56" count="3" type="cond" truecount="2" falsecount="1"/>
<line num="57" count="3" type="cond" truecount="1" falsecount="1"/>
<line num="58" count="3" type="cond" truecount="2" falsecount="0"/>
<line num="60" count="3" type="stmt"/>
<line num="61" count="3" type="cond" truecount="2" falsecount="0"/>
<line num="63" count="3" type="stmt"/>
<line num="64" count="3" type="stmt"/>
<line num="72" count="0" type="stmt"/>
<line num="75" count="4" type="stmt"/>
</file>
<file name="navigation.js" path="C:\Peter\workspace\Yandex\homeworks\testing\utils\navigation.js">
<metrics statements="15" coveredstatements="15" conditionals="11" coveredconditionals="10" methods="3" coveredmethods="3"/>
<line num="2" count="1" type="stmt"/>
<line num="6" count="1" type="stmt"/>
<line num="10" count="4" type="stmt"/>
<line num="17" count="4" type="cond" truecount="2" falsecount="0"/>
<line num="18" count="3" type="cond" truecount="2" falsecount="0"/>
<line num="19" count="3" type="stmt"/>
<line num="22" count="3" type="stmt"/>
<line num="28" count="3" type="stmt"/>
<line num="29" count="3" type="stmt"/>
<line num="30" count="2" type="stmt"/>
<line num="31" count="2" type="stmt"/>
<line num="32" count="2" type="stmt"/>
<line num="39" count="3" type="cond" truecount="2" falsecount="0"/>
<line num="45" count="4" type="stmt"/>
<line num="48" count="4" type="stmt"/>
</file>
</package>
</metrics>
</project>
</coverage>
Loading