mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-08 15:05:26 +02:00
requested changes and unit tests
This commit is contained in:
parent
d825788ffd
commit
ef30929fcd
14 changed files with 109 additions and 65 deletions
4
public/dist/main.bundle.js
vendored
4
public/dist/main.bundle.js
vendored
File diff suppressed because one or more lines are too long
2
public/dist/main.css
vendored
2
public/dist/main.css
vendored
File diff suppressed because one or more lines are too long
|
@ -42,11 +42,7 @@ export default class Writing {
|
||||||
/**
|
/**
|
||||||
* Create Editor
|
* Create Editor
|
||||||
*/
|
*/
|
||||||
this.nodes.editorWrapper = document.createElement('div');
|
this.nodes.editorWrapper = document.getElementById('codex-editor');
|
||||||
this.nodes.editorWrapper.id = 'codex-editor';
|
|
||||||
|
|
||||||
moduleEl.appendChild(this.nodes.editorWrapper);
|
|
||||||
|
|
||||||
if (settings.page) {
|
if (settings.page) {
|
||||||
this.page = settings.page;
|
this.page = settings.page;
|
||||||
}
|
}
|
||||||
|
@ -64,9 +60,13 @@ export default class Writing {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.nodes.removeButton = moduleEl.querySelector('[name="js-submit-remove"]');
|
this.nodes.removeButton = moduleEl.querySelector('[name="js-submit-remove"]');
|
||||||
this.nodes.removeButton.addEventListener('click', () => {
|
|
||||||
this.removeButtonClicked();
|
if (this.nodes.removeButton) {
|
||||||
});
|
this.nodes.removeButton.addEventListener('click', () => {
|
||||||
|
this.removeButtonClicked();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.nodes.parentIdSelector = moduleEl.querySelector('[name="parent"]');
|
this.nodes.parentIdSelector = moduleEl.querySelector('[name="parent"]');
|
||||||
this.nodes.putAboveIdSelector = moduleEl.querySelector('[name="above"]');
|
this.nodes.putAboveIdSelector = moduleEl.querySelector('[name="above"]');
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
&__button {
|
&__button {
|
||||||
@apply --button;
|
@apply --button;
|
||||||
|
@apply --button-primary;
|
||||||
margin: auto 30px auto auto;
|
margin: auto 30px auto auto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
&-button {
|
&-button {
|
||||||
@apply --button;
|
@apply --button;
|
||||||
|
@apply --button-primary;
|
||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
|
|
|
@ -10,19 +10,10 @@
|
||||||
|
|
||||||
&__save {
|
&__save {
|
||||||
@apply --button;
|
@apply --button;
|
||||||
|
@apply --button-primary;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__remove {
|
|
||||||
@apply --button;
|
|
||||||
margin-left: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__save,
|
|
||||||
&__remove {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__left {
|
&__left {
|
||||||
margin: auto 0;
|
margin: auto 0;
|
||||||
color: var(--color-text-second);
|
color: var(--color-text-second);
|
||||||
|
@ -32,3 +23,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.writing-buttons {
|
||||||
|
&__remove {
|
||||||
|
@apply --button;
|
||||||
|
@apply --button-danger;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
--color-text-second: #7B7E89;
|
--color-text-second: #7B7E89;
|
||||||
--color-line-gray: #E8E8EB;
|
--color-line-gray: #E8E8EB;
|
||||||
--color-link-active: #388AE5;
|
--color-link-active: #388AE5;
|
||||||
|
--color-button-danger: #ff1629;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Site layout sizes
|
* Site layout sizes
|
||||||
|
@ -14,17 +15,29 @@
|
||||||
|
|
||||||
--button {
|
--button {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
background: var(--color-link-active);
|
|
||||||
color: #fff;
|
color: #fff;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
padding: 9px 15px;
|
padding: 9px 15px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 1em;
|
line-height: 1em;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
margin: 0 0.3em 0 -0.05em;
|
margin: 0 0.3em 0 -0.05em;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
--button-danger {
|
||||||
|
background: var(--color-button-danger);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: color-mod(var(--color-button-danger) blackness(+10%));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
--button-primary {
|
||||||
|
background: var(--color-link-active);
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background: color-mod(var(--color-link-active) blackness(+10%));
|
background: color-mod(var(--color-link-active) blackness(+10%));
|
||||||
|
|
|
@ -68,7 +68,7 @@ class Page {
|
||||||
|
|
||||||
this.body = body || this.body;
|
this.body = body || this.body;
|
||||||
this.title = this.extractTitleFromBody();
|
this.title = this.extractTitleFromBody();
|
||||||
this._parent = parent || this._parent;
|
this._parent = parent || this._parent || "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -135,6 +135,24 @@ class PageOrder {
|
||||||
return this.order[currentPageInOrder - 1];
|
return this.order[currentPageInOrder - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns page before passed page with id
|
||||||
|
*
|
||||||
|
* @param pageId
|
||||||
|
*/
|
||||||
|
getPageAfter(pageId) {
|
||||||
|
const currentPageInOrder = this.order.indexOf(pageId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If page not found or is last
|
||||||
|
*/
|
||||||
|
if (currentPageInOrder === -1 || currentPageInOrder === this.order.length - 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.order[currentPageInOrder + 1];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns ordered list
|
* Returns ordered list
|
||||||
*
|
*
|
||||||
|
|
|
@ -115,12 +115,15 @@ router.delete('/page/:id', async (req, res) => {
|
||||||
const page = await Pages.get(pageId);
|
const page = await Pages.get(pageId);
|
||||||
const parentPageOrder = await PagesOrder.get(page._parent);
|
const parentPageOrder = await PagesOrder.get(page._parent);
|
||||||
const pageBeforeId = parentPageOrder.getPageBefore(page._id);
|
const pageBeforeId = parentPageOrder.getPageBefore(page._id);
|
||||||
|
const pageAfterId = parentPageOrder.getPageAfter(page._id);
|
||||||
|
|
||||||
let pageToReturn;
|
let responsePage;
|
||||||
if (pageBeforeId) {
|
if (pageBeforeId) {
|
||||||
pageToReturn = await Pages.get(pageBeforeId);
|
responsePage = await Pages.get(pageBeforeId);
|
||||||
|
} else if (pageAfterId) {
|
||||||
|
responsePage = await Pages.get(pageAfterId);
|
||||||
} else {
|
} else {
|
||||||
pageToReturn = page._parent !== "0" ? await Pages.get(page._parent) : null;
|
responsePage = page._parent !== "0" ? await Pages.get(page._parent) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove current page and return previous from order
|
// remove current page and return previous from order
|
||||||
|
@ -129,7 +132,7 @@ router.delete('/page/:id', async (req, res) => {
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
result: pageToReturn
|
result: responsePage
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
|
|
|
@ -44,13 +44,13 @@
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
<span class="writing-header__save" name="js-submit-save">
|
<span class="writing-header__save" name="js-submit-save">Save</span>
|
||||||
Save
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<span class="writing-header__remove" name="js-submit-remove">
|
|
||||||
Remove
|
|
||||||
</span>
|
|
||||||
</header>
|
</header>
|
||||||
|
<div id="codex-editor"></div>
|
||||||
|
<div class="writing-buttons">
|
||||||
|
{% if page._id is not empty %}
|
||||||
|
<span class="writing-buttons__remove" name="js-submit-remove">Remove</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -24,7 +24,7 @@ describe('Page model', () => {
|
||||||
expect(data._id).to.be.undefined;
|
expect(data._id).to.be.undefined;
|
||||||
expect(data.title).to.be.empty;
|
expect(data.title).to.be.empty;
|
||||||
expect(data.body).to.be.undefined;
|
expect(data.body).to.be.undefined;
|
||||||
expect(data.parent).to.be.undefined;
|
expect(data.parent).to.be.equal('0');
|
||||||
|
|
||||||
page = new Page(null);
|
page = new Page(null);
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ describe('Page model', () => {
|
||||||
expect(data._id).to.be.undefined;
|
expect(data._id).to.be.undefined;
|
||||||
expect(data.title).to.be.empty;
|
expect(data.title).to.be.empty;
|
||||||
expect(data.body).to.be.undefined;
|
expect(data.body).to.be.undefined;
|
||||||
expect(data.parent).to.be.undefined;
|
expect(data.parent).to.be.equal('0');
|
||||||
|
|
||||||
const initialData = {
|
const initialData = {
|
||||||
_id: 'page_id',
|
_id: 'page_id',
|
||||||
|
@ -58,12 +58,12 @@ describe('Page model', () => {
|
||||||
expect(data._id).to.equal(initialData._id);
|
expect(data._id).to.equal(initialData._id);
|
||||||
expect(data.title).to.equal(initialData.body.blocks[0].data.text);
|
expect(data.title).to.equal(initialData.body.blocks[0].data.text);
|
||||||
expect(data.body).to.deep.equal(initialData.body);
|
expect(data.body).to.deep.equal(initialData.body);
|
||||||
expect(data.parent).to.be.undefined;
|
expect(data.parent).to.be.equal('0');
|
||||||
|
|
||||||
expect(json._id).to.equal(initialData._id);
|
expect(json._id).to.equal(initialData._id);
|
||||||
expect(json.title).to.equal(initialData.body.blocks[0].data.text);
|
expect(json.title).to.equal(initialData.body.blocks[0].data.text);
|
||||||
expect(json.body).to.deep.equal(initialData.body);
|
expect(json.body).to.deep.equal(initialData.body);
|
||||||
expect(json.parent).to.be.undefined;
|
expect(json.parent).to.be.equal('0');
|
||||||
|
|
||||||
const update = {
|
const update = {
|
||||||
_id: 12345,
|
_id: 12345,
|
||||||
|
@ -86,7 +86,7 @@ describe('Page model', () => {
|
||||||
expect(data._id).to.equal(initialData._id);
|
expect(data._id).to.equal(initialData._id);
|
||||||
expect(data.title).to.equal(update.body.blocks[0].data.text);
|
expect(data.title).to.equal(update.body.blocks[0].data.text);
|
||||||
expect(data.body).to.equal(update.body);
|
expect(data.body).to.equal(update.body);
|
||||||
expect(data.parent).to.be.undefined;
|
expect(data.parent).to.be.equal('0');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Saving, updating and deleting model in the database', async () => {
|
it('Saving, updating and deleting model in the database', async () => {
|
||||||
|
|
|
@ -7,7 +7,7 @@ const {pagesOrder} = require('../../src/utils/database');
|
||||||
|
|
||||||
describe('PageOrder model', () => {
|
describe('PageOrder model', () => {
|
||||||
after(() => {
|
after(() => {
|
||||||
const pathToDB = path.resolve(__dirname, '../../', config.database, './pages.db');
|
const pathToDB = path.resolve(__dirname, '../../', config.database, './pagesOrder.db');
|
||||||
|
|
||||||
if (fs.existsSync(pathToDB)) {
|
if (fs.existsSync(pathToDB)) {
|
||||||
fs.unlinkSync(pathToDB);
|
fs.unlinkSync(pathToDB);
|
||||||
|
|
|
@ -19,10 +19,15 @@ describe('Pages REST: ', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
const pathToDB = path.resolve(__dirname, '../../', config.database, './pages.db');
|
const pathToPagesDB = path.resolve(__dirname, '../../', config.database, './pages.db');
|
||||||
|
const pathToPagesOrderDB = path.resolve(__dirname, '../../', config.database, './pagesOrder.db');
|
||||||
|
|
||||||
if (fs.existsSync(pathToDB)) {
|
if (fs.existsSync(pathToPagesDB)) {
|
||||||
fs.unlinkSync(pathToDB);
|
fs.unlinkSync(pathToPagesDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync(pathToPagesOrderDB)) {
|
||||||
|
fs.unlinkSync(pathToPagesOrderDB);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -229,31 +234,36 @@ describe('Pages REST: ', () => {
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
// let res = await agent
|
let res = await agent
|
||||||
// .put('/api/page')
|
.put('/api/page')
|
||||||
// .send({body});
|
.send({body});
|
||||||
//
|
|
||||||
// expect(res).to.have.status(200);
|
|
||||||
// expect(res).to.be.json;
|
|
||||||
//
|
|
||||||
// const {result: {_id}} = res.body;
|
|
||||||
|
|
||||||
// const res = await agent
|
expect(res).to.have.status(200);
|
||||||
// .delete(`/api/page/${_id}`);
|
expect(res).to.be.json;
|
||||||
//
|
|
||||||
// expect(res).to.have.status(200);
|
|
||||||
// expect(res).to.be.json;
|
|
||||||
//
|
|
||||||
// const {success, result} = res.body;
|
|
||||||
//
|
|
||||||
// expect(success).to.be.true;
|
|
||||||
// expect(result._id).to.be.undefined;
|
|
||||||
// expect(result.title).to.equal(body.blocks[0].data.text);
|
|
||||||
// expect(result.body).to.deep.equal(body);
|
|
||||||
|
|
||||||
// const deletedPage = await model.get(_id);
|
const {result: {_id}} = res.body;
|
||||||
|
console.log('_id', _id);
|
||||||
|
|
||||||
// expect(deletedPage._id).to.be.undefined;
|
res = await agent
|
||||||
|
.delete(`/api/page/${_id}`);
|
||||||
|
|
||||||
|
expect(res).to.have.status(200);
|
||||||
|
expect(res).to.be.json;
|
||||||
|
|
||||||
|
const {success, result} = res.body;
|
||||||
|
|
||||||
|
expect(success).to.be.true;
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
expect(result._id).to.be.undefined;
|
||||||
|
expect(result.title).to.equal(body.blocks[0].data.text);
|
||||||
|
expect(result.body).to.deep.equal(body);
|
||||||
|
const deletedPage = await model.get(_id);
|
||||||
|
|
||||||
|
expect(deletedPage._id).to.be.undefined;
|
||||||
|
} else {
|
||||||
|
expect(result).to.be.null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Removing page with not existing id', async () => {
|
it('Removing page with not existing id', async () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue