Browse Source

fix(geo): optimize geo-region listener and tests

master
mortezaei 3 days ago
parent
commit
6585535310
  1. 30
      src/components/Componentes/question-phone.test.tsx
  2. 4
      src/lib/geo-region.ts

30
src/components/Componentes/question-phone.test.tsx

@ -103,7 +103,7 @@ describe("QuestionPhone IP country detection and shimmer", () => {
expect(input.classList.contains("shimmer-bg")).toBe(false);
await act(async () => {
flutterListeners.forEach((l) =>
flutterListeners.forEach((l) => {
l({
action: "get_location",
success: true,
@ -111,8 +111,8 @@ describe("QuestionPhone IP country detection and shimmer", () => {
country: "Iran",
country_code: "IR",
},
}),
);
});
});
});
await waitFor(() => {
@ -128,12 +128,12 @@ describe("QuestionPhone IP country detection and shimmer", () => {
const { container } = render(<QuestionPhone question={phoneQuestion1} />);
await act(async () => {
flutterListeners.forEach((l) =>
flutterListeners.forEach((l) => {
l({
action: "get_location",
success: false,
}),
);
});
});
});
await waitFor(() => {
@ -173,7 +173,7 @@ describe("QuestionPhone IP country detection and shimmer", () => {
);
await act(async () => {
flutterListeners.forEach((l) =>
flutterListeners.forEach((l) => {
l({
action: "get_location",
success: true,
@ -181,8 +181,8 @@ describe("QuestionPhone IP country detection and shimmer", () => {
country: "Iran",
country_code: "IR",
},
}),
);
});
});
});
await waitFor(() => {
@ -213,7 +213,7 @@ describe("QuestionPhone IP country detection and shimmer", () => {
fireEvent.change(input, { target: { value: "7400123456" } });
await act(async () => {
flutterListeners.forEach((l) =>
flutterListeners.forEach((l) => {
l({
action: "get_location",
success: true,
@ -221,8 +221,8 @@ describe("QuestionPhone IP country detection and shimmer", () => {
country: "Iran",
country_code: "IR",
},
}),
);
});
});
});
expect(screen.getByDisplayValue("7400 123456")).toBeDefined();
@ -255,7 +255,7 @@ describe("QuestionPhone IP country detection and shimmer", () => {
expect(input.placeholder).toBe("7400 123456");
await act(async () => {
flutterListeners.forEach((l) =>
flutterListeners.forEach((l) => {
l({
action: "get_location",
success: true,
@ -263,8 +263,8 @@ describe("QuestionPhone IP country detection and shimmer", () => {
country: "Iran",
country_code: "IR",
},
}),
);
});
});
});
await waitFor(() => {

4
src/lib/geo-region.ts

@ -65,7 +65,9 @@ export function setStoredUserGeoRegion(region: UserGeoRegion) {
}
} catch {}
}
listeners.forEach((fn) => fn(region));
listeners.forEach((fn) => {
fn(region);
});
}
function resolvePhoneCodeFromCountryCode(isoCode?: string): string | undefined {

Loading…
Cancel
Save