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

4
src/lib/geo-region.ts

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

Loading…
Cancel
Save