@applicaster/zapp-react-native-utils
Version:
Applicaster Zapp React Native utilities package
162 lines (131 loc) • 4.33 kB
text/typescript
import { NativeModules } from "react-native";
const settingsManagerMock = {
getConstants: jest.fn(() => ({
settings: { AppleLanguages: ["en-US"] },
})),
};
const qbCommunicationModuleMock = {
languageLocale: "en",
countryLocale: "US",
uiLanguage: "en-US",
};
NativeModules.SettingsManager = settingsManagerMock;
NativeModules.QuickBrickCommunicationModule = qbCommunicationModuleMock;
describe("localizationUtils", () => {
beforeEach(() => {
jest.resetModules();
});
describe("when the app has a single locale", () => {
describe("when the app has only a RTL language as locale", () => {
beforeEach(() => {
jest.resetModules();
const RN = require("react-native");
RN.NativeModules.QuickBrickCommunicationModule = {
languageLocale: "he",
countryLocale: "IL",
uiLanguage: "he-HE",
};
});
it("useIsRTL returns true", () => {
const { useIsRTL } = require("../index");
expect(useIsRTL()).toBe(true);
});
});
describe("when the app has only a LTR language as locale", () => {
beforeEach(() => {
jest.resetModules();
const RN = require("react-native");
RN.NativeModules.QuickBrickCommunicationModule = {
languageLocale: "en",
countryLocale: "US",
uiLanguage: "en",
};
});
it("useIsRTL returns false", () => {
const { useIsRTL } = require("../index");
expect(useIsRTL()).toBe(false);
});
});
});
describe("when the app has several languages", () => {
describe("when device locale is in the app's locales", () => {
describe("when device locale is LTR", () => {
beforeEach(() => {
jest.resetModules();
const RN = require("react-native");
RN.NativeModules.QuickBrickCommunicationModule = {
languageLocale: "en",
countryLocale: "US",
uiLanguage: "en-US",
};
});
it("useIsRTL returns false", () => {
const { useIsRTL } = require("../index");
expect(useIsRTL()).toBe(false);
});
});
describe("when device locale is RTL", () => {
beforeEach(() => {
jest.resetModules();
const RN = require("react-native");
RN.NativeModules.QuickBrickCommunicationModule = {
languageLocale: "he",
countryLocale: "IL",
uiLanguage: "he",
};
});
it("useIsRTL returns true", () => {
const { useIsRTL } = require("../index");
expect(useIsRTL()).toBe(true);
});
});
describe("when a device has a secondary language in a supported language", () => {
beforeEach(() => {
jest.resetModules();
const RN = require("react-native");
RN.NativeModules.QuickBrickCommunicationModule = {
languageLocale: "he",
countryLocale: "IL",
uiLanguage: "he",
};
});
it("useIsRTL returns true", () => {
const { useIsRTL } = require("../index");
expect(useIsRTL()).toBe(true);
});
});
});
describe("when device locale is not in the app's locales", () => {
describe("when first app locale is LTR", () => {
beforeEach(() => {
jest.resetModules();
const RN = require("react-native");
RN.NativeModules.QuickBrickCommunicationModule = {
languageLocale: "fr",
countryLocale: "FR",
uiLanguage: "fr-FR",
};
});
it("useIsRTL returns false", () => {
const { useIsRTL } = require("../index");
expect(useIsRTL()).toBe(false);
});
});
describe("when first app locale is RTL", () => {
beforeEach(() => {
jest.resetModules();
const RN = require("react-native");
RN.NativeModules.QuickBrickCommunicationModule = {
languageLocale: "he",
countryLocale: "HE",
uiLanguage: "he",
};
});
it("useIsRTL returns true", () => {
const { useIsRTL } = require("../index");
expect(useIsRTL()).toBe(true);
});
});
});
});
});