|
| 1 | +import { fromJS } from 'immutable' |
1 | 2 | import { getApiUri } from '../../src/misc/url'
|
2 |
| -import { formatDate } from '../../src/misc/snippet' |
| 3 | +import { formatDate, getSnippetTitle } from '../../src/misc/snippet' |
3 | 4 |
|
4 | 5 | describe('misc', () => {
|
5 |
| - it('should return properly formated date', () => { |
6 |
| - const incomeDate = '2018-03-11T15:28:19' |
7 |
| - |
8 |
| - expect(formatDate(incomeDate)).toEqual('11.03.2018') |
| 6 | + describe('snippet related', () => { |
| 7 | + const snippet = { |
| 8 | + content: 'const memoizedSyntaxes = useMemo()', |
| 9 | + created_at: '2019-09-29T19:23:31', |
| 10 | + id: 364066, |
| 11 | + syntax: 'javascript', |
| 12 | + tags: ['trg', 'rtyger'], |
| 13 | + title: 'some misterious title', |
| 14 | + updated_at: '2020-01-01T23:28:19', |
| 15 | + } |
| 16 | + |
| 17 | + it('should return properly formated date', () => { |
| 18 | + expect(formatDate(snippet.created_at)).toEqual('29.09.2019') |
| 19 | + }) |
| 20 | + |
| 21 | + it('should return properly formatted date for Jan', () => { |
| 22 | + expect(formatDate(snippet.updated_at)).toEqual('01.01.2020') |
| 23 | + }) |
| 24 | + |
| 25 | + it('should return propper title', () => { |
| 26 | + expect(getSnippetTitle(fromJS(snippet))).toEqual(snippet.title) |
| 27 | + }) |
| 28 | + |
| 29 | + it('should return propper title', () => { |
| 30 | + const untitled = { ...snippet, title: undefined } |
| 31 | + const expected = `#${untitled.id}, Untitled` |
| 32 | + |
| 33 | + expect(getSnippetTitle(fromJS(untitled))).toEqual(expected) |
| 34 | + }) |
9 | 35 | })
|
10 | 36 |
|
11 |
| - it('should return properly formatted date for Jan', () => { |
12 |
| - const incomeDate = '2018-01-01T23:28:19' |
13 |
| - |
14 |
| - expect(formatDate(incomeDate)).toEqual('01.01.2018') |
15 |
| - }) |
| 37 | + describe('getApiUri', () => { |
| 38 | + it('should construct correct url with default api version', () => { |
| 39 | + process.env.API_BASE_URI = '//api.xsnippet.org' |
| 40 | + const f = getApiUri('snippets') |
16 | 41 |
|
17 |
| - it('should construct correct url with default api version', () => { |
18 |
| - process.env.API_BASE_URI = '//api.xsnippet.org' |
19 |
| - const f = getApiUri('snippets') |
20 |
| - |
21 |
| - expect(f).toBe(`${process.env.API_BASE_URI}/v1/snippets`) |
22 |
| - }) |
| 42 | + expect(f).toBe(`${process.env.API_BASE_URI}/v1/snippets`) |
| 43 | + }) |
23 | 44 |
|
24 |
| - it('should construct correct url with passed api version', () => { |
25 |
| - process.env.API_BASE_URI = '//api.xsnippet.org' |
26 |
| - const f = getApiUri('snippets', 'v404') |
| 45 | + it('should construct correct url with passed api version', () => { |
| 46 | + process.env.API_BASE_URI = '//api.xsnippet.org' |
| 47 | + const f = getApiUri('snippets', 'v404') |
27 | 48 |
|
28 |
| - expect(f).toBe(`${process.env.API_BASE_URI}/v404/snippets`) |
| 49 | + expect(f).toBe(`${process.env.API_BASE_URI}/v404/snippets`) |
| 50 | + }) |
29 | 51 | })
|
30 | 52 | })
|
0 commit comments