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

BL-11501 fix mark repairs javascript for proper counting failures dep… #299

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dvsa/front-end",
"description": "DVSA front-end assets used within all applications",
"version": "1.3.29",
"version": "1.5.2",
"homepage": "https://github.com/dvsa/front-end",
"license": "MIT",
"authors": [
Expand Down
6 changes: 3 additions & 3 deletions dist/assets/javascripts/development.bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/assets/javascripts/dvsa-manuals.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions dist/assets/javascripts/dvsa-mts-legacy.bundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/assets/javascripts/dvsa-mts.bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/assets/javascripts/dvsa.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/assets/javascripts/vendor.bundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/assets/stylesheets/development.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/assets/stylesheets/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dvsa-front-end",
"version": "1.3.29",
"version": "1.5.2",
"description": "Front-end assets built on Node/Express to be used for public-facing DVSA sites and applications. Based on GOV UK prototype kit, but highly modified. It uses SCSS, Nunjucks, ES6, Webpack 3, Babel, Mocha, Chai, Puppeteer, and NPM libraries.",
"main": "index.js",
"scripts": {
Expand Down
24 changes: 16 additions & 8 deletions src/assets/js/dvsa-mts/modules/mark-repairs/mark-repairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class MarkRepairs {
rfrForm: '.js-rfrForm',
rfrItem: '.js-rfrItem',
itemStatus: '.js-itemStatus',
emissionsTestFailures: 'js-emissionsTestFailures',
defectFailures: 'js-defectFailures',
};

this.elements = {
Expand Down Expand Up @@ -139,7 +141,7 @@ export class MarkRepairs {
if (data && data.success) {
toggleClass(rfrItem, this.classnames.hasStatus, false);
toggleClass(rfrItem, this.classnames.hasSuccess, data.action === this.responseActions.repair);
this.updateCount(data.defectType, data.action);
this.updateCount(data.defectType, data.action, data.failureType);
this.updateBrakeTest(data.brakeTestOutcome, data.brakesTested, data.brakeTestResults, data.disableSubmitButton);
element.disabled = false;
} else {
Expand All @@ -161,20 +163,20 @@ export class MarkRepairs {
* @since 1.1.0
* @author Tameem Safi <t.safi@kainos.com>
*/
updateCount = (defectType, action) => {
updateCount = (defectType, action, failureType) => {
switch (defectType) {
case 'advisory': {
this.updateCountForAllElements(this.elements.numberOfAdvisories, action);
this.updateCountForAllElements(this.elements.numberOfAdvisories, action, failureType);
break;
}

case 'minor': {
this.updateCountForAllElements(this.elements.numberOfMinors, action);
this.updateCountForAllElements(this.elements.numberOfMinors, action, failureType);
break;
}

case 'failure': {
this.updateCountForAllElements(this.elements.numberOfFailures, action);
this.updateCountForAllElements(this.elements.numberOfFailures, action, failureType);
break;
}

Expand All @@ -185,18 +187,24 @@ export class MarkRepairs {
};

/**
* Updates the count of failures, advisories and minors for all elements
* Updates the count of failures, advisories and minors for all elements of the same type
*
* @param {HTMLElement} element Elements which to parse number from and change
* @param {String} action Action can be repair or not
*
* @since 1.1.0
* @author Tameem Safi <t.safi@kainos.com>
*/
updateCountForAllElements = (elements, action) => {
updateCountForAllElements = (elements, action, failureType) => {
if (!elements || !Array.isArray(elements)) return;
elements.forEach(element => {
this.updateCountForElement(element, action);
if (failureType === 'emissionsTest' && element.classList.contains(this.selectors.emissionsTestFailures)) {
this.updateCountForElement(element, action);
} else if (failureType === 'defect' && element.classList.contains(this.selectors.defectFailures)) {
this.updateCountForElement(element, action);
} else if (failureType === null || failureType === undefined) {
this.updateCountForElement(element, action);
}
});
};

Expand Down