-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into chore/test-apply-to-all-use-case
- Loading branch information
Showing
23 changed files
with
765 additions
and
16 deletions.
There are no files selected for viewing
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,38 @@ | ||
name: Application testing | ||
on: | ||
push: | ||
workflow_dispatch: | ||
jobs: | ||
unit-tests: | ||
name: Unit tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: "16.14.0" | ||
|
||
- name: Install yarn | ||
run: npm install -g yarn | ||
|
||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
|
||
- name: Cache yarn dependencies | ||
uses: actions/cache@v2 | ||
id: yarn-cache | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile --silent | ||
|
||
- name: Run jest tests | ||
run: yarn test |
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
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
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
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,19 @@ | ||
import { getPath } from "../OrgUnit"; | ||
import { getMainUserPaths } from "../Config"; | ||
import { config } from "./configFixtures"; | ||
import { orgUnits } from "./orgUnitFixtures"; | ||
|
||
describe("Config", () => { | ||
describe("getMainUserPaths", () => { | ||
it("should return the compacted result of getPath", () => { | ||
const result = getMainUserPaths(config); | ||
expect(result).toEqual([getPath(orgUnits)]); | ||
}); | ||
|
||
it("should handle empty paths correctly", () => { | ||
const userWithoutOrgUnits = { ...config.currentUser, orgUnits: [] }; | ||
const result = getMainUserPaths({ ...config, currentUser: userWithoutOrgUnits }); | ||
expect(result).toEqual([]); | ||
}); | ||
}); | ||
}); |
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,37 @@ | ||
import { getDataElementWithCode, DataElement, DataElementBoolean, DataElementText } from "../DataElement"; | ||
import { dataElementText as dataElementBase } from "./dataFixtures"; | ||
|
||
describe("DataElement", () => { | ||
const dataElementBoolean: DataElementBoolean = { | ||
...dataElementBase, | ||
id: "1", | ||
code: "DE_BOOLEAN", | ||
name: "Boolean Data Element", | ||
type: "BOOLEAN", | ||
isTrueOnly: false, | ||
}; | ||
|
||
const dataElementText: DataElementText = { | ||
...dataElementBase, | ||
id: "2", | ||
code: "DE_TEXT", | ||
name: "Text Data Element", | ||
type: "TEXT", | ||
}; | ||
|
||
const dataElements: DataElement[] = [dataElementBoolean, dataElementText]; | ||
|
||
describe("getDataElementWithCode", () => { | ||
it("should return the correct DataElement when a matching code is found", () => { | ||
const codeToFind = "DE_BOOLEAN"; | ||
const result = getDataElementWithCode(dataElements, codeToFind); | ||
expect(result).toEqual(dataElementBoolean); | ||
}); | ||
|
||
it("should return undefined when no matching code is found", () => { | ||
const codeToFind = "NON_EXISTENT_CODE"; | ||
const result = getDataElementWithCode(dataElements, codeToFind); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
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,88 @@ | ||
import { Id } from "../Base"; | ||
import { DataFormM, DataForm, SectionWithPeriods, SectionSimple } from "../DataForm"; | ||
import { Period } from "../DataValue"; | ||
import { sectionBase, dataFormBase } from "./dataFixtures"; | ||
|
||
describe("DataFormM", () => { | ||
describe("getReferencedPeriods", () => { | ||
it("should return basePeriod when there are no additional periods", () => { | ||
const dataForm: DataForm = { | ||
...dataFormBase, | ||
sections: [], | ||
}; | ||
|
||
const basePeriod: Period = "202101"; | ||
const result = DataFormM.getReferencedPeriods(dataForm, basePeriod); | ||
|
||
expect(result).toEqual([basePeriod]); | ||
}); | ||
|
||
it("should return unique periods from sections and basePeriod", () => { | ||
const sections: SectionWithPeriods[] = [ | ||
createSectionWithPeriods("1", ["202102", "202103"]), | ||
createSectionWithPeriods("2", ["202104", "202105"]), | ||
]; | ||
|
||
const dataForm: DataForm = { | ||
...dataFormBase, | ||
sections, | ||
}; | ||
|
||
const basePeriod: Period = "202101"; | ||
const result = DataFormM.getReferencedPeriods(dataForm, basePeriod); | ||
|
||
expect(result).toEqual(["202101", "202102", "202103", "202104", "202105"]); | ||
}); | ||
|
||
it("should handle mixed section types", () => { | ||
const sections = [createSectionWithPeriods("1", ["202102", "202103"]), createSectionSimple("2")]; | ||
|
||
const dataForm: DataForm = { | ||
...dataFormBase, | ||
sections, | ||
}; | ||
|
||
const basePeriod: Period = "202101"; | ||
const result = DataFormM.getReferencedPeriods(dataForm, basePeriod); | ||
|
||
expect(result).toEqual(["202101", "202102", "202103"]); | ||
}); | ||
|
||
it("should return sorted unique periods", () => { | ||
const sections = [ | ||
createSectionWithPeriods("1", ["202103", "202102"]), | ||
createSectionWithPeriods("2", ["202105", "202104"]), | ||
createSectionWithPeriods("3", ["202101", "202106"]), | ||
]; | ||
|
||
const dataForm: DataForm = { | ||
...dataFormBase, | ||
sections, | ||
}; | ||
|
||
const basePeriod: Period = "202100"; | ||
const result = DataFormM.getReferencedPeriods(dataForm, basePeriod); | ||
|
||
expect(result).toEqual(["202100", "202101", "202102", "202103", "202104", "202105", "202106"]); | ||
}); | ||
}); | ||
}); | ||
|
||
function createSectionSimple(id: Id): SectionSimple { | ||
return { | ||
id, | ||
name: `Section ${id}`, | ||
viewType: "grid-with-combos", | ||
...sectionBase, | ||
}; | ||
} | ||
|
||
function createSectionWithPeriods(id: Id, periods: Period[]): SectionWithPeriods { | ||
return { | ||
id, | ||
name: `Section ${id}`, | ||
viewType: "grid-with-periods", | ||
periods, | ||
...sectionBase, | ||
}; | ||
} |
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,48 @@ | ||
import { DataValueStore } from "../DataValue"; | ||
import { dataElementText, dataValues, dataValueTextSingle, dataValueBase } from "./dataFixtures"; | ||
|
||
describe("DataValueStore", () => { | ||
describe("DataValueStore.from", () => { | ||
it("should create a DataValueStore from an array of DataValues", () => { | ||
const store = DataValueStore.from(dataValues); | ||
expect(store).toBeInstanceOf(DataValueStore); | ||
expect(store.store).toEqual({ | ||
"1.202101.coc1.org1": dataValueTextSingle, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("DataValueStore.set", () => { | ||
it("should set a DataValue in the store", () => { | ||
const store = new DataValueStore({}); | ||
const updatedStore = store.set(dataValueTextSingle); | ||
expect(updatedStore.store).toEqual({ | ||
"1.202101.coc1.org1": dataValueTextSingle, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("DataValueStore.get", () => { | ||
it("should get a DataValue from the store", () => { | ||
const store = DataValueStore.from(dataValues); | ||
const dataValue = store.get(dataElementText, dataValueBase); | ||
expect(dataValue).toEqual(dataValueTextSingle); | ||
}); | ||
}); | ||
|
||
describe("DataValueStore.getOrEmpty", () => { | ||
it("should get a DataValue from the store", () => { | ||
const store = DataValueStore.from(dataValues); | ||
const dataValue = store.getOrEmpty(dataElementText, dataValueBase); | ||
expect(dataValue).toEqual(dataValueTextSingle); | ||
}); | ||
|
||
it("should return an empty DataValue if not in the store", () => { | ||
const store = new DataValueStore({}); | ||
const dataValue = store.getOrEmpty(dataElementText, dataValueBase); | ||
|
||
const emptyDataValue = { ...dataValueTextSingle, value: "" }; | ||
expect(dataValue).toEqual(emptyDataValue); | ||
}); | ||
}); | ||
}); |
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,37 @@ | ||
import { Indicator, checkIndicatorDirection, getIndicatorRelatedToDataElement, IndicatorDirection } from "../Indicator"; | ||
import { indicatorAfter, indicatorBefore, indicators } from "./indicatorFixtures"; | ||
|
||
describe("Indicator", () => { | ||
describe("checkIndicatorDirection", () => { | ||
it("should return true when the indicator's direction matches the provided direction", () => { | ||
const direction: IndicatorDirection = "after"; | ||
|
||
// indicatorAfter indicator contain { direction: "after" } | ||
const result = checkIndicatorDirection(indicatorAfter, direction); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it("should return false when the indicator's direction does not match the provided direction", () => { | ||
const direction: IndicatorDirection = "after"; | ||
|
||
// indicatorBefore indicator contain { direction: "before" } | ||
const result = checkIndicatorDirection(indicatorBefore, direction); | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
|
||
describe("getIndicatorRelatedToDataElement", () => { | ||
it("should return the indicator related to the specified data element code", () => { | ||
const codeToFind = "DE_1"; | ||
const result = getIndicatorRelatedToDataElement(indicators, codeToFind); | ||
// indicatorAfter indicator contain dataElement: { code: "DE_1", direction: "after" } | ||
expect(result).toEqual(indicatorAfter); | ||
}); | ||
|
||
it("should return undefined when no indicator is related to the specified data element code", () => { | ||
const codeToFind = "NON_EXISTENT_CODE"; | ||
const result = getIndicatorRelatedToDataElement(indicators, codeToFind); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.