-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterator.spec.ts
51 lines (40 loc) · 1.25 KB
/
iterator.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
import { describe, it } from '@jest/globals';
import StoreCollection from './StoreCollection';
import { IIterator } from './iteratorTypes';
interface IProduct {
uid: string;
title: string;
price: number;
}
// Mock data item - 1
const firstProduct: IProduct = {
uid: '1',
title: 'Iphone X',
price: 1009.0,
};
// Mock data item - 2
const secondProduct: IProduct = {
uid: '2',
title: 'Iphone XS',
price: 522.0,
};
describe('Behaviours ->Iterator design pattern', () => {
it('Should be able to retrieve a first/current item', () => {
const collection: StoreCollection<IProduct> =
new StoreCollection<IProduct>();
collection.push(firstProduct);
collection.push(secondProduct);
const listIterator: IIterator<IProduct> = collection.listIterator();
expect(listIterator.current()).toEqual(firstProduct);
expect(listIterator.hasNext()).toBeTruthy();
});
it('Should not be able to retrieve next item', () => {
const collection: StoreCollection<IProduct> = new StoreCollection<IProduct>(
[firstProduct],
);
const listIterator: IIterator<IProduct> = collection.listIterator();
listIterator.next();
expect(listIterator.hasNext()).toBeFalsy();
expect(listIterator.next()).toBeFalsy();
});
});