-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathmove_spec.ts
100 lines (88 loc) · 3.33 KB
/
move_spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { of as observableOf } from 'rxjs';
import { SchematicContext } from '../engine/interface';
import { HostTree } from '../tree/host-tree';
import { callRule } from './call';
import { move } from './move';
const context: SchematicContext = null!;
describe('move', () => {
it('works on moving the whole structure', (done) => {
const tree = new HostTree();
tree.create('a/b/file1', 'hello world');
tree.create('a/b/file2', 'hello world');
tree.create('a/c/file3', 'hello world');
callRule(move('sub'), observableOf(tree), context)
.toPromise()
.then((result) => {
expect(result.exists('sub/a/b/file1')).toBe(true);
expect(result.exists('sub/a/b/file2')).toBe(true);
expect(result.exists('sub/a/c/file3')).toBe(true);
})
.then(done, done.fail);
});
it('works on moving a subdirectory structure', (done) => {
const tree = new HostTree();
tree.create('a/b/file1', 'hello world');
tree.create('a/b/file2', 'hello world');
tree.create('a/c/file3', 'hello world');
callRule(move('a/b', 'sub'), observableOf(tree), context)
.toPromise()
.then((result) => {
expect(result.exists('sub/file1')).toBe(true);
expect(result.exists('sub/file2')).toBe(true);
expect(result.exists('a/c/file3')).toBe(true);
})
.then(done, done.fail);
});
it('works on moving a directory into a subdirectory of itself', (done) => {
const tree = new HostTree();
tree.create('a/b/file1', 'hello world');
tree.create('a/b/file2', 'hello world');
tree.create('a/c/file3', 'hello world');
callRule(move('a/b', 'a/b/c'), observableOf(tree), context)
.toPromise()
.then((result) => {
expect(result.exists('a/b/c/file1')).toBe(true);
expect(result.exists('a/b/c/file2')).toBe(true);
expect(result.exists('a/c/file3')).toBe(true);
})
.then(done, done.fail);
});
it('works on moving a directory into a parent of itself', (done) => {
const tree = new HostTree();
tree.create('a/b/file1', 'hello world');
tree.create('a/b/file2', 'hello world');
tree.create('a/c/file3', 'hello world');
callRule(move('a/b', 'a'), observableOf(tree), context)
.toPromise()
.then((result) => {
expect(result.exists('file1')).toBe(false);
expect(result.exists('file2')).toBe(false);
expect(result.exists('a/file1')).toBe(true);
expect(result.exists('a/file2')).toBe(true);
expect(result.exists('a/c/file3')).toBe(true);
})
.then(done, done.fail);
});
it('becomes a noop with identical from and to', (done) => {
const tree = new HostTree();
tree.create('a/b/file1', 'hello world');
tree.create('a/b/file2', 'hello world');
tree.create('a/c/file3', 'hello world');
callRule(move(''), observableOf(tree), context)
.toPromise()
.then((result) => {
expect(result.exists('a/b/file1')).toBe(true);
expect(result.exists('a/b/file2')).toBe(true);
expect(result.exists('a/c/file3')).toBe(true);
})
.then(done, done.fail);
});
});