Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmooney committed Jul 1, 2024
1 parent d13e447 commit cc30eb9
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/base/src/layerBrowser/layerBrowserDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class LayerBrowserWidget extends ReactWidget {

constructor(model: IJupyterGISModel, registry: IRasterLayerGalleryEntry[]) {
super();
this.id = 'jupytergis::layersBrowser';
this.id = 'jupytergis::layerBrowser';
this._model = model;
this._registry = registry;
}
Expand Down
127 changes: 127 additions & 0 deletions ui-tests/tests/layer-browser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import {
IJupyterLabPageFixture,
expect,
galata,
test
} from '@jupyterlab/galata';
import { Locator } from '@playwright/test';
import path from 'path';

// async function openLayerBrowser(
// page: IJupyterLabPageFixture
// ): Promise<Locator> {
// const mainDockPanel = page.locator('#jp-main-dock-panel');
// if (!(await mainDockPanel.isVisible())) {
// const panelIcon = page.getByTitle('JupyterGIS Control Panel');
// await panelIcon.first().click();
// await page.waitForCondition(async () => await mainDockPanel.isVisible());
// }
// return mainDockPanel;
// }

// test.describe('#overview', () => {
// test('should have a left panel', async ({ page }) => {
// const panelIcon = page.getByTitle('JupyterGIS Control Panel');
// await expect(panelIcon).toHaveCount(2);

// await panelIcon.first().click();

// const sidePanel = page.locator('#jupytergis\\:\\:leftControlPanel');
// await expect(sidePanel).toBeVisible();

// await expect(sidePanel.getByTitle('Layer tree')).toHaveCount(1);
// });
// });

async function openLayerBrowser(
page: IJupyterLabPageFixture
): Promise<Locator> {
const layerBrowser = page.locator('#jupytergis\\:\\:layerBrowser');

if (!(await layerBrowser.isVisible())) {
await page.getByTitle('Open Layer Browser').locator('div').click();
await page.waitForCondition(async () => await layerBrowser.isVisible());
}
return layerBrowser;
}

async function getGridTiles(page: IJupyterLabPageFixture): Promise<Locator> {
const layerBrowser = await openLayerBrowser(page);

const gridTiles = layerBrowser.locator(
'.jgis-layer-browser-container .jgis-layer-browser-grid .jgis-layer-browser-tile'
);

return gridTiles;
}

test.describe('#layerBrowser', () => {
test.beforeAll(async ({ request }) => {
const content = galata.newContentsHelper(request);
await content.deleteDirectory('/examples');
await content.uploadDirectory(
path.resolve(__dirname, '../../examples'),
'/examples'
);
});

test.beforeEach(async ({ page }) => {
await page.filebrowser.open('examples/test.jGIS');
});

test.afterEach(async ({ page }) => {
await page.activity.closeAll();
});

test('toolbar should have layer browser icon', async ({ page }) => {
const toolbarIcon = page.getByTitle('Open Layer Browser').locator('div');
await expect(toolbarIcon).toBeVisible();
});

test('layer browser should open when clicked', async ({ page }) => {
const layerBrowser = await openLayerBrowser(page);
await expect(layerBrowser).toBeVisible();
});

test('layer browser should be populated', async ({ page }) => {
const layerBrowser = await openLayerBrowser(page);

const gridTiles = layerBrowser.locator(
'.jgis-layer-browser-container .jgis-layer-browser-grid .jgis-layer-browser-tile'
);
await expect(gridTiles).toHaveCount(32);

Check failure on line 92 in ui-tests/tests/layer-browser.spec.ts

View workflow job for this annotation

GitHub Actions / Integration tests

tests/layer-browser.spec.ts:86:7 › #layerBrowser › layer browser should be populated

1) tests/layer-browser.spec.ts:86:7 › #layerBrowser › layer browser should be populated ────────── Error: Timed out 5000ms waiting for expect(locator).toHaveCount(expected) Locator: locator('#jupytergis\\:\\:layerBrowser').locator('.jgis-layer-browser-container .jgis-layer-browser-grid .jgis-layer-browser-tile') Expected: 32 Received: 37 Call log: - expect.toHaveCount with timeout 5000ms - waiting for locator('#jupytergis\\:\\:layerBrowser').locator('.jgis-layer-browser-container .jgis-layer-browser-grid .jgis-layer-browser-tile') - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" 90 | '.jgis-layer-browser-container .jgis-layer-browser-grid .jgis-layer-browser-tile' 91 | ); > 92 | await expect(gridTiles).toHaveCount(32); | ^ 93 | }); 94 | 95 | test('search bar should filter tiles', async ({ page }) => { at /home/runner/work/jupytergis/jupytergis/ui-tests/tests/layer-browser.spec.ts:92:29

Check failure on line 92 in ui-tests/tests/layer-browser.spec.ts

View workflow job for this annotation

GitHub Actions / Integration tests

tests/layer-browser.spec.ts:86:7 › #layerBrowser › layer browser should be populated

1) tests/layer-browser.spec.ts:86:7 › #layerBrowser › layer browser should be populated ────────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveCount(expected) Locator: locator('#jupytergis\\:\\:layerBrowser').locator('.jgis-layer-browser-container .jgis-layer-browser-grid .jgis-layer-browser-tile') Expected: 32 Received: 37 Call log: - expect.toHaveCount with timeout 5000ms - waiting for locator('#jupytergis\\:\\:layerBrowser').locator('.jgis-layer-browser-container .jgis-layer-browser-grid .jgis-layer-browser-tile') - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" 90 | '.jgis-layer-browser-container .jgis-layer-browser-grid .jgis-layer-browser-tile' 91 | ); > 92 | await expect(gridTiles).toHaveCount(32); | ^ 93 | }); 94 | 95 | test('search bar should filter tiles', async ({ page }) => { at /home/runner/work/jupytergis/jupytergis/ui-tests/tests/layer-browser.spec.ts:92:29
});

test('search bar should filter tiles', async ({ page }) => {
const gridTiles = await getGridTiles(page);
await page.getByPlaceholder('Search...').click();
await page.getByPlaceholder('Search...').fill('mapnik');
await expect(gridTiles).toHaveCount(1);
});

test('category filters should work', async ({ page }) => {
const gridTiles = await getGridTiles(page);
await page.getByText('Strava', { exact: true }).click();
await expect(gridTiles).toHaveCount(5);
});

test('clicking category filter twice should clear filter', async ({
page
}) => {
const gridTiles = await getGridTiles(page);
await page.getByText('WaymarkedTrails', { exact: true }).click();
await page.getByText('WaymarkedTrails', { exact: true }).click();
await expect(gridTiles).toHaveCount(32);

Check failure on line 114 in ui-tests/tests/layer-browser.spec.ts

View workflow job for this annotation

GitHub Actions / Integration tests

tests/layer-browser.spec.ts:108:7 › #layerBrowser › clicking category filter twice should clear filter

2) tests/layer-browser.spec.ts:108:7 › #layerBrowser › clicking category filter twice should clear filter Error: Timed out 5000ms waiting for expect(locator).toHaveCount(expected) Locator: locator('#jupytergis\\:\\:layerBrowser').locator('.jgis-layer-browser-container .jgis-layer-browser-grid .jgis-layer-browser-tile') Expected: 32 Received: 37 Call log: - expect.toHaveCount with timeout 5000ms - waiting for locator('#jupytergis\\:\\:layerBrowser').locator('.jgis-layer-browser-container .jgis-layer-browser-grid .jgis-layer-browser-tile') - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" 112 | await page.getByText('WaymarkedTrails', { exact: true }).click(); 113 | await page.getByText('WaymarkedTrails', { exact: true }).click(); > 114 | await expect(gridTiles).toHaveCount(32); | ^ 115 | }); 116 | 117 | // test('raster layer should have icons', async ({ page }) => { at /home/runner/work/jupytergis/jupytergis/ui-tests/tests/layer-browser.spec.ts:114:29

Check failure on line 114 in ui-tests/tests/layer-browser.spec.ts

View workflow job for this annotation

GitHub Actions / Integration tests

tests/layer-browser.spec.ts:108:7 › #layerBrowser › clicking category filter twice should clear filter

2) tests/layer-browser.spec.ts:108:7 › #layerBrowser › clicking category filter twice should clear filter Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveCount(expected) Locator: locator('#jupytergis\\:\\:layerBrowser').locator('.jgis-layer-browser-container .jgis-layer-browser-grid .jgis-layer-browser-tile') Expected: 32 Received: 37 Call log: - expect.toHaveCount with timeout 5000ms - waiting for locator('#jupytergis\\:\\:layerBrowser').locator('.jgis-layer-browser-container .jgis-layer-browser-grid .jgis-layer-browser-tile') - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" - locator resolved to 37 elements - unexpected value "37" 112 | await page.getByText('WaymarkedTrails', { exact: true }).click(); 113 | await page.getByText('WaymarkedTrails', { exact: true }).click(); > 114 | await expect(gridTiles).toHaveCount(32); | ^ 115 | }); 116 | 117 | // test('raster layer should have icons', async ({ page }) => { at /home/runner/work/jupytergis/jupytergis/ui-tests/tests/layer-browser.spec.ts:114:29
});

// test('raster layer should have icons', async ({ page }) => {
// const layersTree = await openLayerBrowser(page);
// const layerIcons = layersTree.locator(
// '.jp-gis-layer .jp-gis-layerIcon svg'
// );

// expect(await layerIcons.first().screenshot()).toMatchSnapshot(
// 'raster-layer-icon.png'
// );
// });
});

0 comments on commit cc30eb9

Please sign in to comment.