-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: component testing setup with vitest and jest-dom (#46)
* fix: hidden choices keyboard selection issue (#45) * fix: hidden choice keyboard selection * chore: 2.11.1 changelog * fix: issue where pressing space wouldn't continue * update to packages + added pinia testing package * tests starting to work * pnpm lock * tests working in workspace but intellisense on jest-dom lost... * fixed build command issue
- Loading branch information
Showing
16 changed files
with
1,673 additions
and
493 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"vitest.enable": true, | ||
"editor.tabSize": 2, | ||
"files.exclude": { | ||
"**/*.rpyc": true, | ||
|
This file was deleted.
Oops, something went wrong.
17 changes: 15 additions & 2 deletions
17
packages/narrat/examples/games/default/scripts/default.nar
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 |
---|---|---|
@@ -1,15 +1,22 @@ | ||
<template> | ||
<div class="tooltips-ui"> | ||
<FloatingTooltip v-if="tooltip" v-bind="tooltip" /> | ||
<FloatingTooltip v-if="floatingTooltip" v-bind="floatingTooltip" /> | ||
</div> | ||
</template> | ||
<script lang="ts" setup> | ||
import { tooltipsConfig } from '@/config'; | ||
import { useTooltips } from '@/stores/tooltip-store'; | ||
import { computed } from 'vue'; | ||
import FloatingTooltip from '../utils/floating-tooltip.vue'; | ||
import FloatingTooltip, { | ||
FloatingTooltipProps, | ||
} from '../utils/floating-tooltip.vue'; | ||
const tooltip = computed(() => useTooltips().tooltip); | ||
const width = computed(() => tooltipsConfig().options.width); | ||
const floatingTooltip = computed(() => { | ||
const tooltip = useTooltips().tooltip; | ||
return { | ||
...tooltip, | ||
screenMargin: tooltipsConfig().options.screenEdgesMinimumMargin ?? 5, | ||
} as FloatingTooltipProps; | ||
}); | ||
</script> | ||
<style></style> |
18 changes: 18 additions & 0 deletions
18
packages/narrat/src/components/utils/__tests__/alert-modal.spec.ts
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,18 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { render, screen } from '@testing-library/vue'; | ||
import AlertModal from '../alert-modal.vue'; | ||
|
||
describe('AlertModal.vue test', () => { | ||
it('renders a modal with the right title and text', () => { | ||
const title = 'Alert Modal test title'; | ||
const text = 'Alert modal test text'; | ||
render(AlertModal, { | ||
props: { | ||
title, | ||
text, | ||
} | ||
}); | ||
screen.getByText(title); | ||
screen.getByText(text); | ||
}) | ||
}); |
60 changes: 60 additions & 0 deletions
60
packages/narrat/src/components/utils/__tests__/floating-tooltip.spec.ts
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,60 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { render, screen } from '@testing-library/vue'; | ||
import FloatingTooltip from '../floating-tooltip.vue'; | ||
|
||
const title = 'Tooltip test title'; | ||
const text = 'Tooltip test text'; | ||
const width = 200; | ||
const maxWidth = window.innerWidth; | ||
const maxHeight = window.innerHeight; | ||
const screenMargin = 5; | ||
describe('FloatingTooltip.vue tests', () => { | ||
it('renders a tooltip with the right title and text', () => { | ||
render(FloatingTooltip, { | ||
props: { | ||
title, | ||
text, | ||
width: 200, | ||
x: 0, | ||
y: 0, | ||
}, | ||
}); | ||
screen.getByText(title); | ||
screen.getByText(text); | ||
}); | ||
|
||
it('renders tooltips at the right width', () => { | ||
const width = 200; | ||
render(FloatingTooltip, { | ||
props: { | ||
title, | ||
text, | ||
width, | ||
x: 0, | ||
y: 0, | ||
}, | ||
}); | ||
const titleElement = screen.getByText(title); | ||
const tooltip: HTMLElement = titleElement.parentElement!; | ||
expect(tooltip).toBeTruthy(); | ||
expect(tooltip).toHaveStyle({ width: `${width}px` }); | ||
}); | ||
|
||
it('adapts the position of the tooltip to the screen size', () => { | ||
render(FloatingTooltip, { | ||
props: { | ||
title, | ||
text, | ||
width, | ||
x: maxWidth, | ||
y: 0, | ||
screenMargin, | ||
}, | ||
}); | ||
const titleElement = screen.getByText(title); | ||
const tooltip: HTMLElement = titleElement.parentElement!; | ||
const correctX = maxWidth - width - screenMargin; | ||
expect(tooltip).toBeTruthy(); | ||
expect(tooltip).toHaveStyle({ left: `${correctX}px` }); | ||
}); | ||
}); |
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
Oops, something went wrong.