@applicaster/zapp-react-native-utils
Version:
Applicaster Zapp React Native utilities package
83 lines (67 loc) • 2.39 kB
text/typescript
jest.mock("@applicaster/zapp-react-native-redux/AppStore", () => ({
appStore: {
get: jest.fn(() => ({ languageCode: "en", countryLocale: "GB" })),
},
}));
const {
getLocale,
getLanguageCode,
getCountryCode,
toDayJSLocaleMap,
} = require("../localizationsHelper");
describe("getLocale", () => {
it("returns correct locale from window.navigator object", () => {
const locale = "en-gb";
global.window = { navigator: { language: locale } };
const expectedValue = locale;
const currentValue = getLocale();
expect(currentValue).toEqual(expectedValue);
});
it("returns locale in lower case", () => {
const locale = "EN-GB";
global.window = { navigator: { language: locale } };
const expectedValue = "en-gb";
const currentValue = getLocale();
expect(currentValue).toEqual(expectedValue);
});
});
describe("getLanguageCode", () => {
it("returns correct language code from window.navigator object", () => {
const locale = "en-gb";
global.window = { navigator: { language: locale } };
const expectedValue = "en";
const currentValue = getLanguageCode();
expect(currentValue).toEqual(expectedValue);
});
it("returns language code in lower case", () => {
const locale = "EN-GB";
global.window = { navigator: { language: locale } };
const expectedValue = "en";
const currentValue = getLanguageCode();
expect(currentValue).toEqual(expectedValue);
});
});
describe("getCountryCode", () => {
it("returns correct country code from window.navigator object", () => {
const locale = "en-gb";
global.window = { navigator: { language: locale } };
const expectedValue = "gb";
const currentValue = getCountryCode();
expect(currentValue).toEqual(expectedValue);
});
it("returns country code in lower case", () => {
const locale = "EN-GB";
global.window = { navigator: { language: locale } };
const expectedValue = "gb";
const currentValue = getCountryCode();
expect(currentValue).toEqual(expectedValue);
});
});
describe("toDayJSLocaleMap", () => {
const allZappLocales: string[] = require("./allZappLocales").default;
it.each(allZappLocales)("[%s] returns a valid dayjs locale", (locale) => {
const dayJSLocale = toDayJSLocaleMap(locale);
expect(dayJSLocale).toBeDefined();
expect(dayJSLocale).toMatchSnapshot();
});
});