Skip to content

Commit

Permalink
[gh-59] add unit test for prop validator
Browse files Browse the repository at this point in the history
  • Loading branch information
obadakhalili committed Jul 25, 2022
1 parent 17d1bed commit e81028a
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions packages/vue3/src/tests/VueVisualFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,110 @@ beforeEach((ctx) => {
}
})

test("`filteringOptions` prop validator should work as expected", ({ commonProps }) => {
const filteringOptionsValidator =
VueVisualFilter.props.filteringOptions.validator

expect(filteringOptionsValidator(undefined)).toBeFalsy()

expect(filteringOptionsValidator(null)).toBeFalsy()

expect(filteringOptionsValidator({})).toBeFalsy()

expect(filteringOptionsValidator({ data: [] })).toBeFalsy()

expect(filteringOptionsValidator({ data: [{}] })).toBeFalsy()

expect(
filteringOptionsValidator({ data: [{ name: "Firstname" }] }),
).toBeFalsy()

expect(
filteringOptionsValidator({
data: [{ name: "Firstname", type: "nominal" }],
}),
).toBeFalsy()

expect(
filteringOptionsValidator({
data: [{ name: "Firstname", type: "nominal", values: [] }],
}),
).toBeFalsy()

expect(
filteringOptionsValidator({
data: [{ name: "Firstname", type: "nominal", values: ["Foo"] }],
}),
).toBeFalsy()

expect(
filteringOptionsValidator({
data: [
{ name: "Firstname", type: "nominal", values: ["a", "b"] },
{ name: "Firstname", type: "nominal", values: ["x"] },
],
}),
).toBeFalsy()

expect(
filteringOptionsValidator({
data: [{ name: "Firstname", type: "nominal", values: ["a"] }],
methods: {
nominal: null,
},
}),
).toBeFalsy()

expect(
filteringOptionsValidator({
data: [{ name: "Firstname", type: "nominal", values: ["a"] }],
methods: {
nominal: { a: null },
},
}),
).toBeFalsy()

expect(
filteringOptionsValidator({
data: [{ name: "Firstname", type: "nominal", values: ["a"] }],
methods: {
nominal: {
contian: () => {},
},
},
}),
).toBeFalsy()

// TODO: should be considered
// expect(
// filteringOptionsValidator({
// data: [{ name: "Firstname", type: "nominal", values: ["a"] }],
// methods: {
// nominal: {
// contian: () => {},
// },
// numeric: 0,
// },
// }),
// ).toBeFalsy()

expect(
filteringOptionsValidator({
data: [{ name: "Firstname", type: "nominal", values: ["a"] }],
methods: {
nominal: {
contian: () => {},
},
numeric: {
a: null,
},
},
}),
).toBeFalsy()

expect(filteringOptionsValidator(commonProps.filteringOptions)).toBeTruthy()
})

test("after initial render we should have group type and filter type selects with correct initial options", ({
commonProps,
}) => {
Expand Down

0 comments on commit e81028a

Please sign in to comment.