www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

preferences_advancedTest.js (5933B)


      1 describe("Advanced Preferences", function () {
      2 	// TODO: Debug output logging is now in the application menus, and we test in Firefox...
      3 	// Maybe add the debug output menu to Firefox for the purposes of testing?
      4 	describe.skip("General", function () {
      5 		var server;
      6 		
      7 		before(function () {
      8 			server = sinon.fakeServer.create();
      9 			server.autoRespond = true;
     10 			Zotero.HTTP.mock = sinon.FakeXMLHttpRequest;
     11 		});
     12 		
     13 		after(function () {
     14 			Zotero.HTTP.mock = null;
     15 		})
     16 		
     17 		describe("Debug Output", function () {
     18 			it("should log output and submit to server", function* () {
     19 				var win = yield loadWindow("chrome://zotero/content/preferences/preferences.xul", {
     20 					pane: 'zotero-prefpane-advanced',
     21 					tabIndex: 0
     22 				});
     23 				
     24 				// Wait for tab to load
     25 				var doc = win.document;
     26 				var prefwindow = doc.documentElement;
     27 				var defer = Zotero.Promise.defer();
     28 				var pane = doc.getElementById('zotero-prefpane-advanced');
     29 				if (!pane.loaded) {
     30 					pane.addEventListener('paneload', function () {
     31 						defer.resolve();
     32 					})
     33 					yield defer.promise;
     34 				}
     35 				
     36 				var enableButton = doc.getElementById('debug-output-enable');
     37 				enableButton.click();
     38 				yield createDataObject('item');
     39 				enableButton.click();
     40 				
     41 				server.respond(function (req) {
     42 					if (req.method == "POST") {
     43 						req.respond(
     44 							200,
     45 							{},
     46 							'<?xml version="1.0" encoding="UTF-8"?>\n'
     47 								+ '<xml><reported reportID="1234567890"/></xml>'
     48 						);
     49 					}
     50 				});
     51 				
     52 				// Make sure Debug ID is shown in dialog
     53 				var promise = waitForDialog(function (dialog) {
     54 					assert.match(dialog.document.documentElement.textContent, /D1234567890/);
     55 				});
     56 				doc.getElementById('debug-output-submit').click();
     57 				yield promise;
     58 				
     59 				win.close();
     60 			});
     61 		});
     62 	});
     63 	
     64 	describe("Files & Folders", function () {
     65 		describe("Linked Attachment Base Directory", function () {
     66 			var setBaseDirectory = Zotero.Promise.coroutine(function* (basePath) {
     67 				var win = yield loadWindow("chrome://zotero/content/preferences/preferences.xul", {
     68 					pane: 'zotero-prefpane-advanced',
     69 					tabIndex: 1
     70 				});
     71 				
     72 				// Wait for tab to load
     73 				var doc = win.document;
     74 				var prefwindow = doc.documentElement;
     75 				var defer = Zotero.Promise.defer();
     76 				var pane = doc.getElementById('zotero-prefpane-advanced');
     77 				if (!pane.loaded) {
     78 					pane.addEventListener('paneload', function () {
     79 						defer.resolve();
     80 					})
     81 					yield defer.promise;
     82 				}
     83 				
     84 				var promise = waitForDialog();
     85 				yield win.Zotero_Preferences.Attachment_Base_Directory.changePath(basePath);
     86 				yield promise;
     87 				
     88 				win.close();
     89 			});
     90 			
     91 			var clearBaseDirectory = Zotero.Promise.coroutine(function* (basePath) {
     92 				var win = yield loadWindow("chrome://zotero/content/preferences/preferences.xul", {
     93 					pane: 'zotero-prefpane-advanced',
     94 					tabIndex: 1
     95 				});
     96 				
     97 				// Wait for tab to load
     98 				var doc = win.document;
     99 				var prefwindow = doc.documentElement;
    100 				var defer = Zotero.Promise.defer();
    101 				var pane = doc.getElementById('zotero-prefpane-advanced');
    102 				if (!pane.loaded) {
    103 					pane.addEventListener('paneload', function () {
    104 						defer.resolve();
    105 					})
    106 					yield defer.promise;
    107 				}
    108 				
    109 				var promise = waitForDialog();
    110 				yield win.Zotero_Preferences.Attachment_Base_Directory.clearPath();
    111 				yield promise;
    112 				
    113 				win.close();
    114 			});
    115 			
    116 			beforeEach(function () {
    117 				Zotero.Prefs.clear('baseAttachmentPath');
    118 				Zotero.Prefs.clear('saveRelativeAttachmentPath');
    119 			});
    120 			
    121 			it("should set new base directory", function* () {
    122 				var basePath = getTestDataDirectory().path;
    123 				yield setBaseDirectory(basePath);
    124 				assert.equal(Zotero.Prefs.get('baseAttachmentPath'), basePath);
    125 				assert.isTrue(Zotero.Prefs.get('saveRelativeAttachmentPath'));
    126 			})
    127 			
    128 			it("should clear base directory", function* () {
    129 				var basePath = getTestDataDirectory().path;
    130 				yield setBaseDirectory(basePath);
    131 				yield clearBaseDirectory();
    132 				
    133 				assert.equal(Zotero.Prefs.get('baseAttachmentPath'), '');
    134 				assert.isFalse(Zotero.Prefs.get('saveRelativeAttachmentPath'));
    135 			})
    136 			
    137 			it("should change absolute path of linked attachment under new base dir to prefixed path", function* () {
    138 				var file = getTestDataDirectory();
    139 				file.append('test.png');
    140 				var attachment = yield Zotero.Attachments.linkFromFile({ file });
    141 				assert.equal(attachment.attachmentPath, file.path);
    142 				
    143 				var basePath = getTestDataDirectory().path;
    144 				yield setBaseDirectory(basePath);
    145 				
    146 				assert.equal(
    147 					attachment.attachmentPath,
    148 					Zotero.Attachments.BASE_PATH_PLACEHOLDER + 'test.png'
    149 				);
    150 			})
    151 			
    152 			it("should change prefixed path to absolute when changing base directory", function* () {
    153 				var basePath = getTestDataDirectory().path;
    154 				yield setBaseDirectory(basePath);
    155 				
    156 				var file = getTestDataDirectory();
    157 				file.append('test.png');
    158 				var attachment = yield Zotero.Attachments.linkFromFile({ file });
    159 				assert.equal(
    160 					attachment.attachmentPath,
    161 					Zotero.Attachments.BASE_PATH_PLACEHOLDER + 'test.png'
    162 				);
    163 				
    164 				var basePath = Zotero.getTempDirectory().path;
    165 				yield setBaseDirectory(basePath);
    166 				
    167 				assert.equal(attachment.attachmentPath, file.path);
    168 			})
    169 			
    170 			it("should change prefixed path to absolute when clearing base directory", function* () {
    171 				var basePath = getTestDataDirectory().path;
    172 				yield setBaseDirectory(basePath);
    173 				
    174 				var file = getTestDataDirectory();
    175 				file.append('test.png');
    176 				var attachment = yield Zotero.Attachments.linkFromFile({ file });
    177 				assert.equal(
    178 					attachment.attachmentPath,
    179 					Zotero.Attachments.BASE_PATH_PLACEHOLDER + 'test.png'
    180 				);
    181 				
    182 				yield clearBaseDirectory();
    183 				
    184 				assert.equal(Zotero.Prefs.get('baseAttachmentPath'), '');
    185 				assert.isFalse(Zotero.Prefs.get('saveRelativeAttachmentPath'));
    186 				
    187 				assert.equal(attachment.attachmentPath, file.path);
    188 			})
    189 		})
    190 	})
    191 })