-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial set of tests and move linting to Grunt task
Fixes #1
- Loading branch information
Showing
11 changed files
with
181 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["react", "es2015"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/*global expect React shallow Globalize*/ | ||
import FormatCurrency from "../dist/currency"; | ||
|
||
describe("formatCurrency Component", () => { | ||
it("renders as a <span>", () => { | ||
const wrapper = shallow(<FormatCurrency currency="USD">{150}</FormatCurrency>); | ||
expect(wrapper.type()).to.equal("span"); | ||
}); | ||
|
||
it("formats 150 as $150.00", () => { | ||
const wrapper = shallow(<FormatCurrency currency="USD">{150}</FormatCurrency>); | ||
expect(wrapper.text()).to.equal("$150.00"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*global expect React shallow Globalize*/ | ||
import FormatDate from "../dist/date"; | ||
|
||
describe("formatDate Component", () => { | ||
it("renders as a <span>", () => { | ||
const wrapper = shallow(<FormatDate options={{date: "medium"}}>{new Date()}</FormatDate>); | ||
expect(wrapper.type()).to.equal("span"); | ||
}); | ||
|
||
it("formats date using default pattern as 1/1/2016", () => { | ||
const wrapper = shallow(<FormatDate>{new Date("Jan 01 2016")}</FormatDate>); | ||
expect(wrapper.text()).to.equal("1/1/2016"); | ||
}); | ||
|
||
it("formats date using options 'Jan 1, 2016'", () => { | ||
const wrapper = shallow(<FormatDate options={{date: "medium"}}>{new Date(2016, 0, 1)}</FormatDate>); | ||
expect(wrapper.text()).to.equal("Jan 1, 2016"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/*global expect React shallow Globalize*/ | ||
import FormatMessage from "../dist/message"; | ||
|
||
Globalize.loadMessages({ | ||
en: { | ||
salutations: { | ||
hi: "Hi" | ||
}, | ||
variables: { | ||
hello: "Hello, {0} {1} {2}" | ||
}, | ||
party: [ | ||
"{hostGender, select,", | ||
" female {{host} invites {guest} to her party}", | ||
" male {{host} invites {guest} to his party}", | ||
" other {{host} invites {guest} to their party}", | ||
"}" | ||
], | ||
task: [ | ||
"You have {count, plural,", | ||
" =0 {no tasks}", | ||
" one {one task}", | ||
" other {{formattedCount} tasks}", | ||
"} remaining" | ||
] | ||
} | ||
}); | ||
|
||
describe("formatMessage Component", () => { | ||
it("renders as a <span>", () => { | ||
const wrapper = shallow(<FormatMessage path="salutations/hi" />); | ||
expect(wrapper.type()).to.equal("span"); | ||
}); | ||
|
||
it("uses default message and prints 'Hi'", () => { | ||
const wrapper = shallow(<FormatMessage>Hi</FormatMessage>); | ||
expect(wrapper.text()).to.equal("Hi"); | ||
}); | ||
|
||
it("resolves path and prints 'Hi'", () => { | ||
const wrapper = shallow(<FormatMessage path="salutations/hi" />); | ||
expect(wrapper.text()).to.equal("Hi"); | ||
}); | ||
|
||
it("properly replaces variables", () => { | ||
const wrapper = shallow(<FormatMessage path="variables/hello" variables={["Wolfgang", "Amadeus", "Mozart"]} />); | ||
expect(wrapper.text()).to.equal("Hello, Wolfgang Amadeus Mozart"); | ||
}); | ||
|
||
it("uses proper gender inflection", () => { | ||
const wrapper = shallow(<FormatMessage path="party" variables={{guest:"Mozart", guestGender:"male", host:"Beethoven", hostGender:"other"}} />); | ||
expect(wrapper.text()).to.equal("Beethoven invites Mozart to their party"); | ||
}); | ||
|
||
it("uses proper plural inflection", () => { | ||
const wrapper = shallow(<FormatMessage path="task" variables={{count: 1}} />); | ||
expect(wrapper.text()).to.equal("You have one task remaining"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/*global expect React shallow Globalize*/ | ||
import FormatNumber from "../dist/number"; | ||
|
||
describe("formatNumber Component", () => { | ||
it("renders as a <span>", () => { | ||
const wrapper = shallow(<FormatNumber options={{ round: "floor" }}>{Math.PI}</FormatNumber>); | ||
expect(wrapper.type()).to.equal("span"); | ||
}); | ||
|
||
it("formats pi as 3.141", () => { | ||
const wrapper = shallow(<FormatNumber options={{ round: "floor" }}>{Math.PI}</FormatNumber>); | ||
expect(wrapper.text()).to.equal("3.141"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/*global expect React shallow Globalize*/ | ||
import FormatRelativeTime from "../dist/relative-time"; | ||
|
||
describe("formatRelativeTime Component", () => { | ||
it("renders as a <span>", () => { | ||
const wrapper = shallow(<FormatRelativeTime unit="week">{1}</FormatRelativeTime>); | ||
expect(wrapper.type()).to.equal("span"); | ||
}); | ||
|
||
it("formats value of 1 week from now as 'next week'", () => { | ||
const wrapper = shallow(<FormatRelativeTime unit="week">{1}</FormatRelativeTime>); | ||
expect(wrapper.text()).to.equal("next week"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/*global expect React shallow Globalize*/ | ||
import FormatCurrency from "../dist/currency"; | ||
|
||
describe("General Functionality Tests", () => { | ||
it("overrides default locale to format 150 as 150,00 €", () => { | ||
const wrapper = shallow(<FormatCurrency locale="de" currency="EUR">{150}</FormatCurrency>); | ||
expect(wrapper.text()).to.equal("150,00 €"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { expect } from "chai"; | ||
import React from "react"; | ||
import { shallow } from "enzyme"; | ||
import Globalize from "globalize"; | ||
|
||
global.expect = expect; | ||
global.React = React; | ||
global.shallow = shallow; | ||
global.Globalize = Globalize; | ||
|
||
Globalize.load( | ||
require( "cldr-data" ).entireSupplemental(), | ||
require( "cldr-data" ).entireMainFor("en"), | ||
require( "cldr-data" ).entireMainFor("de") | ||
); | ||
|
||
Globalize.locale("en"); |