-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test and document abstract graphs (#181)
Abstract graphs is a handy approach to declare common dependencies that are shared by multiple graphs.
- Loading branch information
Showing
2 changed files
with
130 additions
and
1 deletion.
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
57 changes: 57 additions & 0 deletions
57
packages/react-obsidian/test/acceptance/abstractGraph.test.ts
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { | ||
Graph, | ||
ObjectGraph, | ||
Obsidian, | ||
Provides, | ||
} from '../../src'; | ||
|
||
describe('abstract graph', () => { | ||
it('should be able to create a graph', () => { | ||
expect(new FooGraph()).toBeInstanceOf(FooGraph); | ||
}); | ||
|
||
it('should be able to provide a value', () => { | ||
expect(Obsidian.obtain(FooGraph).atomicDependency()).toBe('foo'); | ||
}); | ||
|
||
it('should be able to provide a composite value', () => { | ||
expect(Obsidian.obtain(FooGraph).compositeDependency()).toBe('foobar'); | ||
}); | ||
|
||
it('should provide dependencies that depend on abstract dependencies', () => { | ||
expect(Obsidian.obtain(FooGraph).dependsOnAbstractDependency()).toBe('depends on baz'); | ||
}); | ||
}); | ||
|
||
|
||
abstract class AbstractGraph extends ObjectGraph { | ||
@Provides() | ||
compositeDependency(atomicDependency: string, bar: string) { | ||
return atomicDependency + bar; | ||
} | ||
|
||
@Provides() | ||
atomicDependency() { | ||
return 'foo'; | ||
} | ||
|
||
@Provides() | ||
dependsOnAbstractDependency(baz: string) { | ||
return `depends on ${baz}`; | ||
} | ||
|
||
abstract baz(): string; | ||
} | ||
|
||
@Graph() | ||
class FooGraph extends AbstractGraph { | ||
@Provides() | ||
bar() { | ||
return 'bar'; | ||
} | ||
|
||
@Provides() | ||
override baz() { | ||
return 'baz'; | ||
} | ||
} |