| 
									
										
										
										
											2016-03-04 14:54:12 -08:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 12:03:13 -08:00
										 |  |  | const assert = require('assert'); | 
					
						
							|  |  |  | const nativeImage = require('electron').nativeImage; | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-04 14:54:12 -08:00
										 |  |  | describe('nativeImage module', () => { | 
					
						
							|  |  |  |   describe('createFromPath(path)', () => { | 
					
						
							| 
									
										
										
										
											2016-03-07 14:19:24 -08:00
										 |  |  |     it('returns an empty image for invalid paths', () => { | 
					
						
							|  |  |  |       assert(nativeImage.createFromPath('').isEmpty()); | 
					
						
							|  |  |  |       assert(nativeImage.createFromPath('does-not-exist.png').isEmpty()); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('loads images from paths relative to the current working directory', () => { | 
					
						
							|  |  |  |       const imagePath = `.${path.sep}${path.join('spec', 'fixtures', 'assets', 'logo.png')}`; | 
					
						
							|  |  |  |       const image = nativeImage.createFromPath(imagePath); | 
					
						
							|  |  |  |       assert(!image.isEmpty()); | 
					
						
							|  |  |  |       assert.equal(image.getSize().height, 190); | 
					
						
							|  |  |  |       assert.equal(image.getSize().width, 538); | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('loads images from paths with `.` segments', () => { | 
					
						
							|  |  |  |       const imagePath = `${path.join(__dirname, 'fixtures')}${path.sep}.${path.sep}${path.join('assets', 'logo.png')}`; | 
					
						
							|  |  |  |       const image = nativeImage.createFromPath(imagePath); | 
					
						
							|  |  |  |       assert(!image.isEmpty()); | 
					
						
							|  |  |  |       assert.equal(image.getSize().height, 190); | 
					
						
							|  |  |  |       assert.equal(image.getSize().width, 538); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('loads images from path with `..` segments', () => { | 
					
						
							|  |  |  |       const imagePath = `${path.join(__dirname, 'fixtures', 'api')}${path.sep}..${path.sep}${path.join('assets', 'logo.png')}`; | 
					
						
							|  |  |  |       const image = nativeImage.createFromPath(imagePath); | 
					
						
							| 
									
										
										
										
											2016-03-04 12:03:13 -08:00
										 |  |  |       assert(!image.isEmpty()); | 
					
						
							| 
									
										
										
										
											2016-03-07 09:28:08 -08:00
										 |  |  |       assert.equal(image.getSize().height, 190); | 
					
						
							|  |  |  |       assert.equal(image.getSize().width, 538); | 
					
						
							| 
									
										
										
										
											2016-03-04 12:03:13 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |