Skip to content

Commit

Permalink
#133 add unit test for preference entries domain function
Browse files Browse the repository at this point in the history
  • Loading branch information
JAGFx committed Jul 29, 2022
1 parent 70807c6 commit 9920e9a
Show file tree
Hide file tree
Showing 12 changed files with 2,400 additions and 149 deletions.
12 changes: 12 additions & 0 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
2 changes: 1 addition & 1 deletion .run/Unit tests.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Unit tests" type="JavaScriptTestRunnerJest">
<node-interpreter value="project" />
<node-options value="--experimental-vm-modules" />
<node-options value="" />
<jest-package value="$PROJECT_DIR$/node_modules/jest" />
<working-dir value="$PROJECT_DIR$" />
<envs />
Expand Down
4 changes: 3 additions & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"@/(.*)$": "<rootDir>/src/$1"
},
"transform": {
"^.+\\.js$": "babel-jest",
"\\.yaml$": "yaml-jest"
},
"testEnvironment": "node"
"testEnvironment": "node",
"clearMocks": true
}
2,446 changes: 2,341 additions & 105 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "ets2-dashboard-skin",
"version": "1.7.2",
"private": false,
"type": "module",
"description": "Euro Truck Simulator 2 dashboard",
"author": {
"name": "Emmanuel SMITH",
Expand All @@ -15,8 +14,8 @@
"lint:prettier": "npx prettier {src/application,src/domain,lib,test,servers}/**/*.{js,vue} --write",
"lint:stylelint": "npx stylelint --fix 'src/application/**/*.scss'",
"test": "npm run test:unit",
"test:unit": "NODE_OPTIONS=--experimental-vm-modules npx jest",
"test:coverage": "NODE_OPTIONS=--experimental-vm-modules npx jest --coverage",
"test:unit": "npx jest",
"test:coverage": "npx jest --coverage",
"test:coverage:preview": "npm run test:coverage && npx http-server coverage/lcov-report/ -p 8002",
"ci": "npm run lint && npm run test",
"build": "set NODE_ENV=production && npx gulp build",
Expand Down Expand Up @@ -68,12 +67,15 @@
"yaml-loader": "0.6.0"
},
"devDependencies": {
"@babel/core": "^7.18.9",
"@babel/preset-env": "^7.18.9",
"@jest/globals": "^28.1.3",
"@modyfi/vite-plugin-yaml": "^1.0.2",
"@vitejs/plugin-vue": "^2.3.3",
"@vue/cli-service": "^5.0.8",
"@vue/compiler-sfc": "^3.2.37",
"@vue/vue3-jest": "^28.0.1",
"babel-jest": "^28.1.3",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
Expand Down
4 changes: 2 additions & 2 deletions src/application/components/menu/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
</template>

<script setup>
import AboutTab from '@/application/components/menu/AboutTab/AboutTab.vue';
import AboutTab from '@/application/components/menu/AboutTab/AboutTab.vue';
import UserPreferenceTab from '@/application/components/menu/UserPreferencesTab/UserPreferenceTab.vue';
import SkinTab from '@/application/components/menu/SkinTab.vue';
import SkinTab from '@/application/components/menu/SkinTab.vue';
import Navlink from '@/application/ui/Navlink/Navlink.vue';
import { shallowRef } from 'vue';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
</template>

<script setup>
import UserPreferenceListItemSelect
from "@/application/components/menu/UserPreferencesTab/UserPreferenceListItemSelect.vue";
import UserPreferenceListItemSwitch
from "@/application/components/menu/UserPreferencesTab/UserPreferenceListItemSwitch.vue";
import UserPreferenceListItemSelect from '@/application/components/menu/UserPreferencesTab/UserPreferenceListItemSelect.vue';
import UserPreferenceListItemSwitch from '@/application/components/menu/UserPreferencesTab/UserPreferenceListItemSwitch.vue';
</script>

<style lang="scss" scoped></style>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</template>

<script setup>
import Tag from '@/application/ui/Tag/Tag.vue';
import Tag from '@/application/ui/Tag/Tag.vue';
import { findPreferenceEntryById } from '@/domain/user-preferences/preference-entry.util.js';
const props = defineProps({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</template>

<script setup>
import UserPreferenceListItem from "@/application/components/menu/UserPreferencesTab/UserPreferenceListItem.vue";
import UserPreferenceListItem from '@/application/components/menu/UserPreferencesTab/UserPreferenceListItem.vue';
defineProps({
configurationId: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</template>

<script setup>
import UserPreferenceListItem from "@/application/components/menu/UserPreferencesTab/UserPreferenceListItem.vue";
import Switch from '@/application/ui/Switch/Switch.vue';
import UserPreferenceListItem from '@/application/components/menu/UserPreferencesTab/UserPreferenceListItem.vue';
import Switch from '@/application/ui/Switch/Switch.vue';
defineProps({
configurationId: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</template>

<script setup>
import UserPreferenceList from "@/application/components/menu/UserPreferencesTab/UserPreferenceList.vue";
import UserPreferenceSearchBar from "@/application/components/menu/UserPreferencesTab/UserPreferenceSearchBar.vue";
import UserPreferenceList from '@/application/components/menu/UserPreferencesTab/UserPreferenceList.vue';
import UserPreferenceSearchBar from '@/application/components/menu/UserPreferencesTab/UserPreferenceSearchBar.vue';
</script>

<style lang="scss"></style>
55 changes: 28 additions & 27 deletions src/domain/user-preferences/preference-entry.util.spec.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import { jest } from '@jest/globals';

const existingConfigurationId = 'an_existing_configuration_id';
const existingConfiguration = {
id: existingConfigurationId,
target: 'application',
label: 'Configuration 1',
description: 'Description 1',
values: [
{
label: 'Value 1',
value: 'value1'
}
]
};
jest.mock('@/domain/configuration/configuration.library.json', () => [
existingConfiguration
]);
const existingConfiguration = [
{
id: 'an_existing_configuration_id',
target: 'application',
label: 'Configuration 1',
description: 'Description 1',
values: [
{
label: 'Value 1',
value: 'value1'
}
]
}
];
jest.mock('@/domain/user-preferences/map.json', () => existingConfiguration);

import { retrieveConfigurationSettings } from '@/domain/user-preferences/configurationLibrary.util.js';
import { findPreferenceEntryById } from '@/domain/user-preferences/preference-entry.util';

beforeEach(() => {
jest.resetModules();
});
describe('Preference entries', () => {
it('An existing preference entry must return data successfully', () => {
const configuration = findPreferenceEntryById(existingConfigurationId);

describe('Configuration', () => {
it('An existing configuration ID must return the configuration data successfully', () => {
const configuration = retrieveConfigurationSettings(
existingConfigurationId
);
expect(configuration).toMatchObject(existingConfiguration.at(0));
});

expect(configuration).toMatchObject(existingConfiguration);
it('An unknown preference entry must thrown an exception', () => {
const unknownPreferenceEntryId = 'an_unknown_preference_entry_id';
expect(() =>
findPreferenceEntryById(unknownPreferenceEntryId)
).toThrowError(
`Unable to find ${unknownPreferenceEntryId} on preference entries list`
);
});
});

0 comments on commit 9920e9a

Please sign in to comment.