Skip to content

Commit

Permalink
Add unit test that checks if SourceCache waits until source is loaded…
Browse files Browse the repository at this point in the history
… before preloading tiles
  • Loading branch information
stepankuzmin committed May 10, 2023
1 parent 9e470da commit 9dea370
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/unit/source/source_cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1897,5 +1897,27 @@ test('SourceCache#_preloadTiles', (t) => {
sourceCache.getSource().onAdd();
});

t.test('waits until source is loaded before preloading tiles', (t) => {
const transform = new Transform();
transform.resize(511, 511);
transform.zoom = 0;

const {sourceCache} = createSourceCache({
loadTile (tile, callback) {
t.ok(sourceCache._sourceLoaded, 'source is loaded before preloading tiles');
t.equal(tile.tileID.key, new OverscaledTileID(0, 0, 0, 0, 0).key,);
tile.state = 'loaded';
callback(null);
}
});

// Marks source as not loaded
sourceCache._sourceLoaded = false;
sourceCache._preloadTiles(transform, () => t.end());

// Fires event that marks source as loaded
sourceCache.getSource().onAdd();
});

t.end();
});

0 comments on commit 9dea370

Please sign in to comment.