Skip to content

Commit aad8034

Browse files
committed
test: SketchyDiv tests completed
1 parent 54cb8ce commit aad8034

File tree

9 files changed

+60
-45
lines changed

9 files changed

+60
-45
lines changed

demo-app/src/App.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<SketchyDiv class="pd" style="margin-bottom: 10px">INsied</SketchyDiv>
2+
<SketchyDiv style="padding: 80px;"></SketchyDiv>
33
<SketchyBtn
44
label="Click"
55
style="padding: 10px 5px; font-size: 18px; margin-bottom: 100px"
@@ -15,7 +15,8 @@
1515
</template>
1616

1717
<script setup>
18-
import { SketchyDiv, SketchyBtn, SketchyHLine, SketchyTab, SketchyTabs } from "codeglynuikit";
18+
import { SketchyBtn, SketchyHLine, SketchyTab, SketchyTabs } from "codeglynuikit";
19+
import SketchyDiv from "../../lib/src/components/sketchydiv/SketchyDiv.vue";
1920
import { ref } from "vue";
2021
2122
const tab = ref("focuz")

docs/unit-tests/sketchy-div.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
These are some unit test cases for SketchyDiv component
33

44
## Rendering
5-
- div and convas dimensions matches
5+
- container div exist
6+
- canvas size is not 0 if container is greator then 0
67

78

89
## Props
9-
- classes passed to it are part of the container div
10+
- classes passed to it are classes of the container div
1011

1112
## Events
1213
- emit `click` event when clicked
@@ -15,9 +16,7 @@ These are some unit test cases for SketchyDiv component
1516
- *no tests specified*
1617

1718
## Slots
18-
- render a div in the dom
19-
- contain the text passed to it
20-
- contain the element passed to it
19+
- render a div that is passed in the slot
2120

2221
## Accessibility
2322
- *no tests specified*

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"dev": "vite",
4545
"build": "vite build",
4646
"preview": "vite preview",
47-
"test:browser": "vitest"
47+
"test:unit": "vitest"
4848
},
4949
"dependencies": {
5050
"roughjs": "^4.6.6",
Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,52 @@
1-
import { mount } from "@vue/test-utils";
2-
import { render } from "@testing-library/vue"
1+
import { flushPromises, mount } from "@vue/test-utils";
2+
import { fireEvent, render } from "@testing-library/vue";
33
import { describe, test, expect } from "vitest";
44
import SketchyDiv from "./SketchyDiv.vue";
55

66
describe("SketchyDiv", () => {
7-
test("div and convas dimension matches", () => {
8-
const wrapper = mount(SketchyDiv)
9-
console.log("Something is happening");
7+
test("container div exists", () => {
8+
const wrapper = render(SketchyDiv);
9+
expect(wrapper.container.firstChild.tagName).toBe("DIV");
10+
});
11+
test("canvas size is not 0 if container is greator then 0", () => {
12+
const wrapper = render(SketchyDiv, {
13+
attrs: {
14+
style: "padding: 80px",
15+
},
16+
});
17+
const canvas = wrapper.container.querySelector("canvas");
18+
expect(canvas.width).toBeGreaterThan(0);
19+
expect(canvas.height).toBeGreaterThan(0);
20+
});
21+
test("classes passed to it are classes of the container div", () => {
22+
const wrapper = render(SketchyDiv, {
23+
attrs: {
24+
class: "cls1 cls2",
25+
},
26+
});
27+
const containerDiv = wrapper.container.firstChild;
28+
expect(containerDiv).toHaveClass("cls1");
29+
});
30+
test("emit `click` event when clicked", async () => {
31+
const wrapper = render(SketchyDiv, {
32+
attrs: {
33+
class: "cls1 cls2",
34+
},
35+
});
36+
const containerDiv = wrapper.container.firstChild;
37+
await fireEvent.click(containerDiv);
38+
expect(wrapper.emitted().click).toBeTruthy();
39+
});
40+
test("render a div that is passed in the slot", () => {
41+
const slotContent =
42+
'<div data-testid="slot-div">This is inside SketchyDiv</div>';
43+
const wrapper = mount(SketchyDiv, {
44+
slots: {
45+
default: slotContent,
46+
},
47+
});
48+
49+
const slotDiv = wrapper.find('[data-testid="slot-div"]');
50+
expect(slotDiv.exists()).toBe(true);
1051
});
1152
});

lib/src/components/sketchydiv/SketchyDiv.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,18 @@ export default {
8787
}
8888
8989
onMounted(() => {
90+
console.log("onMounted, outNext", containerRef.value.clientHeight)
9091
nextTick(() => {
92+
console.log("onMounted, inNext", containerRef.value.clientHeight)
9193
size.value.width = containerRef.value.clientWidth;
9294
size.value.height = containerRef.value.clientHeight;
9395
drawDiv();
9496
});
9597
});
9698
onUpdated(() => {
99+
console.log("onUpdated, outNext", containerRef.value.clientHeight)
97100
nextTick(() => {
101+
console.log("onUpdated, inNext", containerRef.value.clientHeight)
98102
size.value.width = containerRef.value.clientWidth;
99103
size.value.height = containerRef.value.clientHeight;
100104
clearCanvas();
@@ -110,7 +114,7 @@ export default {
110114
height: size.value.height,
111115
class: style.boxCanvas,
112116
}),
113-
slots.default ? slots.default() : () => [],
117+
slots.default ? slots.default() : [],
114118
];
115119
116120
return h("div", nodeProps.value, { default: () => child });

lib/src/components/test/MyTest.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/vite.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default defineConfig({
1010
browser: {
1111
enabled: true,
1212
name: "firefox",
13+
// headless: true,
1314
provider: "playwright",
1415
// https://playwright.dev
1516
providerOptions: {},

lib/vitest-example/HelloWorld.test.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/vitest-example/HelloWorld.vue

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)