1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-25 08:09:43 +02:00

initial commit

This commit is contained in:
Harvey Kandola 2016-07-07 18:54:16 -07:00
commit 18933c6767
1841 changed files with 810642 additions and 0 deletions

63
app/tests/.jshintrc Normal file
View file

@ -0,0 +1,63 @@
{
"predef": [
"server",
"document",
"window",
"location",
"setTimeout",
"$",
"-Promise",
"define",
"console",
"visit",
"exists",
"fillIn",
"click",
"keyEvent",
"triggerEvent",
"find",
"findWithAssert",
"wait",
"DS",
"andThen",
"currentURL",
"currentPath",
"currentRouteName",
"stubSession",
"stubAudit",
"pauseTest",
"userLogin",
"skip",
"waitToAppear",
"waitToAppear",
"stubUserNotification",
"is",
"authenticateUser"
],
"node": false,
"browser": false,
"boss": true,
"curly": true,
"debug": false,
"devel": false,
"eqeqeq": true,
"evil": true,
"forin": false,
"immed": false,
"laxbreak": false,
"newcap": true,
"noarg": true,
"noempty": false,
"nonew": false,
"nomen": false,
"onevar": false,
"plusplus": false,
"regexp": false,
"undef": true,
"sub": true,
"strict": false,
"white": false,
"eqnull": true,
"esnext": true,
"unused": true
}

View file

@ -0,0 +1,28 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import { test } from 'qunit';
import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | Anon access disabled');
test('visiting / when not authenticated and with { allowAnonymousAccess: false } takes user to login', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
visit('/');
andThen(function () {
assert.equal(currentURL(), '/auth/login');
findWithAssert('#authEmail');
findWithAssert('#authPassword');
findWithAssert('button');
});
});

View file

@ -0,0 +1,45 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import { test } from 'qunit';
import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | Anon access enabled');
test('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function (assert) {
server.create('meta', { allowAnonymousAccess: true });
server.createList('folder', 2);
visit('/');
andThen(function () {
assert.equal(find('.login').length, 1, 'Login button is displayed');
assert.equal(find('.documents-list .document').length, 2, '2 document displayed');
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard and public spaces are displayed without being signed in');
});
});
test('visiting / when authenticated and with { allowAnonymousAccess: true } takes user to dashboard', function (assert) {
server.create('meta', { allowAnonymousAccess: true });
server.createList('folder', 2);
visit('/');
andThen(function () {
assert.equal(find('.login').length, 1, 'Login button is displayed');
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard displayed without being signed in');
});
userLogin();
andThen(function () {
assert.equal(find('.login').length, 0, 'Login button is not displayed');
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard is displayed after user is signed in');
});
});

View file

@ -0,0 +1,63 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import { test } from 'qunit';
import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | Authentication');
test('visiting /auth/login and logging in', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
visit('/auth/login');
fillIn('#authEmail', 'brizdigital@gmail.com');
fillIn('#authPassword', 'zinyando123');
click('button');
andThen(function () {
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Login successful');
});
});
test('logging out a user', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
userLogin();
visit('/auth/logout');
andThen(function () {
assert.equal(currentURL(), '/auth/login', 'Logging out successful');
});
});
test('successful sso login authenticates redirects to dashboard', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
visit('/auth/sso/OmJyaXpkaWdpdGFsQGdtYWlsLmNvbTp6aW55YW5kbzEyMw==');
andThen(function () {
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'SSO login successful');
});
});
test('sso login with bad token should redirect to login', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
visit('/auth/sso/randomToken1234567890');
andThen(function () {
assert.equal(currentURL(), '/auth/login', 'SSO login unsuccessful');
});
});

View file

@ -0,0 +1,206 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import { test, skip } from 'qunit';
import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | Documents space');
skip('Adding a new folder space', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
server.createList('permission', 4);
authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project');
andThen(function () {
let personalSpaces = find('.section div:contains(PERSONAL)').length;
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
assert.equal(personalSpaces, 1, '1 personal space is listed');
});
click('#add-folder-button');
fillIn('#new-folder-name', 'body', 'Test Folder');
click('.actions div:contains(Add)', 'body');
andThen(function () {
assert.equal(currentURL(), '/s/V0Vy5Uw_3QeDAMW9/test-folder');
});
});
skip('Adding a document to a space', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
server.createList('permission', 4);
authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project');
andThen(function () {
let numberOfDocuments = find('.documents-list li').length;
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
assert.equal(numberOfDocuments, 2, '2 documents listed');
});
click('#start-document-button');
click('.actions div:contains(Add)', 'body');
andThen(function () {
let numberOfDocuments = find('.documents-list li').length;
assert.equal(numberOfDocuments, 3, '3 documents listed');
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
});
});
test('visiting space settings page', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
server.createList('permission', 4);
authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project');
click('#folder-settings-button');
andThen(function () {
checkForCommonAsserts();
assert.equal(find('#folderName').val().trim(), 'My Project', 'Space name displayed in input box');
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
});
});
test('changing space name', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
server.createList('permission', 4);
authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project');
click('#folder-settings-button');
fillIn('#folderName', 'Test Space');
click('.button-blue');
andThen(function () {
let spaceName = find('.info .title').text().trim();
checkForCommonAsserts();
assert.equal(spaceName, 'Test Space', 'Space name has been changed');
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
});
});
test('sharing a space', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
server.createList('permission', 4);
authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project');
click('#folder-settings-button');
click(('.sidebar-menu .options li:contains(Share)'));
fillIn('#inviteEmail', 'share-test@gmail.com');
click('.button-blue');
andThen(function () {
checkForCommonAsserts();
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
});
});
// Test will pass after moving to factories
test('changing space permissions', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
server.createList('permission', 4);
authenticateUser();
visit('/s/VzMygEw_3WrtFzto/test');
andThen(function () {
let numberOfPublicFolders = find('.sidebar-menu .folders-list .section .list:first a').length;
assert.equal(numberOfPublicFolders, 1, '1 folder listed as public');
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test');
});
click('#folder-settings-button');
click('.sidebar-menu .options li:contains(Permissions)');
click('tr:contains(Everyone) #canView-');
click('tr:contains(Everyone) #canEdit-');
click('.button-blue');
visit('/s/VzMygEw_3WrtFzto/test');
andThen(function () {
let numberOfPublicFolders = find('.folders-list div:contains(EVERYONE) .list a').length;
assert.equal(numberOfPublicFolders, 2, '2 folder listed as public');
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test');
});
});
test('deleting a space', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
server.createList('permission', 4);
authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project');
click('#folder-settings-button');
click('.sidebar-menu .options li:contains(Delete)');
andThen(function () {
checkForCommonAsserts();
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
});
});
skip('deleting a document', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
server.createList('permission', 4);
authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project');
andThen(function () {
let deleteButton = find('#delete-documents-button');
let numberOfDocuments = find('.documents-list li');
assert.equal(numberOfDocuments.length, 2, '2 documents are displayed');
assert.equal(deleteButton.length, 0, 'Delete button not displayed');
});
click('.documents-list li:first .checkbox');
andThen(function () {
let deleteButton = find('#delete-documents-button');
assert.equal(deleteButton.length, 1, 'Delete button displayed after selecting document');
});
click('#delete-documents-button');
waitToAppear('.drop-content');
click('.actions div:contains(Delete)', 'body');
andThen(function () {
let numberOfDocuments = find('.documents-list li');
assert.equal(numberOfDocuments.length, 1, '1 documents is displayed');
});
});
function checkForCommonAsserts() {
findWithAssert('.sidebar-menu');
findWithAssert('.options li:contains(General)');
findWithAssert('.options li:contains(Share)');
findWithAssert('.options li:contains(Permissions)');
findWithAssert('.options li:contains(Delete)');
}

View file

@ -0,0 +1,52 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import { test } from 'qunit';
import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | user profile');
test('visiting /profile', function (assert) {
server.createList('folder', 2);
authenticateUser();
visit('/profile');
andThen(function () {
assert.equal(currentURL(), '/profile');
assert.equal(find('#firstname').val(), 'Lennex', 'Firstaname input displays correct value');
assert.equal(find('#lastname').val(), 'Zinyando', 'Lastname input displays correct value');
assert.equal(find('#email').val(), 'brizdigital@gmail.com', 'Email input displays correct value');
});
});
test('changing user details and email ', function (assert) {
server.createList('folder', 2);
authenticateUser();
visit('/profile');
andThen(function () {
assert.equal(currentURL(), '/profile');
assert.equal(find('.content .name').text().trim(), 'Lennex Zinyando', 'Profile name displayed');
assert.equal(find('#firstname').val(), 'Lennex', 'Firstaname input displays correct value');
assert.equal(find('#lastname').val(), 'Zinyando', 'Lastname input displays correct value');
assert.equal(find('#email').val(), 'brizdigital@gmail.com', 'Email input displays correct value');
});
fillIn('#firstname', 'Test');
fillIn('#lastname', 'User');
fillIn('#email', 'test.user@domain.com');
click('.button-blue');
andThen(function () {
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
assert.equal(find('.content .name').text().trim(), 'Test User', 'Profile name displayed');
});
});

View file

@ -0,0 +1,110 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import { test } from 'qunit';
import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | User Settings');
test('visiting /settings/general', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
authenticateUser();
visit('/settings/general');
andThen(function () {
assert.equal(currentURL(), '/settings/general');
assert.equal(find('#siteTitle').val(), 'EmberSherpa', 'Website title input is filled in correctly');
assert.equal(find('textarea').val(), 'This Documize instance contains all our team documentation', 'Message is set correctly');
assert.equal(find('#allowAnonymousAccess').is(':checked'), false, 'Allow anonymouus checkbox is unchecked');
});
});
test('changing the Website title and description', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
authenticateUser();
visit('/settings/general');
andThen(function () {
let websiteTitle = find('.content .title').text().trim();
let websiteTitleInput = find('#siteTitle').val();
assert.equal(websiteTitleInput, websiteTitle, 'Website title is set to EmberSherpa');
});
fillIn('#siteTitle', 'Documize Tests');
click('.button-blue');
andThen(function () {
let websiteTitle = find('.content .title').text().trim();
let websiteTitleInput = find('#siteTitle').val();
assert.equal(websiteTitleInput, websiteTitle, 'Website title is set to Documize Tests');
});
});
test('visiting /settings/folders', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
authenticateUser();
visit('/settings/folders');
andThen(function () {
checkForCommonAsserts();
assert.equal(currentURL(), '/settings/folders');
});
});
test('visiting /settings/users', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
authenticateUser();
visit('/settings/users');
andThen(function () {
checkForCommonAsserts();
findWithAssert('.user-list');
let numberOfUsers = find('.user-list tr').length;
assert.equal(numberOfUsers, 3, '2 Users listed');
assert.equal(currentURL(), '/settings/users');
});
});
test('add a new user', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
authenticateUser();
visit('/settings/users');
andThen(function () {
checkForCommonAsserts();
findWithAssert('.user-list');
let numberOfUsers = find('.user-list tr').length;
assert.equal(numberOfUsers, 3, '2 Users listed');
assert.equal(currentURL(), '/settings/users');
});
fillIn('#newUserFirstname', 'Test');
fillIn('#newUserLastname', 'User');
fillIn('#newUserEmail', 'test.user@domain.com');
click('.button-blue');
// waitToAppear('.user-notification:contains(Added)');
// waitToDisappear('.user-notification:contains(Added)');
andThen(function () {
let numberOfUsers = find('.user-list tr').length;
assert.equal(numberOfUsers, 4, '3 Users listed');
assert.equal(currentURL(), '/settings/users');
});
});
function checkForCommonAsserts() {
findWithAssert('.sidebar-menu');
findWithAssert('#user-button');
findWithAssert('#accounts-button');
findWithAssert('.info .title');
}

View file

@ -0,0 +1,48 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import Ember from 'ember';
import { authenticateSession } from 'documize/tests/helpers/ember-simple-auth';
const {
merge
} = Ember;
export default Ember.Test.registerAsyncHelper('authenticateUser', function (app, attrs = {}) {
authenticateSession(app, merge({
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
user: {
"id": "VzMuyEw_3WqiafcE",
"created": "2016-05-11T15:08:24Z",
"revised": "2016-05-11T15:08:24Z",
"firstname": "Lennex",
"lastname": "Zinyando",
"email": "brizdigital@gmail.com",
"initials": "LZ",
"active": true,
"editor": true,
"admin": true,
"accounts": [{
"id": "VzMuyEw_3WqiafcF",
"created": "2016-05-11T15:08:24Z",
"revised": "2016-05-11T15:08:24Z",
"admin": true,
"editor": true,
"userId": "VzMuyEw_3WqiafcE",
"orgId": "VzMuyEw_3WqiafcD",
"company": "EmberSherpa",
"title": "EmberSherpa",
"message": "This Documize instance contains all our team documentation",
"domain": ""
}]
}
}, attrs));
});

View file

@ -0,0 +1,6 @@
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
server.shutdown();
}

View file

@ -0,0 +1,32 @@
import { module } from 'qunit';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
export default function(name, options = {}) {
module(name, {
beforeEach() {
this.application = startApp();
stubAudit(this);
stubUserNotification(this);
if (options.beforeEach) {
options.beforeEach.apply(this, arguments);
}
this.register = (fullName, Factory) => {
let instance = this.application.__deprecatedInstance__;
let registry = instance.register ? instance : instance.registry;
return registry.register(fullName, Factory);
};
},
afterEach() {
destroyApp(this.application);
if (options.afterEach) {
options.afterEach.apply(this, arguments);
}
}
});
}

View file

@ -0,0 +1,11 @@
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;

View file

@ -0,0 +1,24 @@
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
import './stub-audit';
import './user-login';
import './wait-to-appear';
import './wait-to-disappear';
import './stub-user-notification';
import './authenticate-user';
export default function startApp(attrs) {
let application;
let attributes = Ember.merge({}, config.APP);
attributes = Ember.merge(attributes, attrs); // use defaults, but you can override;
Ember.run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}

View file

@ -0,0 +1,52 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import Ember from 'ember';
// import netUtil from 'documize/utils/net';
const Audit = Ember.Service.extend({
sessionService: Ember.inject.service('session'),
ready: false,
enabled: true,
init() {
this.start();
},
record(id) {
if (!this.get('enabled')) {
return;
}
if (!this.get('ready')) {
this.start();
}
return id;
},
stop() {},
start() {
let session = this.get('sessionService');
if (!this.get('enabled') || !session.authenticated || this.get('ready')) {
return;
}
this.set('ready', true);
},
});
export default Ember.Test.registerAsyncHelper('stubAudit', function (app, test, attrs = {}) {
test.register('service:audit', Audit.extend(attrs));
});

View file

@ -0,0 +1,32 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import Ember from 'ember';
const userNotification = Ember.Component.extend({
notifications: [],
didInsertElement() {
// this.eventBus.subscribe('notifyUser', this, 'notifyHandler');
},
willDestroyElement() {
// this.eventBus.unsubscribe('notifyUser');
},
showNotification(msg) {
return msg;
}
});
export default Ember.Test.registerAsyncHelper('stubUserNotification', function (app, test, attrs = {}) {
test.register('component:userNotification', userNotification.extend(attrs));
});

View file

@ -0,0 +1,20 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import Ember from 'ember';
export default Ember.Test.registerAsyncHelper('userLogin', function () {
visit('/auth/login');
fillIn('#authEmail', 'brizdigital@gmail.com');
fillIn('#authPassword', 'zinyando123');
click('button');
});

View file

@ -0,0 +1,32 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import Ember from 'ember';
function isVisible(selector) {
return $(selector).length > 0;
}
function checkVisibility(selector, interval, resolve, visibility) {
if (isVisible(selector) === visibility) {
resolve($(selector));
} else {
Ember.run.later(null, function () {
checkVisibility(selector, interval, resolve, visibility);
}, interval);
}
}
export default Ember.Test.registerAsyncHelper('waitToAppear', function (app, selector, interval = 200) {
return new Ember.RSVP.Promise(function (resolve) {
checkVisibility(selector, interval, resolve, true);
});
});

View file

@ -0,0 +1,32 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import Ember from 'ember';
function isVisible(selector) {
return $(selector).length > 0;
}
function checkVisibility(selector, interval, resolve, visibility) {
if (isVisible(selector) === visibility) {
resolve($(selector));
} else {
Ember.run.later(null, function () {
checkVisibility(selector, interval, resolve, visibility);
}, interval);
}
}
export default Ember.Test.registerAsyncHelper('waitToDisappear', function (app, selector, interval = 200) {
return new Ember.RSVP.Promise(function (resolve) {
checkVisibility(selector, interval, resolve, false);
});
});

51
app/tests/index.html Normal file
View file

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Documize Tests</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="dbname" content="{{.DBname}}" />
<meta property="dbhash" content="{{.DBhash}}" />
<meta name="author" content="Documize" />
<style>
#ember-testing-container, #ember-testing-container * {
/* Set position static to short-circuit Hubspot Tether's positioning */
/* https://github.com/HubSpot/tether/pull/98/ */
position: static !important;
}
.tether-container * {
z-index: 9999;
}
</style>
{{content-for "head"}}
{{content-for "test-head"}}
<link rel="stylesheet" href="assets/vendor.css">
<link rel="stylesheet" href="assets/documize.css">
<link rel="stylesheet" href="assets/test-support.css" />
{{content-for "head-footer"}}
{{content-for "test-head-footer"}}
</head>
<body>
{{content-for "body"}}
{{content-for "test-body"}}
<script src="testem.js" integrity=""></script>
<script src="assets/vendor.js"></script>
<script src="assets/test-support.js"></script>
<script src="assets/documize.js"></script>
<script src="assets/tests.js"></script>
<script src="assets/test-loader.js"></script>
{{content-for "body-footer"}}
{{content-for "test-body-footer"}}
</body>
</html>

6
app/tests/test-helper.js Normal file
View file

@ -0,0 +1,6 @@
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);

View file

@ -0,0 +1,23 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import { moduleFor, test } from 'ember-qunit';
moduleFor('service:local-storage', 'Unit | Service | local storage', {
// Specify the other units that are required for this test.
// needs: ['service:foo']
});
// Replace this with your real tests.
test('it exists', function (assert) {
let service = this.subject();
assert.ok(service);
});

View file

@ -0,0 +1,262 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import toc from 'documize/utils/toc';
import models from 'documize/utils/model';
import { module, test } from 'qunit';
module('Unit | Utility | toc');
test('toc can only move down', function (assert) {
let pages = [];
pages.pushObject(models.PageModel.create({ id: "1", level: 1, sequence: 1024 })); //testing
pages.pushObject(models.PageModel.create({ id: "2", level: 1, sequence: 1024 * 2 }));
let state = toc.getState(pages, pages[0]);
assert.equal(state.tocTools.upTarget, '', 'Has no up target');
assert.equal(state.tocTools.downTarget, '2', 'Has down target');
assert.equal(state.tocTools.allowIndent, false, 'Cannot indent');
assert.equal(state.tocTools.allowOutdent, false, 'Cannot outdent');
});
test('toc can move up or indent', function (assert) {
let pages = [];
pages.pushObject(models.PageModel.create({ id: "1", level: 1, sequence: 1024 }));
pages.pushObject(models.PageModel.create({ id: "2", level: 1, sequence: 1024 * 2 })); //testing
let state = toc.getState(pages, pages[1]);
assert.equal(state.tocTools.upTarget, '1', 'Has up target');
assert.equal(state.tocTools.downTarget, '', 'Has no down target');
assert.equal(state.tocTools.allowIndent, true, 'Can indent');
assert.equal(state.tocTools.allowOutdent, false, 'Cannot outdent');
});
test('toc can only outdent', function (assert) {
let pages = [];
pages.pushObject(models.PageModel.create({ id: "1", level: 1, sequence: 1024 }));
pages.pushObject(models.PageModel.create({ id: "2", level: 1, sequence: 1024 * 2 }));
pages.pushObject(models.PageModel.create({ id: "3", level: 2, sequence: 1024 * 3 })); // testing
pages.pushObject(models.PageModel.create({ id: "4", level: 1, sequence: 1024 * 4 }));
let state = toc.getState(pages, pages[2]);
assert.equal(state.tocTools.upTarget, '', 'Has no up target');
assert.equal(state.tocTools.downTarget, '', 'Has no down target');
assert.equal(state.tocTools.allowIndent, false, 'Cannot indent');
assert.equal(state.tocTools.allowOutdent, true, 'Can outdent');
});
test('toc child can move up or indent', function (assert) {
let pages = [];
pages.pushObject(models.PageModel.create({ id: "1", level: 1, sequence: 1024 }));
pages.pushObject(models.PageModel.create({ id: "2", level: 1, sequence: 1024 * 2 }));
pages.pushObject(models.PageModel.create({ id: "3", level: 2, sequence: 1024 * 3 })); // testing
pages.pushObject(models.PageModel.create({ id: "4", level: 1, sequence: 1024 * 4 }));
let page = pages[3];
let state = toc.getState(pages, page);
assert.equal(state.tocTools.upTarget, '2', 'Has up target');
assert.equal(state.tocTools.downTarget, '', 'Has no down target');
assert.equal(state.tocTools.allowIndent, true, 'Can indent');
assert.equal(state.tocTools.allowOutdent, false, 'Cannot outdent');
let pendingChanges = toc.indent(state, pages, page);
assert.equal(pendingChanges.length, 1, 'Has 1 pending change');
assert.equal(pendingChanges[0].pageId, 4);
assert.equal(pendingChanges[0].level, 2);
});
test('toc top node can indent two places', function (assert) {
let pages = [];
pages.pushObject(models.PageModel.create({ id: "1", level: 1, sequence: 1024 }));
pages.pushObject(models.PageModel.create({ id: "2", level: 1, sequence: 1024 * 2 }));
pages.pushObject(models.PageModel.create({ id: "3", level: 2, sequence: 1024 * 3 }));
pages.pushObject(models.PageModel.create({ id: "4", level: 3, sequence: 1024 * 4 }));
pages.pushObject(models.PageModel.create({ id: "5", level: 1, sequence: 1024 * 5 })); // testing
let page = pages[4];
let state = toc.getState(pages, page);
assert.equal(state.tocTools.upTarget, '2', 'Has up target');
assert.equal(state.tocTools.downTarget, '', 'Has no down target');
assert.equal(state.tocTools.allowIndent, true, 'Can indent');
assert.equal(state.tocTools.allowOutdent, false, 'Cannot outdent');
let pendingChanges = toc.indent(state, pages, page);
assert.equal(pendingChanges.length, 1, 'Has 1 pending change');
assert.equal(pendingChanges[0].pageId, 5);
assert.equal(pendingChanges[0].level, 3);
});
test('toc top node with kids can indent two places', function (assert) {
let pages = [];
pages.pushObject(models.PageModel.create({ id: "1", level: 1, sequence: 1024 }));
pages.pushObject(models.PageModel.create({ id: "2", level: 1, sequence: 1024 * 2 }));
pages.pushObject(models.PageModel.create({ id: "3", level: 2, sequence: 1024 * 3 }));
pages.pushObject(models.PageModel.create({ id: "4", level: 3, sequence: 1024 * 4 }));
pages.pushObject(models.PageModel.create({ id: "5", level: 1, sequence: 1024 * 5 })); // testing
pages.pushObject(models.PageModel.create({ id: "6", level: 2, sequence: 1024 * 6 })); // testing
pages.pushObject(models.PageModel.create({ id: "7", level: 3, sequence: 1024 * 7 })); // testing
let page = pages[4];
let state = toc.getState(pages, page);
assert.equal(state.tocTools.upTarget, '2', 'Has up target');
assert.equal(state.tocTools.downTarget, '', 'Has no down target');
assert.equal(state.tocTools.allowIndent, true, 'Can indent');
assert.equal(state.tocTools.allowOutdent, false, 'Cannot outdent');
let pendingChanges = toc.indent(state, pages, page);
assert.equal(pendingChanges.length, 3, 'Has 1 pending change');
assert.equal(pendingChanges[0].pageId, 5);
assert.equal(pendingChanges[0].level, 3);
assert.equal(pendingChanges[1].pageId, 6);
assert.equal(pendingChanges[1].level, 4);
assert.equal(pendingChanges[2].pageId, 7);
assert.equal(pendingChanges[2].level, 5);
});
test('toc same level node with kids can indent one place', function (assert) {
let pages = [];
pages.pushObject(models.PageModel.create({ id: "1", level: 1, sequence: 1024 }));
pages.pushObject(models.PageModel.create({ id: "2", level: 1, sequence: 1024 * 2 }));
pages.pushObject(models.PageModel.create({ id: "3", level: 2, sequence: 1024 * 3 }));
pages.pushObject(models.PageModel.create({ id: "4", level: 2, sequence: 1024 * 4 })); // testing
pages.pushObject(models.PageModel.create({ id: "5", level: 3, sequence: 1024 * 5 }));
pages.pushObject(models.PageModel.create({ id: "6", level: 1, sequence: 1024 * 6 }));
pages.pushObject(models.PageModel.create({ id: "7", level: 2, sequence: 1024 * 7 }));
let page = pages[3];
let state = toc.getState(pages, page);
assert.equal(state.tocTools.upTarget, '3', 'Has up target');
assert.equal(state.tocTools.downTarget, '', 'Has no down target');
assert.equal(state.tocTools.allowIndent, true, 'Can indent');
assert.equal(state.tocTools.allowOutdent, true, 'Can outdent');
let pendingChanges = toc.indent(state, pages, page);
assert.equal(pendingChanges.length, 2, 'Has 2 pending changes');
assert.equal(pendingChanges[0].pageId, 4);
assert.equal(pendingChanges[0].level, 3);
assert.equal(pendingChanges[1].pageId, 5);
assert.equal(pendingChanges[1].level, 4);
});
test('toc child with deep tree moves correctly', function (assert) {
let pages = [];
pages.pushObject(models.PageModel.create({ id: "1", level: 1, sequence: 1024 }));
pages.pushObject(models.PageModel.create({ id: "2", level: 1, sequence: 1024 * 2 }));
pages.pushObject(models.PageModel.create({ id: "3", level: 2, sequence: 1024 * 4 })); // testing
pages.pushObject(models.PageModel.create({ id: "4", level: 3, sequence: 1024 * 5 })); // testing
pages.pushObject(models.PageModel.create({ id: "5", level: 3, sequence: 1024 * 6 })); // testing
pages.pushObject(models.PageModel.create({ id: "6", level: 3, sequence: 1024 * 7 })); // testing
pages.pushObject(models.PageModel.create({ id: "7", level: 1, sequence: 1024 * 8 }));
pages.pushObject(models.PageModel.create({ id: "8", level: 1, sequence: 1024 * 9 }));
pages.pushObject(models.PageModel.create({ id: "9", level: 1, sequence: 1024 * 10 }));
let page = pages[2];
let state = toc.getState(pages, page);
assert.equal(state.tocTools.upTarget, '', 'Has no up target');
assert.equal(state.tocTools.downTarget, '', 'Has no down target');
assert.equal(state.tocTools.allowIndent, false, 'Cannot indent');
assert.equal(state.tocTools.allowOutdent, true, 'Can outdent');
let pendingChanges = toc.outdent(state, pages, page);
assert.equal(pendingChanges.length, 4, 'Have 4 pending changes');
assert.equal(pendingChanges[0].pageId, 3);
assert.equal(pendingChanges[0].level, 1);
assert.equal(pendingChanges[1].pageId, 4);
assert.equal(pendingChanges[1].level, 2);
assert.equal(pendingChanges[2].pageId, 5);
assert.equal(pendingChanges[2].level, 2);
assert.equal(pendingChanges[3].pageId, 6);
assert.equal(pendingChanges[3].level, 2);
});
test('toc top level node skips down some', function (assert) {
let pages = [];
pages.pushObject(models.PageModel.create({ id: "1", level: 1, sequence: 110 })); // testing
pages.pushObject(models.PageModel.create({ id: "2", level: 1, sequence: 220 }));
pages.pushObject(models.PageModel.create({ id: "3", level: 2, sequence: 330 }));
pages.pushObject(models.PageModel.create({ id: "4", level: 3, sequence: 440 }));
pages.pushObject(models.PageModel.create({ id: "5", level: 3, sequence: 550 }));
pages.pushObject(models.PageModel.create({ id: "6", level: 3, sequence: 660 }));
pages.pushObject(models.PageModel.create({ id: "7", level: 1, sequence: 770 }));
pages.pushObject(models.PageModel.create({ id: "8", level: 1, sequence: 880 }));
pages.pushObject(models.PageModel.create({ id: "9", level: 1, sequence: 990 }));
let page = pages[0];
let state = toc.getState(pages, page);
assert.equal(state.tocTools.upTarget, '', 'Has no up target');
assert.equal(state.tocTools.downTarget, '2', 'Has down target');
assert.equal(state.tocTools.allowIndent, false, 'Cannot indent');
assert.equal(state.tocTools.allowOutdent, false, 'Cannot outdent');
let pendingChanges = toc.moveDown(state, pages, page);
assert.equal(pendingChanges.length, 1, 'Have 1 pending change');
assert.equal(pendingChanges[0].pageId, 1);
assert.equal(pendingChanges[0].sequence, (660 + 770) / 2);
});
test('toc top level node skips up some', function (assert) {
let pages = [];
pages.pushObject(models.PageModel.create({ id: "1", level: 1, sequence: 110 }));
pages.pushObject(models.PageModel.create({ id: "2", level: 1, sequence: 220 }));
pages.pushObject(models.PageModel.create({ id: "3", level: 2, sequence: 330 }));
pages.pushObject(models.PageModel.create({ id: "4", level: 3, sequence: 440 }));
pages.pushObject(models.PageModel.create({ id: "5", level: 3, sequence: 550 }));
pages.pushObject(models.PageModel.create({ id: "6", level: 3, sequence: 660 }));
pages.pushObject(models.PageModel.create({ id: "7", level: 1, sequence: 770 })); // testing
pages.pushObject(models.PageModel.create({ id: "8", level: 1, sequence: 880 }));
pages.pushObject(models.PageModel.create({ id: "9", level: 1, sequence: 990 }));
let page = pages[6];
let state = toc.getState(pages, page);
assert.equal(state.tocTools.upTarget, '2', 'Has up target');
assert.equal(state.tocTools.downTarget, '8', 'Has down target');
assert.equal(state.tocTools.allowIndent, true, 'Can indent');
assert.equal(state.tocTools.allowOutdent, false, 'Cannot outdent');
let pendingChanges = toc.moveUp(state, pages, page);
assert.equal(pendingChanges.length, 1, 'Has 1 pending change');
assert.equal(pendingChanges[0].pageId, 7);
assert.equal(pendingChanges[0].sequence, (110 + 220) / 2);
});
test('toc move down top node to bottom', function (assert) {
let pages = [];
pages.pushObject(models.PageModel.create({ id: "1", level: 1, sequence: 110 }));
pages.pushObject(models.PageModel.create({ id: "2", level: 1, sequence: 220 }));
pages.pushObject(models.PageModel.create({ id: "3", level: 2, sequence: 330 }));
let page = pages[0];
let state = toc.getState(pages, page);
assert.equal(state.tocTools.upTarget, '', 'Has no up target');
assert.equal(state.tocTools.downTarget, '2', 'Has down target');
assert.equal(state.tocTools.allowIndent, false, 'Cannot indent');
assert.equal(state.tocTools.allowOutdent, false, 'Cannot outdent');
let pendingChanges = toc.moveDown(state, pages, page);
assert.equal(pendingChanges.length, 1, 'Has 1 pending change');
assert.equal(pendingChanges[0].pageId, 1);
assert.equal(pendingChanges[0].sequence, 330 * 2);
});