diff --git a/.circleci/config.yml b/.circleci/config.yml index 6229170..a3a8ba2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,30 +2,41 @@ # See: https://circleci.com/docs/configuration-reference version: 2.1 -# Define a job to be invoked later in a workflow. -# See: https://circleci.com/docs/jobs-steps/#jobs-overview & https://circleci.com/docs/configuration-reference/#jobs +orbs: + node: circleci/node@6 + jobs: - say-hello: - # Specify the execution environment. You can specify an image from Docker Hub or use one of our convenience images from CircleCI's Developer Hub. - # See: https://circleci.com/docs/executor-intro/ & https://circleci.com/docs/configuration-reference/#executor-job + validate-config: docker: - # Specify the version you desire here - # See: https://circleci.com/developer/images/image/cimg/base - - image: cimg/base:current + - image: cimg/base:stable + steps: + - checkout + - run: + name: Validate CircleCI configuration syntax + command: | + curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/main/install.sh | bash -s -- --no-sudo --install-dir /tmp/circleci-cli + /tmp/circleci-cli/circleci config validate .circleci/config.yml - # Add steps to the job - # See: https://circleci.com/docs/jobs-steps/#steps-overview & https://circleci.com/docs/configuration-reference/#steps + build: + docker: + - image: cimg/node:22.19 steps: - # Checkout the code as the first step. - checkout - run: - name: "Say hello" - command: "echo Hello, World!" + name: Install dependencies + command: npm ci --legacy-peer-deps + working_directory: aq-dashboard + - run: + name: Build + command: npm run build + working_directory: aq-dashboard + - run: + name: Test + command: npm test -- --watchAll=false --passWithNoTests + working_directory: aq-dashboard -# Orchestrate jobs using workflows -# See: https://circleci.com/docs/workflows/ & https://circleci.com/docs/configuration-reference/#workflows workflows: - say-hello-workflow: # This is the name of the workflow, feel free to change it to better match your workflow. - # Inside the workflow, you define the jobs you want to run. + build-workflow: jobs: - - say-hello \ No newline at end of file + - validate-config + - build diff --git a/aq-dashboard/src/App.test.tsx b/aq-dashboard/src/App.test.tsx new file mode 100644 index 0000000..582a875 --- /dev/null +++ b/aq-dashboard/src/App.test.tsx @@ -0,0 +1,41 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import App from './App'; + +// Stub geolocation so Dashboard does not throw in jsdom +beforeEach(() => { + Object.defineProperty(global.navigator, 'geolocation', { + configurable: true, + value: { + getCurrentPosition: jest.fn(), + }, + }); +}); + +// Stub leaflet, which relies on a browser DOM unavailable in jsdom +jest.mock('react-leaflet', () => ({ + MapContainer: ({ children }: { children: React.ReactNode }) => ( +
{children}
+ ), + TileLayer: () =>
, +})); + +jest.mock('axios'); + +describe('App', () => { + it('renders without crashing', () => { + render(); + }); + + it('shows the waiting-for-location prompt while geolocation is pending', () => { + render(); + expect(screen.getByText(/waiting for location/i)).toBeInTheDocument(); + }); + + it('shows a button to enter location manually', () => { + render(); + expect( + screen.getByRole('button', { name: /enter location manually/i }) + ).toBeInTheDocument(); + }); +}); diff --git a/aq-dashboard/src/index.tsx b/aq-dashboard/src/index.tsx index 0ee8b59..8724060 100644 --- a/aq-dashboard/src/index.tsx +++ b/aq-dashboard/src/index.tsx @@ -1,6 +1,5 @@ import { createRoot } from 'react-dom/client'; import React from 'react'; -import ReactDOM from 'react-dom/client'; import './index.css'; import App from './App'; import reportWebVitals from './reportWebVitals';