Skip to content

Commit cf63fd4

Browse files
committed
use jest for snapshot testing localized
1 parent cb6ff27 commit cf63fd4

17 files changed

+1598
-1506
lines changed

fluent-react/babel.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
"presets": [
3+
"@babel/preset-react",
4+
["@babel/preset-env", {
5+
"targets": "node >= 8.9.0"
6+
}]
7+
],
8+
"plugins": [
9+
["babel-plugin-transform-rename-import", {
10+
"original": "fluent",
11+
"replacement": "fluent/compat"
12+
}],
13+
"@babel/plugin-proposal-async-generator-functions"
14+
],
15+
};

fluent-react/package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,20 @@
5555
"react": "^0.14.9 || ^15.0.0 || ^16.0.0"
5656
},
5757
"devDependencies": {
58-
"@babel/preset-react": "^7.0.0-beta.47",
58+
"@babel/plugin-proposal-async-generator-functions": "^7.2.0",
59+
"@babel/preset-env": "^7.5.5",
60+
"@babel/preset-react": "7.0.0",
61+
"babel-jest": "^24.8.0",
5962
"babel-plugin-transform-rename-import": "^2.2.0",
60-
"enzyme": "^3.3.0",
61-
"enzyme-adapter-react-16": "^1.1.1",
62-
"jsdom": "^11.12.0",
63+
"jest": "^24.8.0",
64+
"prettier": "^1.18.2",
6365
"react": "^16.2.0",
6466
"react-dom": "^16.2.0",
65-
"react-test-renderer": "^16.8.6",
66-
"sinon": "^4.2.2"
67+
"react-test-renderer": "^16.8.6"
68+
},
69+
"jest": {
70+
"transformIgnorePatterns": [
71+
"node_modules/(?!(fluent-sequence)/)"
72+
]
6773
}
6874
}

fluent-react/test/.babelrc

Lines changed: 0 additions & 11 deletions
This file was deleted.

fluent-react/test/exports_test.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as FluentReact from '../src/index';
33
import LocalizationProvider from '../src/provider';
44
import Localized from '../src/localized';
55
import withLocalization from '../src/with_localization';
6-
import ReactLocalization, { isReactLocalization } from '../src/localization';
76

87
suite('Exports', () => {
98
test('LocalizationProvider', () => {
@@ -21,8 +20,4 @@ suite('Exports', () => {
2120
test('ReactLocalization', () => {
2221
assert.equal(FluentReact.ReactLocalization, ReactLocalization);
2322
});
24-
25-
test('isReactLocalization', () => {
26-
assert.equal(FluentReact.isReactLocalization, isReactLocalization);
27-
});
2823
});

fluent-react/test/index.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from "react";
2+
import TestRenderer from "react-test-renderer";
3+
import { FluentBundle } from "../../fluent/src";
4+
import { LocalizationProvider, Localized } from "../src/index";
5+
6+
test("relocalizes", () => {
7+
const Root = ({ bundle }) => (
8+
<LocalizationProvider bundles={[bundle]}>
9+
<Localized id="foo">
10+
<div />
11+
</Localized>
12+
</LocalizationProvider>
13+
);
14+
15+
const bundle1 = new FluentBundle();
16+
bundle1.addMessages(`
17+
foo = FOO
18+
`);
19+
const renderer = TestRenderer.create(<Root bundle={bundle1} />);
20+
expect(renderer.toJSON()).toMatchInlineSnapshot(`
21+
<div>
22+
FOO
23+
</div>
24+
`);
25+
26+
const bundle2 = new FluentBundle();
27+
bundle2.addMessages(`
28+
foo = BAR
29+
`);
30+
renderer.update(<Root bundle={bundle2} />);
31+
expect(renderer.toJSON()).toMatchInlineSnapshot(`
32+
<div>
33+
BAR
34+
</div>
35+
`);
36+
});

fluent-react/test/localized_change_test.js

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React from "react";
2+
import TestRenderer from "react-test-renderer";
3+
import { FluentBundle } from "../../fluent/src";
4+
import { LocalizationProvider, Localized } from "../src/index";
5+
6+
test("uses message from 1st bundle", () => {
7+
const bundle1 = new FluentBundle();
8+
9+
bundle1.addMessages(`
10+
foo = FOO
11+
`);
12+
13+
const renderer = TestRenderer.create(
14+
<LocalizationProvider bundles={[bundle1]}>
15+
<Localized id="foo">
16+
<div>Bar</div>
17+
</Localized>
18+
</LocalizationProvider>
19+
);
20+
21+
expect(renderer.toJSON()).toMatchInlineSnapshot(`
22+
<div>
23+
FOO
24+
</div>
25+
`);
26+
});
27+
28+
test("uses message from the 2nd bundle", function() {
29+
const bundle1 = new FluentBundle();
30+
const bundle2 = new FluentBundle();
31+
32+
bundle1.addMessages(`
33+
not-foo = NOT FOO
34+
`);
35+
bundle2.addMessages(`
36+
foo = FOO
37+
`);
38+
39+
const renderer = TestRenderer.create(
40+
<LocalizationProvider bundles={[bundle1, bundle2]}>
41+
<Localized id="foo">
42+
<div>Bar</div>
43+
</Localized>
44+
</LocalizationProvider>
45+
);
46+
47+
expect(renderer.toJSON()).toMatchInlineSnapshot(`
48+
<div>
49+
FOO
50+
</div>
51+
`);
52+
});
53+
54+
test("falls back back for missing message", function() {
55+
const bundle1 = new FluentBundle();
56+
57+
bundle1.addMessages(`
58+
not-foo = NOT FOO
59+
`);
60+
61+
const renderer = TestRenderer.create(
62+
<LocalizationProvider bundles={[bundle1]}>
63+
<Localized id="foo">
64+
<div>Bar</div>
65+
</Localized>
66+
</LocalizationProvider>
67+
);
68+
69+
expect(renderer.toJSON()).toMatchInlineSnapshot(`
70+
<div>
71+
Bar
72+
</div>
73+
`);
74+
});

fluent-react/test/localized_fallback_test.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)