Skip to content

Commit 4ea5666

Browse files
authored
Merge pull request #134 from xsnippet/tests
[Tests] Update misc tests
2 parents 1bf0cbf + 58dd0b3 commit 4ea5666

File tree

2 files changed

+44
-22
lines changed

2 files changed

+44
-22
lines changed

src/misc/download.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getCurrentMode } from './modes'
22

3-
function download(text, name, mime) {
3+
const download = (text, name, mime) => {
44
// It seems it's the only way to initiate file downloading from JavaScript
55
// as of Jan 7, 2018. If you read this and know a better way, please submit
66
// a pull request! ;)
@@ -16,7 +16,7 @@ function download(text, name, mime) {
1616
document.body.removeChild(element)
1717
}
1818

19-
export function downloadSnippet(snippet) {
19+
export const downloadSnippet = snippet => {
2020
// Despite using AceEditor's modes as syntaxes, we can imagine other setup
2121
// when more or even other syntaxes can be used on API side. Hence, we better
2222
// be prepared and fallback to "Text" mode if unknown syntaxes it is.

tests/helpers/index.test.js

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,52 @@
1+
import { fromJS } from 'immutable'
12
import { getApiUri } from '../../src/misc/url'
2-
import { formatDate } from '../../src/misc/snippet'
3+
import { formatDate, getSnippetTitle } from '../../src/misc/snippet'
34

45
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+
})
935
})
1036

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')
1641

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+
})
2344

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')
2748

28-
expect(f).toBe(`${process.env.API_BASE_URI}/v404/snippets`)
49+
expect(f).toBe(`${process.env.API_BASE_URI}/v404/snippets`)
50+
})
2951
})
3052
})

0 commit comments

Comments
 (0)