This repository was archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathmerge.pipe.spec.ts
66 lines (51 loc) · 2.07 KB
/
merge.pipe.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
import { UnionPipe } from './union.pipe';
import { DeepPipe } from './deep.pipe';
import {MergePipe} from "./merge.pipe";
describe('MergePipe', () => {
let pipe: MergePipe;
let deepPipe: DeepPipe;
beforeEach(() => {
pipe = new MergePipe();
deepPipe = new DeepPipe();
});
it('Should return the merge', () => {
const a = [1, 1, 1, 2, 3, 3, 4, 5];
const b = [1, 2];
const result = pipe.transform(a, b);
expect(result).toEqual([1, 1, 1, 2, 3, 3, 4, 5, 1, 2]);
expect(a).toEqual([1, 1, 1, 2, 3, 3, 4, 5]); // Check integrity
expect(b).toEqual([1, 2]); // Check integrity
});
it('Should return the union #2', () => {
const result = pipe.transform([1, 2], [3, 4]);
expect(result).toEqual([1, 2, 3, 4]);
});
it('Should merge with null value', () => {
const result = pipe.transform([1, 2], null);
expect(result).toEqual([1, 2]);
});
it('Should merge on null value', () => {
const result = pipe.transform(null, [1, 2]);
expect(result).toEqual([1, 2]);
});
it('Should merge null values', () => {
const result = pipe.transform(null, null);
expect(result).toEqual([]);
})
it('Should return an empty array', () => {
expect(pipe.transform('a')).toEqual([]);
expect(pipe.transform([], 'a')).toEqual([]);
expect(pipe.transform(deepPipe.transform({ a: 1 }), [])).toEqual([]);
});
it('Should return the union with no deep equal', () => {
const collection = [{ a: 1, b: { c: 2 } }, { a: 2, b: { c: 3 } }, { a: 2, b: { c: 3 } }, { a: 1, b: { c: 2 } }];
const collection2 = [{ a: 1, b: { c: 2 } }];
expect(pipe.transform(collection, collection2)).toEqual(collection.concat(collection2));
});
it('Should return union with deep equal', () => {
const collection = [{ a: 1, b: { c: 2 } }, { a: 2, b: { c: 3 } }, { a: 2, b: { c: 3 } }, { a: 1, b: { c: 2 } }];
const collection2 = [{ a: 1, b: { c: 2 } }, { a: 2, b: { c: 3 } }, { a: 3, b: { c: 2 } }];
const deep = deepPipe.transform(collection);
expect(pipe.transform(deep, collection2)).toEqual(collection.concat(collection2));
});
});