mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-11-29 17:51:46 +00:00
Added minimum requirement for TS2.1, fixed test
This commit is contained in:
Vendored
+1
@@ -5,6 +5,7 @@
|
||||
// Andrey Kurdyumov <https://github.com/kant2002>,
|
||||
// Terry Mun <https://github.com/terrymun>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
/// <reference types="mina" />
|
||||
|
||||
export = Snap;
|
||||
|
||||
+97
-83
@@ -1,94 +1,108 @@
|
||||
(() => {
|
||||
// Tests by Terry Mun
|
||||
// Checks that Snap.set() is properly typed
|
||||
// Tests by Terry Mun
|
||||
// Checks that Snap.set() is properly typed
|
||||
|
||||
const s = Snap(200, 500);
|
||||
s.attr({
|
||||
viewBox: '0 0 200 500'
|
||||
const s = Snap(200, 500);
|
||||
s.attr({
|
||||
viewBox: '0 0 200 500'
|
||||
});
|
||||
|
||||
// Create multiple elements to be added to set
|
||||
const rect1 = s.rect(0, 0, 50, 50);
|
||||
const rect2 = s.rect(0, 100, 50, 50);
|
||||
const rect3 = s.rect(0, 200, 50, 50);
|
||||
const rect4 = s.rect(0, 300, 50, 50);
|
||||
let rect5: Snap.Element;
|
||||
|
||||
// Create new set
|
||||
const rectSet = Snap.set(rect1, rect2);
|
||||
|
||||
// Add missing rectangles to set
|
||||
rectSet.push(rect3, rect4);
|
||||
|
||||
// Set all attributes
|
||||
rectSet.attr({
|
||||
fill: 'steelblue'
|
||||
});
|
||||
|
||||
// Animate all elements in set
|
||||
function animateTest() {
|
||||
return new Promise(resolve => {
|
||||
rectSet.animate({
|
||||
x: 50
|
||||
}, 500, mina.bounce, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
// Animate elements individually
|
||||
function forEachTest() {
|
||||
const colors = ['red', 'green', 'blue'];
|
||||
return new Promise(resolve => {
|
||||
rectSet.forEach((element, idx) => {
|
||||
element.attr({
|
||||
fill: colors[idx] || '#aaa'
|
||||
});
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
// Exclude rect4 from set
|
||||
function excludeTest() {
|
||||
return new Promise(resolve => {
|
||||
rectSet.exclude(rect4);
|
||||
rectSet.animate({
|
||||
x: 100
|
||||
}, 500, mina.bounce, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
// Remove rect2 from set (it has index of 1)
|
||||
// Add new rect5 to set
|
||||
async function spliceTest() {
|
||||
rectSet.splice(1, 1);
|
||||
rectSet.attr({
|
||||
fill: '#000'
|
||||
});
|
||||
|
||||
// Create multiple elements to be added to set
|
||||
const rect1 = s.rect(0,0,50,50);
|
||||
const rect2 = s.rect(0,100,50,50);
|
||||
const rect3 = s.rect(0,200,50,50);
|
||||
const rect4 = s.rect(0,300,50,50);
|
||||
let rect5: Snap.Element;
|
||||
rect5 = s.rect(100, 400, 50, 50);
|
||||
rectSet.splice(1, 0, rect5);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create new set
|
||||
const rectSet = Snap.set(rect1, rect2);
|
||||
// Clear set. Rectangles should not go back to x=0
|
||||
function clearTest() {
|
||||
return new Promise(resolve => {
|
||||
rectSet.clear();
|
||||
|
||||
// Add missing rectangles to set
|
||||
rectSet.push(rect3, rect4);
|
||||
// SHOULD NOT WORK
|
||||
rectSet.animate({
|
||||
x: 0
|
||||
}, 500, mina.bounce, resolve);
|
||||
|
||||
// Set all attributes
|
||||
rectSet.attr({ fill: 'steelblue' });
|
||||
// Re-add rects to set
|
||||
rectSet.push(rect1, rect2, rect3, rect4, rect5);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
// Animate all elements in set
|
||||
function animateTest() {
|
||||
return new Promise(resolve => {
|
||||
rectSet.animate({ x: 50 }, 500, mina.bounce, resolve);
|
||||
});
|
||||
}
|
||||
// Remove all elements from DOM that are present in set
|
||||
async function removeTest() {
|
||||
rectSet.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
// Animate elements individually
|
||||
function forEachTest() {
|
||||
const colors = ['red', 'green', 'blue'];
|
||||
return new Promise(resolve => {
|
||||
rectSet.forEach((element,idx) => element.attr({ fill: colors[idx] || '#aaa' }));
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
// Start test
|
||||
async function startTest() {
|
||||
await animateTest();
|
||||
await forEachTest();
|
||||
await excludeTest();
|
||||
await spliceTest();
|
||||
await clearTest();
|
||||
await removeTest();
|
||||
|
||||
// Exclude rect4 from set
|
||||
function excludeTest() {
|
||||
return new Promise(resolve => {
|
||||
rectSet.exclude(rect4);
|
||||
rectSet.animate({ x: 100 }, 500, mina.bounce, resolve);
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove rect2 from set (it has index of 1)
|
||||
// Add new rect5 to set
|
||||
async function spliceTest() {
|
||||
rectSet.splice(1, 1);
|
||||
rectSet.attr({ fill: '#000' });
|
||||
|
||||
rect5 = s.rect(100, 400, 50, 50);
|
||||
rectSet.splice(1, 0, rect5);
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear set. Rectangles should not go back to x=0
|
||||
function clearTest() {
|
||||
return new Promise(resolve => {
|
||||
rectSet.clear();
|
||||
|
||||
// SHOULD NOT WORK
|
||||
rectSet.animate({ x: 0 }, 500, mina.bounce, resolve);
|
||||
|
||||
// Re-add rects to set
|
||||
rectSet.push(rect1, rect2, rect3, rect4, rect5);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
// Remove all elements from DOM that are present in set
|
||||
async function removeTest() {
|
||||
rectSet.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
// Start test
|
||||
async function startTest() {
|
||||
await animateTest();
|
||||
await forEachTest();
|
||||
await excludeTest();
|
||||
await spliceTest();
|
||||
await clearTest();
|
||||
await removeTest();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
startTest();
|
||||
})();
|
||||
startTest();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user