/
app.e2e-spec.ts
86 lines (68 loc) · 2.64 KB
/
app.e2e-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
import { AppPage } from './app.po';
import { browser } from 'protractor';
describe('TimeSince Lib E2E Tests', function() {
let page: AppPage;
beforeEach(() => (page = new AppPage()));
beforeEach(() => page.navigateTo());
afterEach(() => {
browser
.manage()
.logs()
.get('browser')
.then((browserLog: any[]) => {
expect(browserLog).toEqual([]);
});
});
describe('Parse values', () => {
it('should return time ago if parsable date value', () => {
const dateStr = page.getElementDateStr();
const dateNum = page.getElementDateNum();
const dateObj = page.getElementDateObj();
expect(dateStr.getText()).toMatch(/[0-9] years ago/);
expect(dateNum.getText()).toMatch(/[0-9] years ago/);
expect(dateObj.getText()).toMatch(/[0-9] years ago/);
});
it('should return original value if invalid date', () => {
const dateInvalid = page.getElementDateInvalid();
expect(dateInvalid.getText()).toBe(`foo ago`);
});
});
describe('Units of time', () => {
it('should return number of years', () => {
const dateYears = page.getElementDateYears();
const dateYear = page.getElementDateYear();
expect(dateYears.getText()).toBe(`2 years ago`);
expect(dateYear.getText()).toBe(`1 year ago`);
});
it('should return number of months', () => {
const dateMonths = page.getElementDateMonths();
const dateMonth = page.getElementDateMonth();
expect(dateMonths.getText()).toBe(`2 months ago`);
expect(dateMonth.getText()).toBe(`1 month ago`);
});
it('should return number of days', () => {
const dateDays = page.getElementDateDays();
const dateDay = page.getElementDateDay();
expect(dateDays.getText()).toBe(`2 days ago`);
expect(dateDay.getText()).toBe(`1 day ago`);
});
it('should return number of hours', () => {
const dateHours = page.getElementDateHours();
const dateHour = page.getElementDateHour();
expect(dateHours.getText()).toBe(`2 hours ago`);
expect(dateHour.getText()).toBe(`1 hour ago`);
});
it('should return number of minutes', () => {
const dateMinutes = page.getElementDateMins();
const dateMinute = page.getElementDateMin();
expect(dateMinutes.getText()).toBe(`2 minutes ago`);
expect(dateMinute.getText()).toBe(`1 minute ago`);
});
it('should return number of seconds', () => {
const dateSeconds = page.getElementDateSecs();
const dateSecond = page.getElementDateSec();
expect(dateSeconds.getText()).toBe(`2 seconds ago`);
expect(dateSecond.getText()).toBe(`1 second ago`);
});
});
});