Skip to content

Commit

Permalink
test API
Browse files Browse the repository at this point in the history
  • Loading branch information
mluena committed Jan 15, 2025
1 parent 2c6212b commit 99c6a3c
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 58 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules

ENV NEXT_PUBLIC_API_URL https://g3w.earthmonitor.org/dev
ENV NEXT_PUBLIC_API_URL https://g3w.earthmonitor.org
/
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
Expand All @@ -25,7 +25,7 @@ FROM deps AS runner
WORKDIR /app

ENV NODE_ENV production
ENV NEXT_PUBLIC_API_URL https://g3w.earthmonitor.org/dev
ENV NEXT_PUBLIC_API_URL https://g3w.earthmonitor.org
/
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED 1
Expand Down
15 changes: 8 additions & 7 deletions e2e/datasets-hub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ test.beforeEach(async ({ page }) => {
});

test('geostories and monitors display', async ({ page }) => {
console.log(process.env.NEXT_PUBLIC_API_URL);
const datasetsResponse = await page.waitForResponse(
'https://g3w.earthmonitor.org/dev/monitors-and-geostories*'
`${process.env.NEXT_PUBLIC_API_URL}/monitors-and-geostories*?responseformat=json`
);

const datasetsData = (await datasetsResponse.json()) as MonitorsAndGeostoriesPaginated;

const pageLength = datasetsData['monitors and geostories'].length;
const pageLength = datasetsData['results'].length;

const datasetCard = page.getByTestId('datasets-list').locator('li');
const maxResultShown = pageLength;
Expand All @@ -29,17 +30,17 @@ test('geostories and monitors display', async ({ page }) => {
await expect(resultNumber).toHaveText(result);
});

test.describe('monitors and geostories display', () => {
test.describe('results display', () => {
test('monitors display', async ({ page }) => {
const monitorsCheckbox = page.getByTestId('monitors-button-checkbox');
await monitorsCheckbox.click();

const monitorsResponse = await page.waitForResponse(
'https://g3w.earthmonitor.org/dev/monitors-and-geostories?type=monitors*'
`${process.env.NEXT_PUBLIC_API_URL}/monitors-and-geostories?type=monitors*`
);

const monitorsData = (await monitorsResponse.json()) as MonitorsAndGeostoriesPaginated;
const firstMonitorWithData = monitorsData['monitors and geostories'].find(
const firstMonitorWithData = monitorsData['results'].find(
(monitor) => monitor.ready && monitor.description !== null
) as Monitor;

Expand Down Expand Up @@ -87,11 +88,11 @@ test.describe('monitors and geostories display', () => {
await geostoriesCheckbox.click();

const geostoriesResponse = await page.waitForResponse(
'https://g3w.earthmonitor.org/dev/monitors-and-geostories?type=geostories*'
'https://g3w.earthmonitor.org/monitors-and-geostories?type=geostories*'
);

const geostoriesData = (await geostoriesResponse.json()) as MonitorsAndGeostoriesPaginated;
const firstGeostoryWithData = geostoriesData['monitors and geostories'].find(
const firstGeostoryWithData = geostoriesData['results'].find(
(geostory) => geostory.ready && geostory.description !== null
) as Geostory;

Expand Down
14 changes: 7 additions & 7 deletions e2e/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test, expect } from '@playwright/test';

import type { MonitorsAndGeostoriesPaginated } from '@/types/monitors-and-geostories';

const API_URL = 'https://g3w.earthmonitor.org/dev';
const API_URL = 'https://g3w.earthmonitor.org';
test.beforeEach(async ({ page }) => {
await page.goto('/');
});
Expand All @@ -14,26 +14,26 @@ test.describe('search of monitors and geostories', () => {
const searchInput = page.getByTestId('search-input');

const searchPromise = page.waitForResponse(`${API_URL}?*title=*`);
await searchInput.fill(datasetsData['monitors and geostories'][0].title);
await searchInput.fill(datasetsData['results'][0].title);
const filteredResponse = await searchPromise;
const inputValue = await searchInput.inputValue();
const filteredJson = (await filteredResponse.json()) as MonitorsAndGeostoriesPaginated;

expect(filteredJson['monitors and geostories'][0].title).toEqual(inputValue);
expect(filteredJson['results'][0].title).toEqual(inputValue);

// check that the number of results is displayed accurately
await expect(page.getByTestId('datasets-result')).toBeVisible();
if (filteredJson['monitors and geostories'].length === 1) {
if (filteredJson['results'].length === 1) {
await expect(page.getByTestId('datasets-result')).toHaveText('1 result');
} else if (filteredJson['monitors and geostories'].length > 1) {
} else if (filteredJson['results'].length > 1) {
await expect(page.getByTestId('datasets-result')).toHaveText(
`${filteredJson['monitors and geostories'].length} results`
`${filteredJson['results'].length} results`
);
}

// check that the no results disclaimer is displayed
const noResultsDisclaimer = page.getByTestId('no-results-found');
if (!filteredJson['monitors and geostories'].length) {
if (!filteredJson['results'].length) {
await expect(noResultsDisclaimer).toBeVisible();
}
});
Expand Down
26 changes: 12 additions & 14 deletions e2e/theme-filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ test.beforeEach(async ({ page }) => {
test.describe('filter monitors and geostories by different theme', () => {
test('Filter by theme Soil', async ({ page, request }) => {
const response = await request.get(
'https://g3w.earthmonitor.org/dev/monitors-and-geostories?theme=Soil&pagination=true'
`${process.env.NEXT_PUBLIC_API_URL}monitors-and-geostories?theme=Soil&pagination=true`
);
const datasetsData = (await response.json()) as MonitorsAndGeostoriesPaginated;

await page.getByTestId('themes-filter').click();
await page.getByTestId('Soil-checkbox').setChecked(true);

const filteredResponse = await page.waitForResponse(
`https://g3w.earthmonitor.org/dev/monitors-and-geostories?*theme=Soil*`
`${process.env.NEXT_PUBLIC_API_URL}monitors-and-geostories?*theme=Soil*`
);
const filteredJson = (await filteredResponse.json()) as MonitorsAndGeostoriesPaginated;

expect(filteredJson['monitors and geostories']).toEqual(
datasetsData['monitors and geostories']
);
expect(filteredJson['results']).toEqual(datasetsData['results']);

// check that the badge is displayed accurately
await expect(page.getByTestId('Soil-button')).toBeVisible();
Expand All @@ -32,7 +30,7 @@ test.describe('filter monitors and geostories by different theme', () => {

test(`Filter by themes Agriculture and Climate & Health`, async ({ page, request }) => {
const response = await request.get(
'https://g3w.earthmonitor.org/dev/monitors-and-geostories?theme=Climate+%26+Health,Agriculture&pagination=true'
`https://g3w.earthmonitor.org/dev/monitors-and-geostories?theme=Climate+%26+Health,Agriculture&pagination=true`
);
const datasetsData = (await response.json()) as MonitorsAndGeostoriesPaginated;

Expand All @@ -46,7 +44,7 @@ test(`Filter by themes Agriculture and Climate & Health`, async ({ page, request
const filteredResponse = await responsePromise;
const filteredJson = (await filteredResponse.json()) as MonitorsAndGeostoriesPaginated;

expect(filteredJson['monitors and geostories']).toEqual(datasetsData['monitors and geostories']);
expect(filteredJson['results']).toEqual(datasetsData['results']);

// check that the badge is displayed accurately
await expect(page.getByTestId('Agriculture-button')).toBeVisible();
Expand All @@ -55,7 +53,7 @@ test(`Filter by themes Agriculture and Climate & Health`, async ({ page, request

test(`Filter by themes Soil and Water`, async ({ page, request }) => {
const response = await request.get(
'https://g3w.earthmonitor.org/dev/monitors-and-geostories?theme=Water,Soil&pagination=true'
`${process.env.NEXT_PUBLIC_API_URL}monitors-and-geostories?theme=Water,Soil&pagination=true`
);
const datasetsData = (await response.json()) as MonitorsAndGeostoriesPaginated;

Expand All @@ -64,12 +62,12 @@ test(`Filter by themes Soil and Water`, async ({ page, request }) => {
await page.getByTestId('Water-checkbox').setChecked(true);

const responsePromise = page.waitForResponse(
`https://g3w.earthmonitor.org/dev/monitors-and-geostories?*theme=Water,Soil*`
`${process.env.NEXT_PUBLIC_API_URL}monitors-and-geostories?*theme=Water,Soil*`
);
const filteredResponse = await responsePromise;
const filteredJson = (await filteredResponse.json()) as MonitorsAndGeostoriesPaginated;

expect(filteredJson['monitors and geostories']).toEqual(datasetsData['monitors and geostories']);
expect(filteredJson['results']).toEqual(datasetsData['results']);

// check that the badge is displayed accurately
await expect(page.getByTestId('Soil-button')).toBeVisible();
Expand All @@ -83,7 +81,7 @@ test.describe('Cards and badges displayed according selected themes', () => {
await page.getByTestId('Water-checkbox').setChecked(true);

const responsePromise = page.waitForResponse(
'https://g3w.earthmonitor.org/dev/monitors-and-geostories?*theme=Water,Soil*'
`${process.env.NEXT_PUBLIC_API_URL}monitors-and-geostories?*theme=Water,Soil*`
);
const filteredResponse = await responsePromise;
const filteredJson = (await filteredResponse.json()) as MonitorsAndGeostoriesPaginated;
Expand All @@ -92,7 +90,7 @@ test.describe('Cards and badges displayed according selected themes', () => {
const datasetsLists = page.getByTestId('datasets-list');
const datasetsListsItems = await datasetsLists.locator('> li').count();

expect(datasetsListsItems).toBe(filteredJson['monitors and geostories'].length);
expect(datasetsListsItems).toBe(filteredJson['results'].length);

// check that the badges are displayed accurately
await expect(page.getByTestId('Soil-button')).toBeVisible();
Expand All @@ -105,7 +103,7 @@ test.describe('Cards and badges displayed according selected themes', () => {
await page.getByTestId('Agriculture-checkbox').setChecked(true);

const responsePromise = page.waitForResponse(
'https://g3w.earthmonitor.org/dev/monitors-and-geostories?*theme=Agriculture,Forest,Biodiversity*'
`${process.env.NEXT_PUBLIC_API_URL}monitors-and-geostories?*theme=Agriculture,Forest,Biodiversity*`
);
const filteredResponse = await responsePromise;
const filteredJson = (await filteredResponse.json()) as MonitorsAndGeostoriesPaginated;
Expand All @@ -114,7 +112,7 @@ test.describe('Cards and badges displayed according selected themes', () => {
const datasetsLists = page.getByTestId('datasets-list');
const datasetsListsItems = await datasetsLists.locator('> li').count();

expect(datasetsListsItems).toBe(filteredJson['monitors and geostories'].length);
expect(datasetsListsItems).toBe(filteredJson['results'].length);

// check that the badges are displayed accurately
await expect(page.getByTestId('Biodiversity-button')).toBeVisible();
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const nextConfig = {
output: 'standalone',
poweredByHeader: false,
env: {
API_URL: process.env.API_URL || 'https://g3w.earthmonitor.org/dev',
API_URL: process.env.API_URL || 'https://g3w.earthmonitor.org',
},
images: {
unoptimized: true,
Expand Down
2 changes: 1 addition & 1 deletion public/images/svgs/arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions public/images/svgs/geometries.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions public/svgs/active-layer-position.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions public/svgs/regions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions src/components/map/controls/compare-regions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,30 @@ const CompareRegionsStatistics = ({
>
<path
d="M20.5852 14.7002H16.4992C16.0218 14.7002 15.564 14.8898 15.2264 15.2274C14.8889 15.565 14.6992 16.0228 14.6992 16.5002V20.5862"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
className="stroke-current text-secondary-500 group-hover:text-[#09131D]"
/>
<path
d="M7.5 4.20581V5.69981C7.5 6.4159 7.78446 7.10265 8.29081 7.609C8.79716 8.11535 9.48392 8.39981 10.2 8.39981C10.6774 8.39981 11.1352 8.58945 11.4728 8.92702C11.8104 9.26458 12 9.72242 12 10.1998C12 11.1898 12.81 11.9998 13.8 11.9998C14.2774 11.9998 14.7352 11.8102 15.0728 11.4726C15.4104 11.135 15.6 10.6772 15.6 10.1998C15.6 9.20981 16.41 8.39981 17.4 8.39981H20.253"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
className="stroke-current text-secondary-500 group-hover:text-[#09131D]"
/>
<path
d="M11.0999 20.9551V17.4001C11.0999 16.9227 10.9103 16.4649 10.5727 16.1273C10.2351 15.7897 9.77731 15.6001 9.29992 15.6001C8.82253 15.6001 8.3647 15.4105 8.02713 15.0729C7.68956 14.7353 7.49992 14.2775 7.49992 13.8001V12.9001C7.49992 12.4227 7.31028 11.9649 6.97271 11.6273C6.63515 11.2897 6.17731 11.1001 5.69992 11.1001H3.04492"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
className="stroke-current text-secondary-500 group-hover:text-[#09131D]"
/>
<path
d="M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
className="stroke-current text-secondary-500 group-hover:text-[#09131D]"
/>
</svg>
Expand Down
Loading

0 comments on commit 99c6a3c

Please sign in to comment.