|
| 1 | +/* globals describe, expect, it */ |
| 2 | + |
| 3 | +const testFile = ` |
| 4 | +import messages, { analysis, project as proj } from '../utils/messages' |
| 5 | +import Component, { React, PropTypes } from 'react' |
| 6 | +
|
| 7 | +const test = messages.common.download |
| 8 | +const test2 = messages.common.downloadRegional |
| 9 | +const test3 = <div>{analysis.run}</div> |
| 10 | +const test3b = <div>{analysis.stop}</div> |
| 11 | +const test4 = analysis.stop |
| 12 | +const test5 = proj.new |
| 13 | +// handle multiple messages in one line |
| 14 | +const test6 = test5 ? proj.delete : proj.new |
| 15 | +const test7 = test6 ? proj.new : proj.delete |
| 16 | +const test8 = test7 ? messages.common.runRegional : messages.common.stopRegional |
| 17 | +` |
| 18 | + |
| 19 | +// test messages, some of the referenced messages are undefined |
| 20 | +const testMessages = { |
| 21 | + common: { |
| 22 | + download: 'Download' |
| 23 | + }, |
| 24 | + analysis: { |
| 25 | + run: 'Run' |
| 26 | + }, |
| 27 | + project: { |
| 28 | + new: 'New' |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +describe('lint-messages', () => { |
| 33 | + const { lintFileContents, parseImportLine } = require('../../lib/lint-messages') |
| 34 | + it('should parse root import correctly', () => { |
| 35 | + expect(parseImportLine("import msgs from '../utils/messages'")) |
| 36 | + .toMatchSnapshot("import msgs from '../utils/messages'") |
| 37 | + }) |
| 38 | + |
| 39 | + it('should parse named imports correctly', () => { |
| 40 | + expect(parseImportLine("import { analysis, project as proj } from '../utils/messages'")) |
| 41 | + .toMatchSnapshot("import { analysis, project as proj } from '../utils/messages'") |
| 42 | + |
| 43 | + // make sure it works when spacing is smaller |
| 44 | + expect(parseImportLine("import {analysis, project as proj} from '../utils/messages'")) |
| 45 | + .toMatchSnapshot("import {analysis, project as proj} from '../utils/messages'") |
| 46 | + }) |
| 47 | + |
| 48 | + it('should parse named and default imports together correctly', () => { |
| 49 | + expect(parseImportLine("import messages, { analysis, project as proj } from '../utils/messages'")) |
| 50 | + .toMatchSnapshot("import messages, { analysis, project as proj } from '../utils/messages'") |
| 51 | + |
| 52 | + // try it with the default import after the named imports |
| 53 | + expect(parseImportLine("import { analysis, project as proj }, messages from '../utils/messages'")) |
| 54 | + .toMatchSnapshot("import { analysis, project as proj }, messages from '../utils/messages'") |
| 55 | + }) |
| 56 | + |
| 57 | + it('should lint file', () => { |
| 58 | + expect(lintFileContents(testMessages, testFile)).toMatchSnapshot() |
| 59 | + }) |
| 60 | +}) |
0 commit comments