All files editorTypes.test.js

100% Statements 46/46
100% Branches 0/0
100% Functions 16/16
100% Lines 46/46
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106    1x 1x 1x 1x     1x 1x   1x   1x         1x 1x   1x   1x     1x 1x   1x   1x           1x 1x 1x     1x 1x   1x   1x               1x 1x   1x   1x     1x 1x   1x   1x       1x 1x 1x     1x 1x   1x   1x           1x 1x   1x   1x     1x 1x   1x   1x        
import { editorTypes } from './editorTypes'
 
describe('editorTypes', async () => {
  describe('json', async () => {
    it('returns valid mode for json', () => {
      expect(editorTypes.json.mode).toEqual('application/json')
    })
 
    it('formats json', () => {
      const sql = '{"valid": "json"}'
 
      const formatted = editorTypes.json.format(sql)
 
      expect(formatted).toEqual(`{
  "valid": "json"
}`)
    })
 
    it('parses json into object', () => {
      const json = '{"valid": "json"}'
 
      const object = editorTypes.json.parse(json)
 
      expect(object).toEqual({ valid: 'json' })
    })
 
    it('returns string representation of json object', () => {
      const json = { valid: 'json' }
 
      const string = editorTypes.json.toString(json)
 
      expect(string).toEqual(`{
  "valid": "json"
}`)
    })
  })
 
  describe('sql', async () => {
    it('returns valid mode for sql', () => {
      expect(editorTypes.sql.mode).toEqual('text/x-sql')
    })
 
    it('formats sql', () => {
      const sql = 'SELECT * FROM TestTable WHERE 1=1'
 
      const formatted = editorTypes.sql.format(sql)
 
      expect(formatted).toEqual(`SELECT
  *
FROM
  TestTable
WHERE
  1 = 1`)
    })
 
    it('parse function keeps sql the same', () => {
      const sql = 'SELECT * FROM TestTable WHERE 1=1'
 
      const string = editorTypes.sql.parse(sql)
 
      expect(string).toEqual(sql)
    })
 
    it('returns string representation of sql', () => {
      const sql = 'SELECT * FROM TestTable WHERE 1=1'
 
      const string = editorTypes.sql.toString(sql)
 
      expect(string).toEqual(sql)
    })
  })
 
  describe('html', async () => {
    it('returns valid mode for html', () => {
      expect(editorTypes.html.mode).toEqual('text/html')
    })
 
    it('formats html', () => {
      const html = '<html  attribute = "value"> <div> hi </div>  </html>'
 
      const formatted = editorTypes.html.format(html)
 
      expect(formatted).toEqual(`<html attribute="value">
  <div> hi </div>
 
</html>`)
    })
 
    it('parse function keeps html the same', () => {
      const html = '<html>a</html>'
 
      const string = editorTypes.html.parse(html)
 
      expect(string).toEqual(html)
    })
 
    it('returns string representation of html', () => {
      const html = '<html>a</html>'
 
      const string = editorTypes.html.toString(html)
 
      expect(string).toEqual(html)
    })
  })
})