|
1 |
| -/*global expect React shallow Globalize*/ |
2 |
| -import FormatMessage from "../src/message"; |
3 |
| - |
4 |
| -Globalize.loadMessages({ |
5 |
| - en: { |
6 |
| - salutations: { |
7 |
| - hi: "Hi" |
8 |
| - }, |
9 |
| - variables: { |
10 |
| - hello: "Hello, {0} {1} {2}" |
11 |
| - }, |
12 |
| - party: [ |
13 |
| - "{hostGender, select,", |
14 |
| - " female {{host} invites {guest} to her party}", |
15 |
| - " male {{host} invites {guest} to his party}", |
16 |
| - " other {{host} invites {guest} to their party}", |
17 |
| - "}" |
18 |
| - ], |
19 |
| - task: [ |
20 |
| - "You have {count, plural,", |
21 |
| - " =0 {no tasks}", |
22 |
| - " one {one task}", |
23 |
| - " other {{formattedCount} tasks}", |
24 |
| - "} remaining" |
25 |
| - ] |
26 |
| - } |
27 |
| -}); |
28 |
| - |
29 |
| -[ "development", "production" ].forEach((env) => { |
30 |
| - describe(`formatMessage Component (${env})`, () => { |
31 |
| - var originalEnv = process.env.NODE_ENV; |
32 |
| - |
33 |
| - before(() => { |
34 |
| - process.env.NODE_ENV = env; |
35 |
| - }); |
36 |
| - |
37 |
| - after(() => { |
38 |
| - process.env.NODE_ENV = originalEnv; |
39 |
| - }); |
40 |
| - |
41 |
| - it("renders as a <span>", () => { |
42 |
| - const wrapper = shallow(<FormatMessage path="salutations/hi" />); |
43 |
| - expect(wrapper.type()).to.equal("span"); |
44 |
| - }); |
45 |
| - |
46 |
| - it("uses default message and prints 'Hi'", () => { |
47 |
| - const wrapper = shallow(<FormatMessage>Hi</FormatMessage>); |
48 |
| - expect(wrapper.text()).to.equal("Hi"); |
49 |
| - }); |
50 |
| - |
51 |
| - it("resolves path and prints 'Hi'", () => { |
52 |
| - const wrapper = shallow(<FormatMessage path="salutations/hi" />); |
53 |
| - expect(wrapper.text()).to.equal("Hi"); |
54 |
| - }); |
55 |
| - |
56 |
| - it("properly replaces variables", () => { |
57 |
| - const wrapper = shallow(<FormatMessage path="variables/hello" variables={["Wolfgang", "Amadeus", "Mozart"]} />); |
58 |
| - expect(wrapper.text()).to.equal("Hello, Wolfgang Amadeus Mozart"); |
59 |
| - }); |
60 |
| - |
61 |
| - it("uses proper gender inflection", () => { |
62 |
| - const wrapper = shallow(<FormatMessage path="party" variables={{guest:"Mozart", guestGender:"male", host:"Beethoven", hostGender:"other"}} />); |
63 |
| - expect(wrapper.text()).to.equal("Beethoven invites Mozart to their party"); |
64 |
| - }); |
65 |
| - |
66 |
| - it("uses proper plural inflection", () => { |
67 |
| - const wrapper = shallow(<FormatMessage path="task" variables={{count: 1}} />); |
68 |
| - expect(wrapper.text()).to.equal("You have one task remaining"); |
69 |
| - }); |
70 |
| - |
71 |
| - it("updates when children change", () => { |
72 |
| - const wrapper = shallow(<FormatMessage>Hello</FormatMessage>); |
73 |
| - wrapper.setProps({ children: "Goodbye" }); |
74 |
| - expect(wrapper.text()).to.equal("Goodbye"); |
75 |
| - }); |
76 |
| - }); |
77 |
| -}); |
| 1 | +/*global expect React shallow Globalize*/ |
| 2 | +import FormatMessage from "../src/message"; |
| 3 | + |
| 4 | +Globalize.loadMessages({ |
| 5 | + en: { |
| 6 | + salutations: { |
| 7 | + hi: "Hi" |
| 8 | + }, |
| 9 | + variables: { |
| 10 | + hello: "Hello, {0} {1} {2}" |
| 11 | + }, |
| 12 | + party: [ |
| 13 | + "{hostGender, select,", |
| 14 | + " female {{host} invites {guest} to her party}", |
| 15 | + " male {{host} invites {guest} to his party}", |
| 16 | + " other {{host} invites {guest} to their party}", |
| 17 | + "}" |
| 18 | + ], |
| 19 | + task: [ |
| 20 | + "You have {count, plural,", |
| 21 | + " =0 {no tasks}", |
| 22 | + " one {one task}", |
| 23 | + " other {{formattedCount} tasks}", |
| 24 | + "} remaining" |
| 25 | + ] |
| 26 | + } |
| 27 | +}); |
| 28 | + |
| 29 | +[ "development", "production" ].forEach((env) => { |
| 30 | + describe(`formatMessage Component (${env})`, () => { |
| 31 | + var originalEnv = process.env.NODE_ENV; |
| 32 | + |
| 33 | + before(() => { |
| 34 | + process.env.NODE_ENV = env; |
| 35 | + }); |
| 36 | + |
| 37 | + after(() => { |
| 38 | + process.env.NODE_ENV = originalEnv; |
| 39 | + }); |
| 40 | + |
| 41 | + it("renders as a <span>", () => { |
| 42 | + const wrapper = shallow(<FormatMessage path="salutations/hi" />); |
| 43 | + expect(wrapper.type()).to.equal("span"); |
| 44 | + }); |
| 45 | + |
| 46 | + it("uses default message and prints 'Hi'", () => { |
| 47 | + const wrapper = shallow(<FormatMessage>Hi</FormatMessage>); |
| 48 | + expect(wrapper.text()).to.equal("Hi"); |
| 49 | + }); |
| 50 | + |
| 51 | + it("resolves path and prints 'Hi'", () => { |
| 52 | + const wrapper = shallow(<FormatMessage path="salutations/hi" />); |
| 53 | + expect(wrapper.text()).to.equal("Hi"); |
| 54 | + }); |
| 55 | + |
| 56 | + it("properly replaces variables", () => { |
| 57 | + const wrapper = shallow(<FormatMessage path="variables/hello" variables={["Wolfgang", "Amadeus", "Mozart"]} />); |
| 58 | + expect(wrapper.text()).to.equal("Hello, Wolfgang Amadeus Mozart"); |
| 59 | + }); |
| 60 | + |
| 61 | + it("uses proper gender inflection", () => { |
| 62 | + const wrapper = shallow(<FormatMessage path="party" variables={{guest:"Mozart", guestGender:"male", host:"Beethoven", hostGender:"other"}} />); |
| 63 | + expect(wrapper.text()).to.equal("Beethoven invites Mozart to their party"); |
| 64 | + }); |
| 65 | + |
| 66 | + it("uses proper plural inflection", () => { |
| 67 | + const wrapper = shallow(<FormatMessage path="task" variables={{count: 1}} />); |
| 68 | + expect(wrapper.text()).to.equal("You have one task remaining"); |
| 69 | + }); |
| 70 | + |
| 71 | + it("updates when children change", () => { |
| 72 | + const wrapper = shallow(<FormatMessage>Hello</FormatMessage>); |
| 73 | + wrapper.setProps({ children: "Goodbye" }); |
| 74 | + expect(wrapper.text()).to.equal("Goodbye"); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments