dawarich/e2e/helpers/places.js

133 lines
4.4 KiB
JavaScript
Raw Normal View History

0.36.0 (#1952) * Implement OmniAuth GitHub authentication * Fix omniauth GitHub scope to include user email access * Remove margin-bottom * Implement Google OAuth2 authentication * Implement OIDC authentication for Dawarich using omniauth_openid_connect gem. * Add patreon account linking and patron checking service * Update docker-compose.yml to use boolean values instead of strings * Add support for KML files * Add tests * Update changelog * Remove patreon OAuth integration * Move omniauthable to a concern * Update an icon in integrations * Update changelog * Update app version * Fix family location sharing toggle * Move family location sharing to its own controller * Update changelog * Implement basic tagging functionality for places, allowing users to categorize and label places with custom tags. * Add places management API and tags feature * Add some changes related to places management feature * Fix some tests * Fix sometests * Add places layer * Update places layer to use Leaflet.Control.Layers.Tree for hierarchical layer control * Rework tag form * Add hashtag * Add privacy zones to tags * Add notes to places and manage place tags * Update changelog * Update e2e tests * Extract tag serializer to its own file * Fix some tests * Fix tags request specs * Fix some tests * Fix rest of the tests * Revert some changes * Add missing specs * Revert changes in place export/import code * Fix some specs * Fix PlaceFinder to only consider global places when finding existing places * Fix few more specs * Fix visits creator spec * Fix last tests * Update place creating modal * Add home location based on "Home" tagged place * Save enabled tag layers * Some fixes * Fix bug where enabling place tag layers would trigger saving enabled layers, overwriting with incomplete data * Update migration to use disable_ddl_transaction! and add up/down methods * Fix tag layers restoration and filtering logic * Update OIDC auto-registration and email/password registration settings * Fix potential xss
2025-11-24 13:45:09 -05:00
/**
* Places helper functions for Playwright tests
*/
/**
* Enable or disable the Places layer
* @param {Page} page - Playwright page object
* @param {boolean} enable - True to enable, false to disable
*/
export async function enablePlacesLayer(page, enable) {
// Wait a bit for Places control to potentially be created
await page.waitForTimeout(500);
// Check if Places control button exists
const placesControlBtn = page.locator('.leaflet-control-places-button');
const hasPlacesControl = await placesControlBtn.count() > 0;
if (hasPlacesControl) {
// Use Places control panel
const placesPanel = page.locator('.leaflet-control-places-panel');
const isPanelVisible = await placesPanel.evaluate((el) => {
return el.style.display !== 'none' && el.offsetParent !== null;
}).catch(() => false);
// Open panel if not visible
if (!isPanelVisible) {
await placesControlBtn.click();
await page.waitForTimeout(300);
}
// Toggle the "Show All Places" checkbox
const allPlacesCheckbox = page.locator('[data-filter="all"]');
if (await allPlacesCheckbox.isVisible()) {
const isChecked = await allPlacesCheckbox.isChecked();
if (enable && !isChecked) {
await allPlacesCheckbox.check();
await page.waitForTimeout(1000);
} else if (!enable && isChecked) {
await allPlacesCheckbox.uncheck();
await page.waitForTimeout(500);
}
}
} else {
// Fallback: Use Leaflet's layer control
await page.locator('.leaflet-control-layers').hover();
await page.waitForTimeout(300);
const placesLayerCheckbox = page.locator('.leaflet-control-layers-overlays label')
.filter({ hasText: 'Places' })
.locator('input[type="checkbox"]');
if (await placesLayerCheckbox.count() > 0) {
const isChecked = await placesLayerCheckbox.isChecked();
if (enable && !isChecked) {
await placesLayerCheckbox.check();
await page.waitForTimeout(1000);
} else if (!enable && isChecked) {
await placesLayerCheckbox.uncheck();
await page.waitForTimeout(500);
}
}
}
}
/**
* Check if the Places layer is currently visible on the map
* @param {Page} page - Playwright page object
* @returns {Promise<boolean>} - True if Places layer is visible
*/
export async function getPlacesLayerVisible(page) {
return await page.evaluate(() => {
const controller = window.Stimulus?.controllers.find(c => c.identifier === 'maps');
const placesLayer = controller?.placesManager?.placesLayer;
if (!placesLayer || !controller?.map) {
return false;
}
return controller.map.hasLayer(placesLayer);
});
}
/**
* Create a test place programmatically
* @param {Page} page - Playwright page object
* @param {string} name - Name of the place
* @param {number} latitude - Latitude coordinate
* @param {number} longitude - Longitude coordinate
*/
export async function createTestPlace(page, name, latitude, longitude) {
// Enable place creation mode
const createPlaceBtn = page.locator('#create-place-btn');
await createPlaceBtn.click();
await page.waitForTimeout(300);
// Simulate map click to open the creation popup
const mapContainer = page.locator('#map');
await mapContainer.click({ position: { x: 300, y: 300 } });
await page.waitForTimeout(500);
// Fill in the form
const nameInput = page.locator('[data-place-creation-target="nameInput"]');
await nameInput.fill(name);
// Set coordinates manually (overriding the auto-filled values from map click)
await page.evaluate(({ lat, lng }) => {
const latInput = document.querySelector('[data-place-creation-target="latitudeInput"]');
const lngInput = document.querySelector('[data-place-creation-target="longitudeInput"]');
if (latInput) latInput.value = lat.toString();
if (lngInput) lngInput.value = lng.toString();
}, { lat: latitude, lng: longitude });
// Set up a promise to wait for the place:created event
const placeCreatedPromise = page.evaluate(() => {
return new Promise((resolve) => {
document.addEventListener('place:created', (e) => {
resolve(e.detail);
}, { once: true });
});
});
// Submit the form
const submitBtn = page.locator('[data-place-creation-target="form"] button[type="submit"]');
await submitBtn.click();
// Wait for the place to be created
await placeCreatedPromise;
await page.waitForTimeout(500);
}