mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-04-08 02:54:16 +00:00
Merge when updates items in datasource
This commit is contained in:
parent
c5de9256c7
commit
9f86414210
@ -1,63 +1,73 @@
|
||||
import {DataSource} from "./datasource";
|
||||
|
||||
class TestDataSource extends DataSource<string> {
|
||||
protected findIndex(item: string) {
|
||||
return this.data.findIndex((i: string) => i === item);
|
||||
class Item {
|
||||
constructor(public id: string, public property1?: string, public property2?: string) {}
|
||||
}
|
||||
|
||||
|
||||
class TestDataSource extends DataSource<Item> {
|
||||
protected findIndex(item: Item) {
|
||||
return this.data.findIndex((i: Item) => i.id === item.id);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
describe('TestDataSource', () => {
|
||||
let dataSource: TestDataSource;
|
||||
let data: string[];
|
||||
let data: Item[];
|
||||
|
||||
beforeEach(() => {
|
||||
dataSource = new TestDataSource();
|
||||
dataSource.connect().subscribe((updated: string[]) => {
|
||||
dataSource.connect().subscribe((updated: Item[]) => {
|
||||
data = updated;
|
||||
});
|
||||
});
|
||||
|
||||
describe('Item can be added', () => {
|
||||
beforeEach(() => {
|
||||
dataSource.add("test");
|
||||
dataSource.add(new Item("test1", "property1"));
|
||||
});
|
||||
|
||||
it('item should be in data', () => {
|
||||
expect(data).toEqual(["test"]);
|
||||
expect(data).toEqual([new Item("test1", "property1")]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Items can be set', () => {
|
||||
beforeEach(() => {
|
||||
dataSource.set(["test", "test2"]);
|
||||
dataSource.set([new Item("test1", "property1"), new Item("test2", "property2")]);
|
||||
});
|
||||
|
||||
it('items should be in data', () => {
|
||||
expect(data).toEqual(["test", "test2"]);
|
||||
expect(data).toEqual([new Item("test1", "property1"), new Item("test2", "property2")]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Items can be removed', () => {
|
||||
beforeEach(() => {
|
||||
dataSource.set(["test", "test2"]);
|
||||
dataSource.remove("test");
|
||||
dataSource.set([new Item("test1", "property1"), new Item("test2", "property2")]);
|
||||
dataSource.remove(new Item("test1", "property1"));
|
||||
});
|
||||
|
||||
it('item should not be in data', () => {
|
||||
expect(data).toEqual(["test2"]);
|
||||
expect(data).toEqual([new Item("test2", "property2")]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Item can be updated', () => {
|
||||
beforeEach(() => {
|
||||
dataSource.set(["test", "test2"]);
|
||||
dataSource.update("test");
|
||||
dataSource.set([new Item("test1", "property1", "another"), new Item("test2", "property2")]);
|
||||
dataSource.update(new Item("test1", "property3"));
|
||||
});
|
||||
|
||||
it('item should be updated', () => {
|
||||
expect(data).toEqual(["test", "test2"]);
|
||||
expect(data).toEqual([
|
||||
new Item("test1", "property3"),
|
||||
new Item("test2", "property2")
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -21,7 +21,7 @@ export abstract class DataSource<T> {
|
||||
public update(item: T) {
|
||||
const index = this.findIndex(item);
|
||||
if (index >= 0) {
|
||||
this.data[index] = item;
|
||||
this.data[index] = Object.assign(this.data[index], item);
|
||||
this.dataChange.next(this.data);
|
||||
}
|
||||
}
|
||||
|
@ -43,11 +43,11 @@ g.node text {
|
||||
}
|
||||
|
||||
|
||||
svg image:hover, svg image.chosen, g.selectable.selected {
|
||||
svg image:hover, svg image.chosen, g.selected {
|
||||
filter: grayscale(100%);
|
||||
}
|
||||
|
||||
path.selectable.selected {
|
||||
path.selected {
|
||||
stroke: darkred;
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,6 @@ export class ProjectMapComponent implements OnInit {
|
||||
|
||||
this.mapChild.graphLayout.getNodesWidget().setOnNodeClickedCallback((event: any, node: Node) => {
|
||||
selectionManager.setSelectedNodes([node]);
|
||||
|
||||
if (this.drawLineMode) {
|
||||
this.nodeSelectInterfaceMenu.open(node, event.clientY, event.clientX);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user