Skip to content

Commit

Permalink
continuing testing development. Adding/removing packages as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
siddheshraze committed Feb 4, 2025
1 parent 2c6c672 commit c23d565
Show file tree
Hide file tree
Showing 18 changed files with 3,134 additions and 138 deletions.
17 changes: 17 additions & 0 deletions frontend/app/(hub)/measurementshub/recentchanges/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use client';

import React from 'react';
import { Box, Button, Typography } from '@mui/joy';

const ErrorPage = (props: { error: Error; reset: () => void }) => {
const { error, reset } = props;
return (
<Box sx={{ p: 3, textAlign: 'center' }}>
<Typography level="h1">Something went wrong - Recent Changes Page</Typography>
<Typography level="body-lg">{error?.message ?? 'No error message received'}</Typography>
<Button onClick={reset}>Retry Now</Button>
</Box>
);
};

export default ErrorPage;

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions frontend/cypress/components/app/page/homepage.cy.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ErrorPage from '@/app/error';

describe('App --> Page --> <ErrorPage />', () => {
describe('Error Pages', () => {
it('renders', () => {
cy.mount(<ErrorPage error={new Error('Test Error')} reset={function (): void {}} />);
});
Expand Down
32 changes: 32 additions & 0 deletions frontend/cypress/components/pages.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import HomePage from '@/app/page';
import LoginFailedPage from '@/app/loginfailed/page';
import * as nextAuthReact from 'next-auth/react';
import * as nextNavigation from 'next/navigation';

describe('Mounting Home Page', () => {
it('renders', () => {
cy.mount(<HomePage />);
});
});

describe('Login failure page test', () => {
beforeEach(() => {
cy.stub(window.sessionStorage, 'clear').as('sessionStorageClear');
cy.stub(window.localStorage, 'clear').as('localStorageClear');

cy.stub(nextAuthReact, 'signOut').resolves();

cy.stub(nextNavigation, 'useSearchParams').returns(() => new URLSearchParams('?reason=Invalid Credentials'));
});

it('renders the login failure message', () => {
cy.mount(<LoginFailedPage />);
cy.contains('Oops! Login Failed').should('be.visible');
});

it('displays a default failure reason if none is provided', () => {
cy.mount(<LoginFailedPage />);
cy.contains('Failure caused due to Login failure triggered without reason. Please speak to an administrator').should('be.visible');
});
});
10 changes: 10 additions & 0 deletions frontend/cypress/fixtures/changelog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"id": 1,
"operation": "UPDATE",
"tableName": "measurements",
"changeTimestamp": "2024-01-01T12:00:00Z",
"oldRowState": { "columnA": "oldValue" },
"newRowState": { "columnA": "newValue" }
}
]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions frontend/cypress/support/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// cypress/support/mocks.ts

import * as nextAuthReact from 'next-auth/react';
import { PlotRDS, SitesRDS } from '@/config/sqlrdsdefinitions/zones';
import { OrgCensusRDS } from '@/config/sqlrdsdefinitions/timekeeping';
import * as userContext from '@/app/contexts/userselectionprovider';
import * as lockAnimationContext from '@/app/contexts/lockanimationcontext';

const testSite1: SitesRDS = {
siteName: 'Test Site 1',
schemaName: 'site1'
};

const testSite2: SitesRDS = {
siteName: 'Test Site 2',
schemaName: 'site2'
};

const testPlot: PlotRDS = {
plotID: 1,
plotName: 'Test Plot'
};

const testCensus: OrgCensusRDS = {
censusIDs: [],
dateRanges: [],
description: '',
plotID: 1,
plotCensusNumber: 1
};

export function mockUseSession(overrides = {}) {
cy.stub(nextAuthReact, 'useSession').returns({
data: {
user: {
name: 'J Doe',
email: '[email protected]',
userStatus: 'db admin',
sites: [testSite1, testSite2],
...overrides
}
}
});
}

export function mockUserContexts(site = testSite1, plot = testPlot, census = testCensus) {
cy.stub(userContext, 'useSiteContext').returns(site);
cy.stub(userContext, 'usePlotContext').returns(plot);
cy.stub(userContext, 'useOrgCensusContext').returns(census);
}

export function mockLockAnimationContext() {
cy.stub(lockAnimationContext, 'useLockAnimation').returns({
triggerPulse: cy.stub().as('triggerPulse'),
isPulsing: false
});
}

export function mockApiResponses() {
cy.intercept('GET', '/api/changelog/**', { fixture: 'changelog.json' }).as('getChangelog');
}
Loading

0 comments on commit c23d565

Please sign in to comment.