<commit_before>'use strict';

const { Application } = require('spectron');
const { assert } = require('chai');

const APP_PATH = './dist/Negative-darwin-x64/Negative.app/Contents/MacOS/Negative';

const IMAGE_ID = '#negativeImage';

describe('Negative', function () {
	const app = new Application({
		path: APP_PATH,
		env: {
			IGNORE_WINDOW_SETTINGS: true,
			NODE_ENV: 'development'
		}
	});
	
	before(function () {
		return app.start();
	});

	after(function () {
		if (app && app.isRunning()) {
			return app.stop();
		}
	});
	
	describe('Launch', function () {
		it('shows an initial window', function () {
			return app.client.getWindowCount().then(function (count) {
				assert.isAtLeast(count, 1);
			});
		});
	});

	describe('Menues', function () {
		describe('Negative', function () {
			after(function () {
				return app.start();
			});
			
			it('About Negative');
			it('Preferences...');
			it('Quit Negative', function () {
				return app.electron.ipcRenderer.send('test-quit-negative')
					.then(function () {
						return app.client.getWindowCount().then(function (count) {
							assert.equal(count, 0);
						});
					});
			});
		});
		
		describe('File', function () {
			it('New Tab', function () {
				return app.electron.ipcRenderer.send('test-new-tab')
					.then(function () {
						return app.client.selectorExecute('#tabs', function (element) {
							const el = element[0];
							
							return el.children && el.children.length;
						});
					})
					.then(function (tabCount) {
						assert.equal(tabCount, 2);
					});
			});
			
			it('Close Tab', function () {
				return app.electron.ipcRenderer.send('test-close-tab')
					.then(function () {
						return app.client.selectorExecute('#tabs', function (element) {
							const el = element[0];
							
							return el.children && el.children.length;
						});
					})
					.then(function (tabCount) {
						assert.equal(tabCount, 1);
					});
			});
			
			it('New Window');
			it('Close Window');
			it('Close');
		});
		
		describe('Edit', function () {
			it('Undo', function () {
				// Get some history first
				return app.electron.ipcRenderer.send('test-clear')
					.then(function () {
						return app.electron.ipcRenderer.send('test-capture');
					})
					.then(function () {
						return app.client.selectorExecute(IMAGE_ID, (element) => element[0].getAttribute('src'));
					})
					.then(function (src) {
						assert.notEqual(src, '');
					})
					.then(function () {
						return app.electron.ipcRenderer.send('test-undo');
					})
					.then(function () {
						return app.client.selectorExecute(IMAGE_ID, (element) => element[0].getAttribute('src'));
					})
					.then(function (src) {
						assert.equal(src, '');
					});
					
			});
			
			it('Redo', function () {
				// Use history from Undo test
				return app.electron.ipcRenderer.send('test-redo')
					.then(function () {
						return app.client.selectorExecute(IMAGE_ID, (element) => element[0].getAttribute('src'));
					})
					.then(function (src) {
						assert.notEqual(src, '');
					});
			});
			it('Copy', function () {
				return app.electron.ipcRenderer.send('test-capture')
					.then(function () {
						return app.electron.ipcRenderer.send('test-copy');
					})
					.then(function () {
						return app.electron.clipboard.readImage();
					})
					.then(function (image) {
						// @TODO better assertions: test type
						assert.isDefined(image);
					})
			});
			it('Paste', function () {
				return app.electron.ipcRenderer.send('test-clear')
					.then(function () {
						return app.electron.ipcRenderer.send('test-paste');
					})
					.then(function () {
						return app.client.selectorExecute(IMAGE_ID, (element) => element[0].getAttribute('src'));
					})
					.then(function (src) {
						// @TODO better assertions: test string
						assert.notEqual(src, '');
					});
			});
		});
		
		describe('View', function () {
			it('Capture', function () {
				// Clear first, then test that capturing works
				return app.electron.ipcRenderer.send('test-clear')
					.then(function () {
						return app.electron.ipcRenderer.send('test-capture');
					})
					.then(function () {
						return app.client.selectorExecute(IMAGE_ID, (element) => element[0].getAttribute('src'));
					})
					.then(function (src) {
						assert.notEqual(src, '');
					})
			});
			
			it('Clear', function () {
				// Capture first, then test that clearing works
				return app.electron.ipcRenderer.send('test-capture')
					.then(function () {
						return app.electron.ipcRenderer.send('test-clear')
					})
					.then(function () {
						return app.client.selectorExecute(IMAGE_ID, (element) => element[0].getAttribute('src'));
					})
					.then(function (src) {
						assert.equal(src, '');
					});
			});
			
			it('Actual Size');
			it('Zoom In');
			it('Zoom Out');
			it('Reload');<commit_msg>Add better assertions for checking images<commit_after>'use strict';

const { Application } = require('spectron');
const { assert } = require('chai');

const APP_PATH = './dist/Negative-darwin-x64/Negative.app/Contents/MacOS/Negative';

const IMAGE_ID = '#negativeImage';
const REGEX_BASE_64_PNG = /^data:image\/png;base64,/;

describe('Negative', function () {
	const app = new Application({
		path: APP_PATH,
		env: {
			IGNORE_WINDOW_SETTINGS: true,
			NODE_ENV: 'development'
		}
	});
	
	before(function () {
		return app.start();
	});

	after(function () {
		if (app && app.isRunning()) {
			return app.stop();
		}
	});
	
	describe('Launch', function () {
		it('shows an initial window', function () {
			return app.client.getWindowCount().then(function (count) {
				assert.isAtLeast(count, 1);
			});
		});
	});

	describe('Menues', function () {
		describe('Negative', function () {
			after(function () {
				return app.start();
			});
			
			it('About Negative');
			it('Preferences...');
			it('Quit Negative', function () {
				return app.electron.ipcRenderer.send('test-quit-negative')
					.then(function () {
						return app.client.getWindowCount().then(function (count) {
							assert.equal(count, 0);
						});
					});
			});
		});
		
		describe('File', function () {
			it('New Tab', function () {
				return app.electron.ipcRenderer.send('test-new-tab')
					.then(function () {
						return app.client.selectorExecute('#tabs', function (element) {
							const el = element[0];
							
							return el.children && el.children.length;
						});
					})
					.then(function (tabCount) {
						assert.equal(tabCount, 2);
					});
			});
			
			it('Close Tab', function () {
				return app.electron.ipcRenderer.send('test-close-tab')
					.then(function () {
						return app.client.selectorExecute('#tabs', function (element) {
							const el = element[0];
							
							return el.children && el.children.length;
						});
					})
					.then(function (tabCount) {
						assert.equal(tabCount, 1);
					});
			});
			
			it('New Window');
			it('Close Window');
			it('Close');
		});
		
		describe('Edit', function () {
			it('Undo', function () {
				// Get some history first
				return app.electron.ipcRenderer.send('test-clear')
					.then(function () {
						return app.electron.ipcRenderer.send('test-capture');
					})
					.then(function () {
						return app.client.selectorExecute(IMAGE_ID, (element) => element[0].getAttribute('src'));
					})
					.then(function (src) {
						assert.notEqual(src, '');
					})
					.then(function () {
						return app.electron.ipcRenderer.send('test-undo');
					})
					.then(function () {
						return app.client.selectorExecute(IMAGE_ID, (element) => element[0].getAttribute('src'));
					})
					.then(function (src) {
						assert.equal(src, '');
					});
					
			});
			
			it('Redo', function () {
				// Use history from Undo test
				return app.electron.ipcRenderer.send('test-redo')
					.then(function () {
						return app.client.selectorExecute(IMAGE_ID, (element) => element[0].getAttribute('src'));
					})
					.then(function (src) {
						assert.isTrue(REGEX_BASE_64_PNG.test(src));
					});
			});
			
			it('Copy', function () {
				return app.electron.ipcRenderer.send('test-capture')
					.then(function () {
						return app.electron.ipcRenderer.send('test-copy');
					})
					.then(function () {
						return app.electron.clipboard.readImage();
					})
					.then(function (image) {
						assert.isDefined(image);
						assert.isDefined(image.getSize);
					})
			});
			
			it('Paste', function () {
				return app.electron.ipcRenderer.send('test-clear')
					.then(function () {
						return app.electron.ipcRenderer.send('test-paste');
					})
					.then(function () {
						return app.client.selectorExecute(IMAGE_ID, (element) => element[0].getAttribute('src'));
					})
					.then(function (src) {
						assert.isTrue(REGEX_BASE_64_PNG.test(src));
					});
			});
		});
		
		describe('View', function () {
			it('Capture', function () {
				// Clear first, then test that capturing works
				return app.electron.ipcRenderer.send('test-clear')
					.then(function () {
						return app.electron.ipcRenderer.send('test-capture');
					})
					.then(function () {
						return app.client.selectorExecute(IMAGE_ID, (element) => element[0].getAttribute('src'));
					})
					.then(function (src) {
						assert.isTrue(REGEX_BASE_64_PNG.test(src));
					})
			});
			
			it('Clear', function () {
				// Capture first, then test that clearing works
				return app.electron.ipcRenderer.send('test-capture')
					.then(function () {
						return app.electron.ipcRenderer.send('test-clear')
					})
					.then(function () {
						return app.client.selectorExecute(IMAGE_ID, (element) => element[0].getAttribute('src'));
					})
					.then(function (src) {
						assert.equal(src, '');
					});
			});
			
			it('Actual Size');
			it('Zoom In');
			it('Zoom Out');
			it('Reload');
{'fraction_non_alphanumeric': 0.1794090770636613, 'fraction_numerical': 0.0038582597217991675, 'mean_word_length': 2.7296478606588415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '708121', 'n_tokens_mistral': 4269, 'n_tokens_neox': 3069, 'n_words': 510}