forked from mystiq/hydrogen-web
add failing test for problem
This commit is contained in:
parent
0c51df220c
commit
4176af56ea
1 changed files with 64 additions and 0 deletions
|
@ -172,3 +172,67 @@ export default class TilesCollection extends BaseObservableList {
|
|||
return this._tiles.length;
|
||||
}
|
||||
}
|
||||
|
||||
import ObservableArray from "../../../../observable/list/ObservableArray.js";
|
||||
import UpdateAction from "./UpdateAction.js";
|
||||
|
||||
export function tests() {
|
||||
|
||||
class TestTile {
|
||||
constructor(entry, update) {
|
||||
this.entry = entry;
|
||||
this.update = update;
|
||||
}
|
||||
tryIncludeEntry() {
|
||||
return false;
|
||||
}
|
||||
compareEntry(b) {
|
||||
return this.entry.n - b.n;
|
||||
}
|
||||
removeEntry() {
|
||||
return true;
|
||||
}
|
||||
get upperEntry() {
|
||||
return this.entry;
|
||||
}
|
||||
|
||||
get lowerEntry() {
|
||||
return this.entry;
|
||||
}
|
||||
updateNextSibling() {}
|
||||
updatePreviousSibling() {}
|
||||
updateEntry() {
|
||||
return UpdateAction.Nothing;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
"don't emit update before add": assert => {
|
||||
class UpdateOnSiblingTile extends TestTile {
|
||||
updateNextSibling() {
|
||||
// this happens with isContinuation
|
||||
this.update(this, "next");
|
||||
}
|
||||
updatePreviousSibling() {
|
||||
// this happens with isContinuation
|
||||
this.update(this, "previous");
|
||||
}
|
||||
}
|
||||
const entries = new ObservableArray([{n: 5}, {n: 10}]);
|
||||
const tiles = new TilesCollection(entries, (e, u) => new UpdateOnSiblingTile(e, u));
|
||||
let receivedAdd = false;
|
||||
tiles.subscribe({
|
||||
onAdd(idx, tile) {
|
||||
assert(tile.entry.n, 7);
|
||||
receivedAdd = true;
|
||||
},
|
||||
onUpdate(idx, tile) {
|
||||
assert(tile.entry.n, 7);
|
||||
assert(!receivedAdd, "receiving update before add");
|
||||
}
|
||||
});
|
||||
entries.insert(1, {n: 7});
|
||||
assert(receivedAdd);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue