Skip to content

Commit

Permalink
Merge pull request #229 from amosproj/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
PianoRollRepresentation authored Jun 1, 2021
2 parents adb7388 + e199bbe commit 4808db1
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 41 deletions.
Binary file added backend/docker/mount/dumps/testing-dump-big.dump
Binary file not shown.
2 changes: 1 addition & 1 deletion backend/src/config/neo4j/KmapNeo4jModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createNeo4jDriver } from './createNeo4jDriver';
*/
export class KmapNeo4jModule {
/**
* Overrides the driver factory from the {@link Neo4jModule} so additional
* Overrides the driver factory from the {@link Neo4jModule} so
* additional {@link Neo4jDriverOptions} are possible.
* @private
*/
Expand Down
47 changes: 28 additions & 19 deletions backend/tests/e2e/app.service.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Test, TestingModule } from '@nestjs/testing';
import { Neo4jService } from 'nest-neo4j/dist';
import { AppModule } from '../../src/app.module';
import { ConfigModule } from '@nestjs/config';
import { AppService } from '../../src/app.service';
import { Node, Edge } from '../../src/shared/entities';
import {
Expand All @@ -9,7 +9,7 @@ import {
queryAllDummies,
queryAllNoLimitDummies,
} from '../fixtures/testingDumpData';
import { CountQueryResult, QueryResult } from '../../src/shared/queries';
import { QueryResult } from '../../src/shared/queries';
import { KmapNeo4jModule } from '../../src/config/neo4j/KmapNeo4jModule';

describe('AppService (e2e)', () => {
Expand All @@ -19,7 +19,14 @@ describe('AppService (e2e)', () => {
beforeAll(async () => {
// Global setup
const mockAppModule: TestingModule = await Test.createTestingModule({
imports: [AppModule, KmapNeo4jModule],
imports: [
ConfigModule.forRoot({
envFilePath: '.env.test',
}),
KmapNeo4jModule.fromEnv({
disableLosslessIntegers: true,
}),
],
providers: [AppService],
}).compile();

Expand Down Expand Up @@ -57,6 +64,24 @@ describe('AppService (e2e)', () => {
expect(actualResult).toEqual(expectedResult);
});

describe('Method queryAll for no limit', () => {
it('should return expected node length for no limit', async () => {
// Act
const actualResult: QueryResult = await appService.queryAll();

// Assert
expect(actualResult.nodes.length).toEqual(4);
});

it('should return expected edge length for no limit', async () => {
// Act
const actualResult: QueryResult = await appService.queryAll();

// Assert
expect(actualResult.edges.length).toEqual(3);
});
});

it('should return no nodes when called with nodes limited to 0', async () => {
// Arrange
const result = await appService.queryAll({ limits: { nodes: 0 } });
Expand Down Expand Up @@ -103,20 +128,4 @@ describe('AppService (e2e)', () => {
expect(actualEdges).toEqual(expectedEdges);
});
});

describe('Method getNumberOfEntities', () => {
it('should return the correct number of nodes and edges', async () => {
// Arrange
const expected: CountQueryResult = {
nodes: 4,
edges: 3,
};

// Act
const actual = await appService.getNumberOfEntities();

// Assert
expect(actual).toEqual(expected);
});
});
});
13 changes: 10 additions & 3 deletions backend/tests/e2e/filter/filter.service.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Test, TestingModule } from '@nestjs/testing';
import { Neo4jService } from 'nest-neo4j/dist';
import { ConfigModule } from '@nestjs/config';
import { FilterService } from '../../../src/filter/filter.service';
import { KmapNeo4jModule } from '../../../src/config/neo4j/KmapNeo4jModule';
import { AppModule } from '../../../src/app.module';
import {
getEdgeTypeFilterModelResult,
getNodeTypeFilterModelResult,
Expand All @@ -23,8 +23,15 @@ describe('FilterService', () => {
// Global Setup
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [AppModule, KmapNeo4jModule],
providers: [],
imports: [
ConfigModule.forRoot({
envFilePath: '.env.test',
}),
KmapNeo4jModule.fromEnv({
disableLosslessIntegers: true,
}),
],
providers: [FilterService],
}).compile();

service = module.get<FilterService>(FilterService);
Expand Down
13 changes: 10 additions & 3 deletions backend/tests/e2e/schema/schema.service.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Test, TestingModule } from '@nestjs/testing';
import { Neo4jService } from 'nest-neo4j/dist';
import { ConfigModule } from '@nestjs/config';
import { SchemaService } from '../../../src/schema/schema.service';
import { KmapNeo4jModule } from '../../../src/config/neo4j/KmapNeo4jModule';
import { AppModule } from '../../../src/app.module';
import { edgeInfo, nodeInfo } from '../../fixtures/nodeInfo/GraphInfoDb';

/*
Expand All @@ -16,8 +16,15 @@ describe('SchemaService', () => {
// Global Setup
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [AppModule, KmapNeo4jModule],
providers: [],
imports: [
ConfigModule.forRoot({
envFilePath: '.env.test',
}),
KmapNeo4jModule.fromEnv({
disableLosslessIntegers: true,
}),
],
providers: [SchemaService],
}).compile();

service = module.get<SchemaService>(SchemaService);
Expand Down
11 changes: 9 additions & 2 deletions backend/tests/e2e/search/search.service.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Test, TestingModule } from '@nestjs/testing';
import { Neo4jService } from 'nest-neo4j/dist';
import { ConfigModule } from '@nestjs/config';
import { SearchService } from '../../../src/search/search.service';
import { KmapNeo4jModule } from '../../../src/config/neo4j/KmapNeo4jModule';
import { AppModule } from '../../../src/app.module';

describe('SearchService', () => {
let service: SearchService;
Expand All @@ -11,7 +11,14 @@ describe('SearchService', () => {
// Global Setup
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [AppModule, KmapNeo4jModule],
imports: [
ConfigModule.forRoot({
envFilePath: '.env.test',
}),
KmapNeo4jModule.fromEnv({
disableLosslessIntegers: true,
}),
],
providers: [SearchService],
}).compile();

Expand Down
9 changes: 5 additions & 4 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
## Testing
1. start react with `yarn run start:forTests` in package.json.
2. open cypress with `yarn run cy:open:e2e` or `yarn run cy:run:e2e`.
3. if `yarn run cy:open:e2e` was used, start all tests manually.
4. print testing-coverage with `yarn run coverage:print`.

### `yarn run build`

Expand Down
3 changes: 2 additions & 1 deletion frontend/cypress/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"cypress/no-force": "warn",
"cypress/no-async-tests": "error",
"import/prefer-default-export": 0,
"class-methods-use-this": "off"
"class-methods-use-this": "off",
"import/extensions": "off"
},
"env": {
"cypress/globals": true
Expand Down
26 changes: 20 additions & 6 deletions frontend/cypress/integration/visualization/filter.e2e.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import '../../support/index.js';

context('Filter', () => {
// Global setup
beforeEach(() => {
Expand Down Expand Up @@ -31,7 +33,7 @@ context('Filter', () => {
cy.contains('name');
});

it('Shows expected property-values', () => {
it('shows expected property-values', () => {
// Act
cy.get('.Filter').click();
cy.get('.FilterButton:first').click();
Expand All @@ -44,17 +46,29 @@ context('Filter', () => {
cy.contains('Lana Wachowski');
});

it('constructs correct filterQuery', () => {
it('selects no property values', () => {
// Act
cy.get('.Filter').click();
cy.get('.FilterButton:first').click();
cy.get('.FilterDialog');

// eslint-disable-next-line cypress/no-force
cy.get('.ApplyFilter').focus().click({ force: true });

cy.get('.AddButton:first').click();
});

it('applies filter', () => {
// Act
cy.get('.Filter').click();
cy.get('.FilterButton:first').click();
cy.get('.FilterDialog');
cy.get('.FilterSelect:last').click();

// Assert
cy.contains('Keanu Reeves').click();
cy.contains('Carrie-Anne Moss').click();
cy.contains('Lana Wachowski').click();

// eslint-disable-next-line cypress/no-force
cy.get('.ApplyFilter').focus().click({ force: true });
});
Expand All @@ -79,7 +93,7 @@ context('Filter', () => {
});

context('Edges', () => {
it('Shows expected property-names', () => {
it('shows expected property-names', () => {
// Act
cy.get('.Filter').click();
cy.contains('Edge Types').click();
Expand All @@ -102,7 +116,7 @@ context('Filter', () => {
cy.contains('Error: No string').click();
});

it('constructs correct filterQuery', () => {
it('applies filter', () => {
// Act
cy.get('.Filter').click();
cy.get('.EdgeTypes').click();
Expand All @@ -116,7 +130,7 @@ context('Filter', () => {
cy.get('.ApplyFilter').focus().click({ force: true });
});

it('constructs correct filterQuery', () => {
it('adds edges to view', () => {
// Act
cy.get('.Filter').click();
cy.get('.EdgeTypes').click();
Expand Down
3 changes: 2 additions & 1 deletion frontend/cypress/integration/visualization/tabs.e2e.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { apiBaseUrl } from '../../support/constants';

context('Visualization Tabs', () => {
const apiBaseUrl = 'http://localhost:8080/api';
// Global setup
beforeEach(() => {
cy.visit('http://localhost:3000/visualization');
Expand Down
9 changes: 9 additions & 0 deletions frontend/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

import { apiBaseUrl } from './constants';

Cypress.Commands.add('switchBackendPort', (port) => {
cy.intercept({ url: `${apiBaseUrl}/**`, middleware: true }, (req) => {
req.url = `http://localhost:${port}${req.url.slice(21)}`;
req.continue();
});
});
2 changes: 2 additions & 0 deletions frontend/cypress/support/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const apiBaseUrl =
Cypress.env('apiBaseUrl') ?? 'http:localhost:8080/api';
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ const EntityFilterDialog = (props: {
}
}

/* istanbul ignore else */
if (filterConditions.length > 0) {
setFilterQuery(MatchAllCondition(...filterConditions));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function fetchDataFromService<TArgs extends unknown[], TData>(
}
})
.catch((err) => {
/* istanbul ignore if */
if (mounted) {
setError(err);
setIsLoading(false);
Expand Down

0 comments on commit 4808db1

Please sign in to comment.