1 | import { Container } from 'aurelia-dependency-injection';
|
2 | import { ViewLocator } from '../src/view-locator';
|
3 | import { StaticViewStrategy } from '../src/view-strategy';
|
4 | import './setup';
|
5 |
|
6 | describe('ViewLocator', () => {
|
7 |
|
8 | let container;
|
9 |
|
10 | let viewLocator;
|
11 |
|
12 | beforeEach(() => {
|
13 | container = new Container();
|
14 | viewLocator = new ViewLocator();
|
15 | });
|
16 |
|
17 | describe('static $view strategy', () => {
|
18 | it('works with static field and raw string', () => {
|
19 | class El {
|
20 | static $view = '<template></template>';
|
21 | }
|
22 | let strategy = viewLocator.getViewStrategy(El);
|
23 | expect(strategy instanceof StaticViewStrategy).toBe(true);
|
24 | expect(strategy.template).toBe(El.$view);
|
25 | });
|
26 |
|
27 | it('works with static field', () => {
|
28 | class El {
|
29 | static $view = {
|
30 | template: '<template></template>'
|
31 | }
|
32 | }
|
33 | let strategy = viewLocator.getViewStrategy(El);
|
34 | expect(strategy instanceof StaticViewStrategy).toBe(true);
|
35 | expect(strategy.template).toBe(El.$view.template);
|
36 | });
|
37 |
|
38 | it('works with static method', () => {
|
39 | class El {
|
40 | static $view() {
|
41 | return {
|
42 | template: '<template></template>'
|
43 | };
|
44 | }
|
45 | }
|
46 | let strategy = viewLocator.getViewStrategy(El);
|
47 | expect(strategy instanceof StaticViewStrategy).toBe(true);
|
48 | expect(strategy.template).toBe('<template></template>');
|
49 | });
|
50 |
|
51 | it('works with static method and raw string', () => {
|
52 | class El {
|
53 | static $view() {
|
54 | return '<template></template>';
|
55 | }
|
56 | }
|
57 | let strategy = viewLocator.getViewStrategy(El);
|
58 | expect(strategy instanceof StaticViewStrategy).toBe(true);
|
59 | expect(strategy.template).toBe('<template></template>');
|
60 | });
|
61 |
|
62 | it('invokes static method with correct scope', () => {
|
63 | class Base {
|
64 | static template = '<template><div></div></template>';
|
65 | static $view() {
|
66 | return this.template;
|
67 | }
|
68 | }
|
69 | class El extends Base{
|
70 | }
|
71 | let strategy = viewLocator.getViewStrategy(El);
|
72 | expect(strategy instanceof StaticViewStrategy).toBe(true);
|
73 | expect(strategy.template).toBe(Base.template);
|
74 |
|
75 | class El1 extends Base {
|
76 | static template = '<template>11</template>';
|
77 | }
|
78 | strategy = viewLocator.getViewStrategy(El1);
|
79 | expect(strategy.template).toBe(El1.template);
|
80 | });
|
81 | });
|
82 | });
|