Interactive interface for browsing global, full-resolution satellite imagery
// @ts-check
const { test, expect } = require('@playwright/test')
const {
openImageDownloadPanel,
clickDownload,
closeModal
} = require('../../test-utils/hooks/wvHooks')
const { joinUrl } = require('../../test-utils/hooks/basicHooks')
const fs = require('fs')
const path = require('path')
/** @type {import('@playwright/test').Page} */
let page
/** @type {Promise<import("playwright-core").Download>} */
let downloadPromise
const downloadDir = 'test-downloads'
test.beforeAll(() => {
if (!fs.existsSync(downloadDir)) {
fs.mkdirSync(downloadDir)
}
})
test.beforeEach(async ({ browser }) => {
page = await browser.newPage()
downloadPromise = page.waitForEvent('download')
})
test.afterEach(async () => {
await page.close()
})
test.afterAll(() => {
if (fs.existsSync(downloadDir)) {
fs.rmdirSync(downloadDir, { recursive: true })
}
})
test('download KMZ format with larger area', async () => {
test.setTimeout(200_500)
const largeAreaParams = [
'l=MODIS_Terra_CorrectedReflectance_TrueColor',
'v=-10,-10,10,10', // Larger viewport
't=2018-06-01'
]
const url = await joinUrl(largeAreaParams, null)
await page.goto(url)
await closeModal(page)
await openImageDownloadPanel(page)
// Change format to KMZ
const formatSelect = page.locator('#wv-image-format')
await formatSelect.selectOption('application/vnd.google-earth.kmz')
// Set resolution to 1km for larger area
const resolutionSelect = page.locator('#wv-image-resolution')
await resolutionSelect.selectOption('1000')
await clickDownload(page)
await expect(page.locator('.wv-snapshot-progress-dialog')).toBeVisible()
const download = await downloadPromise
const suggestedFilename = download.suggestedFilename()
await expect(suggestedFilename).toMatch('snapshot-2018-06-01.kmz')
const filePath = path.join(downloadDir, suggestedFilename)
await download.saveAs(filePath)
expect(fs.existsSync(filePath)).toBeTruthy()
const fileStats = fs.statSync(filePath)
expect(fileStats.size).toBeGreaterThan(0)
fs.unlinkSync(filePath)
})
test('download with different date and layers', async () => {
test.setTimeout(200_500)
const multiLayerParams = [
'l=MODIS_Terra_CorrectedReflectance_TrueColor,MODIS_Aqua_CorrectedReflectance_TrueColor',
'v=-5,-5,5,5',
't=2020-01-15'
]
const url = await joinUrl(multiLayerParams, null)
await page.goto(url)
await closeModal(page)
await openImageDownloadPanel(page)
await clickDownload(page)
await expect(page.locator('.wv-snapshot-progress-dialog')).toBeVisible()
const download = await downloadPromise
const suggestedFilename = download.suggestedFilename()
await expect(suggestedFilename).toMatch('snapshot-2020-01-15.jpeg')
const filePath = path.join(downloadDir, suggestedFilename)
await download.saveAs(filePath)
expect(fs.existsSync(filePath)).toBeTruthy()
const fileStats = fs.statSync(filePath)
expect(fileStats.size).toBeGreaterThan(0)
fs.unlinkSync(filePath)
})
test('download Arctic projection with PNG format', async () => {
test.setTimeout(200_500)
const arcticParams = [
'p=arctic',
'l=MODIS_Terra_CorrectedReflectance_TrueColor',
'v=-1000000,-1000000,1000000,1000000',
't=2018-06-01'
]
const url = await joinUrl(arcticParams, null)
await page.goto(url)
await closeModal(page)
await openImageDownloadPanel(page)
// Change format to PNG (KMZ not available in polar projections)
const formatSelect = page.locator('#wv-image-format')
await formatSelect.selectOption('image/png')
// Set appropriate resolution for Arctic
const resolutionSelect = page.locator('#wv-image-resolution')
await resolutionSelect.selectOption('1000')
await clickDownload(page)
await expect(page.locator('.wv-snapshot-progress-dialog')).toBeVisible()
const download = await downloadPromise
const suggestedFilename = download.suggestedFilename()
await expect(suggestedFilename).toMatch('snapshot-2018-06-01.png')
const filePath = path.join(downloadDir, suggestedFilename)
await download.saveAs(filePath)
expect(fs.existsSync(filePath)).toBeTruthy()
const fileStats = fs.statSync(filePath)
expect(fileStats.size).toBeGreaterThan(0)
fs.unlinkSync(filePath)
})
test('download with high resolution (60m)', async () => {
test.setTimeout(200_500)
const highResParams = [
'l=MODIS_Terra_CorrectedReflectance_TrueColor',
'v=-0.5,-0.5,0.5,0.5', // Small area for high resolution
't=2018-06-01'
]
const url = await joinUrl(highResParams, null)
await page.goto(url)
await closeModal(page)
await openImageDownloadPanel(page)
// Set high resolution
const resolutionSelect = page.locator('#wv-image-resolution')
await resolutionSelect.selectOption('60')
await clickDownload(page)
await expect(page.locator('.wv-snapshot-progress-dialog')).toBeVisible()
const download = await downloadPromise
const suggestedFilename = download.suggestedFilename()
await expect(suggestedFilename).toMatch('snapshot-2018-06-01.jpeg')
const filePath = path.join(downloadDir, suggestedFilename)
await download.saveAs(filePath)
expect(fs.existsSync(filePath)).toBeTruthy()
const fileStats = fs.statSync(filePath)
expect(fileStats.size).toBeGreaterThan(0)
fs.unlinkSync(filePath)
})
test('download with Antarctic projection and GeoTIFF', async () => {
test.setTimeout(200_500)
const antarcticParams = [
'p=antarctic',
'l=MODIS_Terra_CorrectedReflectance_TrueColor',
'v=-1000000,-1000000,1000000,1000000',
't=2018-06-01'
]
const url = await joinUrl(antarcticParams, null)
await page.goto(url)
await closeModal(page)
await openImageDownloadPanel(page)
// Change format to GeoTIFF
const formatSelect = page.locator('#wv-image-format')
await formatSelect.selectOption('image/tiff')
// Set resolution to 500m
const resolutionSelect = page.locator('#wv-image-resolution')
await resolutionSelect.selectOption('500')
await clickDownload(page)
await expect(page.locator('.wv-snapshot-progress-dialog')).toBeVisible()
const download = await downloadPromise
const suggestedFilename = download.suggestedFilename()
await expect(suggestedFilename).toMatch('snapshot-2018-06-01.tif')
const filePath = path.join(downloadDir, suggestedFilename)
await download.saveAs(filePath)
expect(fs.existsSync(filePath)).toBeTruthy()
const fileStats = fs.statSync(filePath)
expect(fileStats.size).toBeGreaterThan(0)
fs.unlinkSync(filePath)
})