Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[frontend] Add tests to Environment.exportData (#1489) #2210

Merged
merged 9 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions openbas-front/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'eslint-import-resolver-oxc';

import js from '@eslint/js';
import stylistic from '@stylistic/eslint-plugin';
import vitest from '@vitest/eslint-plugin';
import i18next from 'eslint-plugin-i18next';
import importPlugin from 'eslint-plugin-import';
import playwright from 'eslint-plugin-playwright';
Expand Down Expand Up @@ -178,6 +179,27 @@ export default [
},
},

// unit tests config
{
files: ['src/__tests__/**/*'],
// rules recommended by vitest
plugins: {
vitest,
},
rules: {
...vitest.configs.recommended.rules,
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
'**/*.ts',
'**/*.tsx',
],
},
],
},
},

// tests e2e config
{
files: ['tests_e2e/**/*'],
Expand All @@ -190,6 +212,7 @@ export default [
{
devDependencies: [
'**/*.ts',
'**/*.tsx',
],
},
],
Expand Down
3 changes: 3 additions & 0 deletions openbas-front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
},
"devDependencies": {
"@eslint/js": "9.15.0",
"@faker-js/faker": "9.3.0",
"@playwright/test": "1.49.1",
"@stylistic/eslint-plugin": "2.13.0",
"@testing-library/dom": "10.4.0",
Expand All @@ -95,7 +96,9 @@
"@types/seamless-immutable": "7.1.19",
"@types/uuid": "10.0.0",
"@typescript-eslint/parser": "8.18.1",
"@typescript-eslint/utils": "8.20.0",
"@vitejs/plugin-react": "4.3.4",
"@vitest/eslint-plugin": "1.1.25",
"chokidar": "4.0.3",
"cross-env": "7.0.3",
"esbuild": "0.24.0",
Expand Down
59 changes: 59 additions & 0 deletions openbas-front/src/__tests__/fixtures/api-types.fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { faker } from '@faker-js/faker';

import { Exercise, Organization, Scenario, Tag } from '../../utils/api-types';

export function createTagMap(numberTags: number): { [key: string]: Tag } {
const tagMap: { [key: string]: Tag } = {};
for (let i = 0; i < numberTags; i++) {
const id = faker.string.uuid();
tagMap[id] = {
tag_id: faker.string.uuid(), tag_name: faker.lorem.sentence(),
};
}
return tagMap;
}

export function createOrganisationsMap(numberTags: number): { [key: string]: Organization } {
const orgMap: { [key: string]: Organization } = {};
for (let i = 0; i < numberTags; i++) {
const id = faker.string.uuid();
orgMap[id] = {
organization_created_at: faker.date.recent().toISOString(),
organization_name: faker.hacker.noun(),
organization_updated_at: faker.date.soon().toISOString(),
organization_id: id,
};
}
return orgMap;
}

export function createExercisesMap(numberTags: number): { [key: string]: Exercise } {
const exerciseMap: { [key: string]: Exercise } = {};
for (let i = 0; i < numberTags; i++) {
const id = faker.string.uuid();
exerciseMap[id] = {
exercise_created_at: faker.date.recent().toISOString(),
exercise_id: id,
exercise_mail_from: faker.internet.email(),
exercise_name: faker.hacker.phrase(),
exercise_status: 'SCHEDULED',
exercise_updated_at: faker.date.soon().toISOString(),
};
}
return exerciseMap;
}

export function createScenarioMap(numberTags: number): { [key: string]: Scenario } {
const scenarioMap: { [key: string]: Scenario } = {};
for (let i = 0; i < numberTags; i++) {
const id = faker.string.uuid();
scenarioMap[id] = {
scenario_created_at: faker.date.recent().toISOString(),
scenario_id: id,
scenario_mail_from: faker.internet.email(),
scenario_name: faker.hacker.phrase(),
scenario_updated_at: faker.date.soon().toISOString(),
};
}
return scenarioMap;
}
Loading
Loading