-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some unit tests for Determination class
- Loading branch information
Showing
4 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Determination } from './determination.mjs' | ||
|
||
describe('Determination', () => { | ||
let determination = null | ||
|
||
beforeEach(() => { | ||
document.body.classList.add("govuk-frontend-supported") | ||
document.body.append(` | ||
<table id="determinations" data-module="govuk-determination" data-apply-vat="true" data-vat-url="/vat.json" data-submitted-date="2023-07-18" data-scheme="agfs"> | ||
</table> | ||
`) | ||
|
||
const elements = window.document.querySelectorAll('[data-module="govuk-determination"]') | ||
determination = new Determination(elements[0]) | ||
determination.init() | ||
}) | ||
|
||
describe('parsedValue', () => { | ||
it('should parse a positive integer', () => { | ||
const field = document.createElement('input') | ||
field.value = '100' | ||
|
||
expect(determination.parsedValue(field)).toEqual(100.0) | ||
}) | ||
|
||
it('should parse a positive float', () => { | ||
const field = document.createElement('input') | ||
field.value = '99.99' | ||
|
||
expect(determination.parsedValue(field)).toEqual(99.99) | ||
}) | ||
|
||
it('should return zero for a negative integer', () => { | ||
const field = document.createElement('input') | ||
field.value = '-100' | ||
|
||
expect(determination.parsedValue(field)).toEqual(0.0) | ||
}) | ||
|
||
it('should return zero for a negative float', () => { | ||
const field = document.createElement('input') | ||
field.value = '-99.99' | ||
|
||
expect(determination.parsedValue(field)).toEqual(0.0) | ||
}) | ||
|
||
it('should return zero for a value that cannot be parsed', () => { | ||
const field = document.createElement('input') | ||
field.value = 'test' | ||
|
||
expect(determination.parsedValue(field)).toEqual(0.0) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters