.circleci
.github
.vscode
__mocks__
app
flow-typed
public
server
__mocks__
__snapshots__
api
auth
commands
config
emails
middlewares
migrations
models
ApiKey.js
Attachment.js
Authentication.js
Backlink.js
Collection.js
Collection.test.js
CollectionGroup.js
CollectionUser.js
Document.js
Document.test.js
Event.js
Group.js
Group.test.js
GroupUser.js
Integration.js
Notification.js
NotificationSetting.js
Revision.js
Share.js
Star.js
Team.js
Team.test.js
User.js
User.test.js
View.js
index.js
onboarding
pages
policies
presenters
services
static
test
utils
.jestconfig.json
app.js
errors.js
events.js
index.js
logistics.js
mailer.js
mailer.test.js
redis.js
routes.js
routes.test.js
sequelize.js
slack.js
shared
.babelrc
.env.sample
.eslintignore
.eslintrc
.flowconfig
.gitignore
.sequelizerc
CODE_OF_CONDUCT.md
Dockerfile
LICENSE
Makefile
Procfile
README.md
SECURITY.md
app.json
docker-compose.yml
index.js
init.js
package.json
setupJest.js
webpack.config.dev.js
webpack.config.js
webpack.config.prod.js
yarn.lock
* WIP * document migration * fix: Handle clashing keyboard events * fix: convert getSummary * fix: parseDocumentIds * lint * fix: Remove unused plugin * Move editor version to header Add editor version check for API endpoints * fix: Editor update auto-reload Bump RME * test * bump rme * Remove slate flow types, improve themeing, bump rme * bump rme * fix: parseDocumentIds returning duplicate ID's, improved regression tests * test * fix: Missing code styles * lint * chore: Upgrade v2 migration to use AST * Bump RME * Update welcome doc * add highlight to keyboard shortcuts ref * theming improvements * fix: Code comments show as headings, closes #1255 * loop * fix: TOC highlighting * lint * add: Automated backup of docs before migration * Update embeds to new format * fix: React warning * bump to final editor version 10.0.0 * test
195 lines
4.4 KiB
JavaScript
195 lines
4.4 KiB
JavaScript
/* eslint-disable flowtype/require-valid-file-annotation */
|
|
import { flushdb } from '../test/support';
|
|
import { Document } from '../models';
|
|
import { buildDocument, buildCollection, buildTeam } from '../test/factories';
|
|
|
|
beforeEach(flushdb);
|
|
beforeEach(jest.resetAllMocks);
|
|
|
|
describe('#getSummary', () => {
|
|
test('should strip markdown', async () => {
|
|
const document = await buildDocument({
|
|
version: 1,
|
|
text: `*paragraph*
|
|
|
|
paragraph 2`,
|
|
});
|
|
|
|
expect(document.getSummary()).toBe('paragraph');
|
|
});
|
|
|
|
test('should strip title when no version', async () => {
|
|
const document = await buildDocument({
|
|
version: null,
|
|
text: `# Heading
|
|
|
|
*paragraph*`,
|
|
});
|
|
|
|
expect(document.getSummary()).toBe('paragraph');
|
|
});
|
|
});
|
|
|
|
describe('#migrateVersion', () => {
|
|
test('should maintain empty paragraph under headings', async () => {
|
|
const document = await buildDocument({
|
|
version: 1,
|
|
text: `# Heading
|
|
|
|
paragraph`,
|
|
});
|
|
await document.migrateVersion();
|
|
expect(document.text).toBe(`# Heading
|
|
|
|
paragraph`);
|
|
});
|
|
|
|
test('should add breaks under headings with extra paragraphs', async () => {
|
|
const document = await buildDocument({
|
|
version: 1,
|
|
text: `# Heading
|
|
|
|
|
|
paragraph`,
|
|
});
|
|
await document.migrateVersion();
|
|
expect(document.text).toBe(`# Heading
|
|
|
|
|
|
\\
|
|
paragraph`);
|
|
});
|
|
|
|
test('should add breaks between paragraphs', async () => {
|
|
const document = await buildDocument({
|
|
version: 1,
|
|
text: `paragraph
|
|
|
|
paragraph`,
|
|
});
|
|
await document.migrateVersion();
|
|
expect(document.text).toBe(`paragraph
|
|
|
|
\\
|
|
paragraph`);
|
|
});
|
|
|
|
test('should add breaks for multiple empty paragraphs', async () => {
|
|
const document = await buildDocument({
|
|
version: 1,
|
|
text: `paragraph
|
|
|
|
|
|
paragraph`,
|
|
});
|
|
await document.migrateVersion();
|
|
expect(document.text).toBe(`paragraph
|
|
|
|
\\
|
|
\\
|
|
paragraph`);
|
|
});
|
|
|
|
test('should add breaks with non-latin characters', async () => {
|
|
const document = await buildDocument({
|
|
version: 1,
|
|
text: `除。
|
|
|
|
通`,
|
|
});
|
|
await document.migrateVersion();
|
|
expect(document.text).toBe(`除。
|
|
|
|
\\
|
|
通`);
|
|
});
|
|
|
|
test('should update task list formatting', async () => {
|
|
const document = await buildDocument({
|
|
version: 1,
|
|
text: `[ ] list item
|
|
`,
|
|
});
|
|
await document.migrateVersion();
|
|
expect(document.text).toBe(`- [ ] list item
|
|
`);
|
|
});
|
|
|
|
test('should update task list with multiple items', async () => {
|
|
const document = await buildDocument({
|
|
version: 1,
|
|
text: `[ ] list item
|
|
[ ] list item 2
|
|
`,
|
|
});
|
|
await document.migrateVersion();
|
|
expect(document.text).toBe(`- [ ] list item
|
|
- [ ] list item 2
|
|
`);
|
|
});
|
|
|
|
test('should update checked task list formatting', async () => {
|
|
const document = await buildDocument({
|
|
version: 1,
|
|
text: `[x] list item
|
|
`,
|
|
});
|
|
await document.migrateVersion();
|
|
expect(document.text).toBe(`- [x] list item
|
|
`);
|
|
});
|
|
|
|
test('should update nested task list formatting', async () => {
|
|
const document = await buildDocument({
|
|
version: 1,
|
|
text: `[x] list item
|
|
[ ] list item
|
|
[x] list item
|
|
`,
|
|
});
|
|
await document.migrateVersion();
|
|
expect(document.text).toBe(`- [x] list item
|
|
- [ ] list item
|
|
- [x] list item
|
|
`);
|
|
});
|
|
});
|
|
|
|
describe('#searchForTeam', () => {
|
|
test('should return search results from public collections', async () => {
|
|
const team = await buildTeam();
|
|
const collection = await buildCollection({ teamId: team.id });
|
|
const document = await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
title: 'test',
|
|
});
|
|
|
|
const results = await Document.searchForTeam(team, 'test');
|
|
expect(results.length).toBe(1);
|
|
expect(results[0].document.id).toBe(document.id);
|
|
});
|
|
|
|
test('should not return search results from private collections', async () => {
|
|
const team = await buildTeam();
|
|
const collection = await buildCollection({
|
|
private: true,
|
|
teamId: team.id,
|
|
});
|
|
await buildDocument({
|
|
teamId: team.id,
|
|
collectionId: collection.id,
|
|
title: 'test',
|
|
});
|
|
|
|
const results = await Document.searchForTeam(team, 'test');
|
|
expect(results.length).toBe(0);
|
|
});
|
|
|
|
test('should handle no collections', async () => {
|
|
const team = await buildTeam();
|
|
const results = await Document.searchForTeam(team, 'test');
|
|
expect(results.length).toBe(0);
|
|
});
|
|
});
|