Keep the iOS status bar outside the Capacitor web view and replace startup geolocation watching with silent permission checks plus an explicit location action. Verified by full unit, App Store readiness, Qodana, production build, Capacitor sync, and Playwright mobile suites.
91 lines
2.5 KiB
JavaScript
91 lines
2.5 KiB
JavaScript
// @vitest-environment jsdom
|
|
import { defineComponent, h, nextTick } from "vue";
|
|
import { mount } from "@vue/test-utils";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const locationMocks = vi.hoisted(() => ({
|
|
getCurrentDeviceLocation: vi.fn(),
|
|
set: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@/services/deviceLocation", () => ({
|
|
getCurrentDeviceLocation: locationMocks.getCurrentDeviceLocation,
|
|
}));
|
|
|
|
vi.mock("@/components/displays/department/pos/steps/mobile/objects/PosDepartmentStepMobileFlow.vue", () => ({
|
|
locations: {
|
|
normalizeCoordinatePair: (coords) => coords,
|
|
set: locationMocks.set,
|
|
},
|
|
default: defineComponent({
|
|
render: () => h("div"),
|
|
}),
|
|
}));
|
|
|
|
import PosDepartmentStepMobile1Location from "@/components/displays/department/pos/steps/mobile/elements/PosDepartmentStepMobile1Location.vue";
|
|
|
|
const mountLocation = () =>
|
|
mount(PosDepartmentStepMobile1Location, {
|
|
global: {
|
|
mocks: {
|
|
$t: (key) => key,
|
|
},
|
|
},
|
|
});
|
|
|
|
describe("mobile location permission control", () => {
|
|
beforeEach(() => {
|
|
locationMocks.getCurrentDeviceLocation.mockReset();
|
|
locationMocks.set.mockReset();
|
|
});
|
|
|
|
it("checks silently on mount and prompts only from the location button", async () => {
|
|
locationMocks.getCurrentDeviceLocation
|
|
.mockResolvedValueOnce({
|
|
permission: "prompt",
|
|
coords: null,
|
|
timestamp: null,
|
|
errorCode: null,
|
|
errorMessage: null,
|
|
})
|
|
.mockResolvedValueOnce({
|
|
permission: "granted",
|
|
coords: {
|
|
latitude: 55.6761,
|
|
longitude: 12.5683,
|
|
},
|
|
timestamp: 1_721_234_567_890,
|
|
errorCode: null,
|
|
errorMessage: null,
|
|
});
|
|
|
|
const wrapper = mountLocation();
|
|
await nextTick();
|
|
await nextTick();
|
|
|
|
expect(locationMocks.getCurrentDeviceLocation).toHaveBeenNthCalledWith(
|
|
1,
|
|
expect.objectContaining({ promptIfNeeded: false })
|
|
);
|
|
expect(wrapper.get('[data-testid="location-permission-control"]').exists()).toBe(true);
|
|
|
|
await wrapper.get('[data-testid="location-permission-action"]').trigger("click");
|
|
await nextTick();
|
|
await nextTick();
|
|
|
|
expect(locationMocks.getCurrentDeviceLocation).toHaveBeenNthCalledWith(
|
|
2,
|
|
expect.objectContaining({ promptIfNeeded: true })
|
|
);
|
|
expect(locationMocks.set).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
coords: {
|
|
latitude: 55.6761,
|
|
longitude: 12.5683,
|
|
},
|
|
})
|
|
);
|
|
expect(wrapper.emitted("location-updated")).toEqual([[{ latitude: 55.6761, longitude: 12.5683 }]]);
|
|
});
|
|
});
|