|
1 | | -import { describe, it, expect } from 'react-native-harness'; |
2 | | -import { Images } from 'react-native-nitro-image'; |
| 1 | +import { describe, expect, it } from 'react-native-harness' |
| 2 | +import { Images } from 'react-native-nitro-image' |
3 | 3 |
|
4 | 4 | const makeImage = () => |
5 | | - Images.createBlankImage(16, 16, false, { r: 0, g: 0, b: 1, a: 1 }); |
| 5 | + Images.createBlankImage(16, 16, false, { r: 0, g: 0, b: 1, a: 1 }) |
6 | 6 |
|
7 | 7 | describe('Image - toRawPixelData', () => { |
8 | 8 | it('returns a non-empty pixel buffer with matching dimensions', () => { |
9 | | - const image = makeImage(); |
10 | | - const raw = image.toRawPixelData(); |
11 | | - expect(raw.width).toBe(16); |
12 | | - expect(raw.height).toBe(16); |
13 | | - expect(raw.buffer.byteLength).toBeGreaterThan(0); |
14 | | - expect(typeof raw.pixelFormat).toBe('string'); |
15 | | - }); |
| 9 | + const image = makeImage() |
| 10 | + const raw = image.toRawPixelData() |
| 11 | + expect(raw.width).toBe(16) |
| 12 | + expect(raw.height).toBe(16) |
| 13 | + expect(raw.buffer.byteLength).toBeGreaterThan(0) |
| 14 | + expect(typeof raw.pixelFormat).toBe('string') |
| 15 | + }) |
16 | 16 |
|
17 | 17 | it('toRawPixelDataAsync resolves with pixel data', async () => { |
18 | | - const image = makeImage(); |
19 | | - const raw = await image.toRawPixelDataAsync(); |
20 | | - expect(raw.buffer.byteLength).toBeGreaterThan(0); |
21 | | - }); |
22 | | -}); |
| 18 | + const image = makeImage() |
| 19 | + const raw = await image.toRawPixelDataAsync() |
| 20 | + expect(raw.buffer.byteLength).toBeGreaterThan(0) |
| 21 | + }) |
| 22 | +}) |
23 | 23 |
|
24 | 24 | describe('Image - toEncodedImageData', () => { |
25 | 25 | it('encodes to PNG', () => { |
26 | | - const image = makeImage(); |
27 | | - const encoded = image.toEncodedImageData('png'); |
28 | | - expect(encoded.imageFormat).toBe('png'); |
29 | | - expect(encoded.width).toBe(16); |
30 | | - expect(encoded.height).toBe(16); |
31 | | - expect(encoded.buffer.byteLength).toBeGreaterThan(0); |
32 | | - }); |
| 26 | + const image = makeImage() |
| 27 | + const encoded = image.toEncodedImageData('png') |
| 28 | + expect(encoded.imageFormat).toBe('png') |
| 29 | + expect(encoded.width).toBe(16) |
| 30 | + expect(encoded.height).toBe(16) |
| 31 | + expect(encoded.buffer.byteLength).toBeGreaterThan(0) |
| 32 | + }) |
33 | 33 |
|
34 | 34 | it('encodes to JPEG with quality', async () => { |
35 | | - const image = makeImage(); |
36 | | - const encoded = await image.toEncodedImageDataAsync('jpg', 70); |
37 | | - expect(encoded.imageFormat).toBe('jpg'); |
38 | | - expect(encoded.buffer.byteLength).toBeGreaterThan(0); |
39 | | - }); |
40 | | -}); |
| 35 | + const image = makeImage() |
| 36 | + const encoded = await image.toEncodedImageDataAsync('jpg', 70) |
| 37 | + expect(encoded.imageFormat).toBe('jpg') |
| 38 | + expect(encoded.buffer.byteLength).toBeGreaterThan(0) |
| 39 | + }) |
| 40 | +}) |
41 | 41 |
|
42 | 42 | describe('Images - loadFromEncodedImageData', () => { |
43 | 43 | it('round-trips through PNG encoding', () => { |
44 | | - const image = makeImage(); |
45 | | - const encoded = image.toEncodedImageData('png'); |
46 | | - const decoded = Images.loadFromEncodedImageData(encoded); |
47 | | - expect(decoded.width).toBe(image.width); |
48 | | - expect(decoded.height).toBe(image.height); |
49 | | - }); |
50 | | -}); |
| 44 | + const image = makeImage() |
| 45 | + const encoded = image.toEncodedImageData('png') |
| 46 | + const decoded = Images.loadFromEncodedImageData(encoded) |
| 47 | + expect(decoded.width).toBe(image.width) |
| 48 | + expect(decoded.height).toBe(image.height) |
| 49 | + }) |
| 50 | +}) |
51 | 51 |
|
52 | 52 | describe('Image - saveToTemporaryFileAsync', () => { |
53 | 53 | it('writes a JPG to a temporary path', async () => { |
54 | | - const image = makeImage(); |
55 | | - const path = await image.saveToTemporaryFileAsync('jpg', 80); |
56 | | - expect(typeof path).toBe('string'); |
57 | | - expect(path.length).toBeGreaterThan(0); |
58 | | - }); |
59 | | -}); |
| 54 | + const image = makeImage() |
| 55 | + const path = await image.saveToTemporaryFileAsync('jpg', 80) |
| 56 | + expect(typeof path).toBe('string') |
| 57 | + expect(path.length).toBeGreaterThan(0) |
| 58 | + }) |
| 59 | +}) |
0 commit comments