-
-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed url validation form normalizeSpriteURL
- Loading branch information
Showing
5 changed files
with
68 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,38 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import {RequestManager} from '../util/request_manager'; | ||
import {loadSprite} from './load_sprite'; | ||
import {loadSprite, normalizeSpriteURL} from './load_sprite'; | ||
import {type FakeServer, fakeServer} from 'nise'; | ||
import {bufferToArrayBuffer} from '../util/test/util'; | ||
import {ABORT_ERROR} from '../util/abort_error'; | ||
import * as util from '../util/util'; | ||
|
||
describe('normalizeSpriteURL', () => { | ||
test('concantenates path, ratio, and extension for non-mapbox:// scheme', () => { | ||
expect( | ||
normalizeSpriteURL('http://www.foo.com/bar', '@2x', '.png') | ||
).toBe('http://www.foo.com/[email protected]'); | ||
}); | ||
|
||
test('concantenates path, ratio, and extension for file:/// scheme', () => { | ||
expect( | ||
normalizeSpriteURL('file:///path/to/bar', '@2x', '.png') | ||
).toBe('file:///path/to/[email protected]'); | ||
}); | ||
|
||
test('normalizes non-mapbox:// scheme when query string exists', () => { | ||
expect( | ||
normalizeSpriteURL('http://www.foo.com/bar?fresh=true', '@2x', '.png') | ||
).toBe('http://www.foo.com/[email protected]?fresh=true'); | ||
}); | ||
|
||
test('test relative URL', () => { | ||
expect( | ||
normalizeSpriteURL('/bar?fresh=true', '@2x', '.png') | ||
).toBe('/[email protected]?fresh=true'); | ||
}); | ||
}); | ||
|
||
describe('loadSprite', () => { | ||
|
||
let server: FakeServer; | ||
|
@@ -56,6 +82,38 @@ describe('loadSprite', () => { | |
expect(server.requests[1].url).toBe('http://localhost:9966/test/unit/assets/sprite1.png'); | ||
}); | ||
|
||
test('transform of relative URL', async () => { | ||
const transform = jest.fn().mockImplementation((url, type) => { | ||
return {url: `http://localhost:9966${url}`, type}; | ||
}); | ||
|
||
const manager = new RequestManager(transform); | ||
|
||
server.respondWith('GET', 'http://localhost:9966/test/unit/assets/sprite1.json', fs.readFileSync(path.join(__dirname, '../../test/unit/assets/sprite1.json')).toString()); | ||
server.respondWith('GET', 'http://localhost:9966/test/unit/assets/sprite1.png', bufferToArrayBuffer(fs.readFileSync(path.join(__dirname, '../../test/unit/assets/sprite1.png')))); | ||
|
||
const promise = loadSprite('/test/unit/assets/sprite1', manager, 1, new AbortController()); | ||
|
||
server.respond(); | ||
|
||
const result = await promise; | ||
|
||
expect(transform).toHaveBeenCalledTimes(2); | ||
expect(transform).toHaveBeenNthCalledWith(1, '/test/unit/assets/sprite1.json', 'SpriteJSON'); | ||
expect(transform).toHaveBeenNthCalledWith(2, '/test/unit/assets/sprite1.png', 'SpriteImage'); | ||
|
||
expect(Object.keys(result)).toHaveLength(1); | ||
expect(Object.keys(result)[0]).toBe('default'); | ||
|
||
Object.values(result['default']).forEach(styleImage => { | ||
expect(styleImage.spriteData).toBeTruthy(); | ||
expect(styleImage.spriteData.context).toBeInstanceOf(CanvasRenderingContext2D); | ||
}); | ||
|
||
expect(server.requests[0].url).toBe('http://localhost:9966/test/unit/assets/sprite1.json'); | ||
expect(server.requests[1].url).toBe('http://localhost:9966/test/unit/assets/sprite1.png'); | ||
}); | ||
|
||
test('array of objects support', async () => { | ||
const transform = jest.fn().mockImplementation((url, type) => { | ||
return {url, type}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters