github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/app/tests/acceptance/documents-space-test.js (about)

     1  // Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
     2  //
     3  // This software (Documize Community Edition) is licensed under
     4  // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
     5  //
     6  // You can operate outside the AGPL restrictions by purchasing
     7  // Documize Enterprise Edition and obtaining a commercial license
     8  // by contacting <sales@documize.com>.
     9  //
    10  // https://documize.com
    11  
    12  import { test } from 'qunit';
    13  import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
    14  
    15  moduleForAcceptance('Acceptance | Documents space');
    16  
    17  test('Adding a new folder space', function (assert) {
    18  	server.create('meta', { allowAnonymousAccess: false });
    19  	authenticateUser();
    20  	visit('/s/VzMuyEw_3WqiafcG/my-project');
    21  
    22  	andThen(function () {
    23  		let personalSpaces = find('.folders-list div:contains(PERSONAL) .list a').length;
    24  		assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
    25  		assert.equal(personalSpaces, 1, '1 personal space is listed');
    26  	});
    27  
    28  	click('#add-folder-button');
    29  
    30  	fillIn('#new-folder-name', 'Test Folder');
    31  
    32  	click('.actions div:contains(Add)');
    33  
    34  	andThen(function () {
    35  		let folderCount = find('.folders-list div:contains(PERSONAL) .list a').length;
    36  		assert.equal(folderCount, 2, 'New folder has been added');
    37  		assert.equal(currentURL(), '/s/V0Vy5Uw_3QeDAMW9/test-folder');
    38  	});
    39  
    40  });
    41  
    42  test('Adding a document to a space', function (assert) {
    43  	server.create('meta', { allowAnonymousAccess: false });
    44  	authenticateUser();
    45  	visit('/s/VzMuyEw_3WqiafcG/my-project');
    46  
    47  	andThen(function () {
    48  
    49  		let numberOfDocuments = find('.documents-list li').length;
    50  		assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
    51  		assert.equal(numberOfDocuments, 2, '2 documents listed');
    52  	});
    53  
    54  	click('.actions div:contains(Start) .flat-green');
    55  
    56  	andThen(function () {
    57  		assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/d/V4y7jkw_3QvCDSeS/new-document', 'New document displayed');
    58  	});
    59  
    60  	click('a div:contains(My Project) .space-name');
    61  
    62  	andThen(function () {
    63  		let numberOfDocuments = find('.documents-list li').length;
    64  		assert.equal(numberOfDocuments, 3, '3 documents listed');
    65  	});
    66  });
    67  
    68  test('visiting space settings page', function (assert) {
    69  	server.create('meta', { allowAnonymousAccess: false });
    70  	authenticateUser();
    71  	visit('/s/VzMuyEw_3WqiafcG/my-project');
    72  
    73  	click('#folder-settings-button');
    74  
    75  	andThen(function () {
    76  		checkForCommonAsserts();
    77  		assert.equal(find('#folderName').val().trim(), 'My Project', 'Space name displayed in input box');
    78  		assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
    79  	});
    80  });
    81  
    82  test('changing space name', function (assert) {
    83  	server.create('meta', { allowAnonymousAccess: false });
    84  	authenticateUser();
    85  	visit('/s/VzMuyEw_3WqiafcG/my-project');
    86  
    87  	click('#folder-settings-button');
    88  
    89  	fillIn('#folderName', 'Test Space');
    90  	click('.button-blue');
    91  
    92  	andThen(function () {
    93  		let spaceName = find('.info .title').text().trim();
    94  		checkForCommonAsserts();
    95  		assert.equal(spaceName, 'Test Space', 'Space name has been changed');
    96  		assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
    97  	});
    98  });
    99  
   100  test('sharing a space', function (assert) {
   101  	server.create('meta', { allowAnonymousAccess: false });
   102  	authenticateUser();
   103  	visit('/s/VzMuyEw_3WqiafcG/my-project');
   104  
   105  	click('#folder-settings-button');
   106  
   107  	click(('.sidebar-menu .options li:contains(Share)'));
   108  	fillIn('#inviteEmail', 'share-test@gmail.com');
   109  	click('.button-blue');
   110  
   111  	andThen(function () {
   112  		checkForCommonAsserts();
   113  		assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
   114  	});
   115  });
   116  
   117  test('changing space permissions', function (assert) {
   118  	server.create('meta', { allowAnonymousAccess: false });
   119  	authenticateUser();
   120  
   121  	visit('/s/VzMygEw_3WrtFzto/test');
   122  	andThen(function () {
   123  		let numberOfPublicFolders = find('.sidebar-menu .folders-list .section .list:first a').length;
   124  		assert.equal(numberOfPublicFolders, 1, '1 folder listed as public');
   125  		assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test');
   126  	});
   127  
   128  	click('#folder-settings-button');
   129  
   130  	click('.sidebar-menu .options li:contains(Permissions)');
   131  
   132  	click('tr:contains(Everyone) #canView-');
   133  	click('tr:contains(Everyone) #canEdit-');
   134  	click('.button-blue');
   135  
   136  	visit('/s/VzMygEw_3WrtFzto/test');
   137  
   138  	andThen(function () {
   139  		let numberOfPublicFolders = find('.folders-list div:contains(EVERYONE) .list a').length;
   140  		assert.equal(numberOfPublicFolders, 2, '2 folder listed as public');
   141  		assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test');
   142  	});
   143  });
   144  
   145  test('deleting a space', function (assert) {
   146  	server.create('meta', { allowAnonymousAccess: false });
   147  	authenticateUser();
   148  	visit('/s/VzMuyEw_3WqiafcG/my-project');
   149  
   150  	click('#folder-settings-button');
   151  
   152  	click('.sidebar-menu .options li:contains(Delete)');
   153  
   154  	andThen(function () {
   155  		checkForCommonAsserts();
   156  		assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
   157  	});
   158  });
   159  
   160  test('deleting a document', function (assert) {
   161  	server.create('meta', { allowAnonymousAccess: false });
   162  	authenticateUser();
   163  	visit('/s/VzMuyEw_3WqiafcG/my-project');
   164  
   165  	andThen(function () {
   166  		let deleteButton = find('#delete-documents-button');
   167  		let numberOfDocuments = find('.documents-list li');
   168  		assert.equal(numberOfDocuments.length, 2, '2 documents are displayed');
   169  		assert.equal(deleteButton.length, 0, 'Delete button not displayed');
   170  	});
   171  
   172  	click('.documents-list li:first .checkbox');
   173  
   174  	andThen(function () {
   175  		let deleteButton = find('#delete-documents-button');
   176  		assert.equal(deleteButton.length, 1, 'Delete button displayed after selecting document');
   177  	});
   178  
   179  	click('.actions div:contains(Delete) .flat-red');
   180  
   181  	andThen(function () {
   182  		let numberOfDocuments = find('.documents-list li');
   183  		assert.equal(numberOfDocuments.length, 1, '1 documents is displayed');
   184  	});
   185  });
   186  
   187  test('clicking a document title displays the document', function (assert) {
   188  	server.create('meta', { allowAnonymousAccess: false });
   189  	authenticateUser();
   190  	visit('/s/VzMygEw_3WrtFzto/test');
   191  
   192  	click('a .title:contains(README)');
   193  
   194  	andThen(function () {
   195  		findWithAssert('#add-section-button');
   196  		findWithAssert('#delete-document-button');
   197  		findWithAssert('#print-document-button');
   198  		findWithAssert('#save-template-button');
   199  		findWithAssert('#attachment-button');
   200  		findWithAssert('#set-meta-button');
   201  		findWithAssert('.name.space-name');
   202  		findWithAssert('.document-sidebar');
   203  		let title = find('.zone-header .title').text().trim();
   204  		assert.equal(title, 'README', 'document displayed correctly');
   205  		assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test/d/VzMvJEw_3WqiafcI/readme');
   206  	});
   207  });
   208  
   209  function checkForCommonAsserts() {
   210  	findWithAssert('.sidebar-menu');
   211  	findWithAssert('.options li:contains(General)');
   212  	findWithAssert('.options li:contains(Share)');
   213  	findWithAssert('.options li:contains(Permissions)');
   214  	findWithAssert('.options li:contains(Delete)');
   215  }