Skip to content

Commit

Permalink
test: update selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdehaven committed Jan 3, 2024
1 parent 9fc7b64 commit 8a96b73
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
20 changes: 20 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,25 @@ module.exports = {
prefer: 'type-imports',
fixStyle: 'separate-type-imports',
}],
'vue/no-restricted-static-attribute': ['error',
{
key: 'data-test-id',
message: 'Using "data-test-id" is not allowed. Use "data-testid" instead.',
},
{
key: 'data-tracking-id',
message: 'Using "data-tracking-id" is not allowed. Use "data-testid" instead.',
},
],
'vue/no-restricted-v-bind': ['error',
{
argument: 'data-test-id',
message: 'Using "data-test-id" is not allowed. Use "data-testid" instead.',
},
{
argument: 'data-tracking-id',
message: 'Using "data-tracking-id" is not allowed. Use "data-testid" instead.',
},
],
},
}
6 changes: 3 additions & 3 deletions src/components/MarkdownContent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('<MarkdownContent />', () => {
},
})

expect(wrapper.find('.markdown-content').isVisible()).toBe(true)
expect(wrapper.findTestId('markdown-content').isVisible()).toBe(true)
expect(wrapper.find('h1').text()).toEqual(title)
expect(wrapper.findTestId('paragraph-1').isVisible()).toBe(true)
expect(wrapper.findTestId('paragraph-1').text()).toEqual(sentence)
Expand All @@ -59,8 +59,8 @@ describe('<MarkdownContent />', () => {
},
})

expect(wrapper.find('.markdown-content').isVisible()).toBe(true)
expect(wrapper.find('.markdown-content').attributes('class')).toContain(`mode-${mode}`)
expect(wrapper.findTestId('markdown-content').isVisible()).toBe(true)
expect(wrapper.findTestId('markdown-content').attributes('class')).toContain(`mode-${mode}`)
expect(wrapper.find('h1').text()).toEqual(title)
})
}
Expand Down
1 change: 1 addition & 0 deletions src/components/MarkdownUi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ref="markdownComponent"
class="kong-ui-public-markdown-ui"
:class="[`mode-${currentMode}`, `theme-${activeTheme}`, { 'fullscreen': isFullscreen }]"
data-testid="markdown-ui"
>
<div
v-if="editable && currentMode !== 'read'"
Expand Down
5 changes: 2 additions & 3 deletions vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { config, DOMWrapper } from '@vue/test-utils'
import { config } from '@vue/test-utils'

const DataTestIdPlugin = (wrapper: any) => {
/** Find element by `data-testid` selector */
const findTestId = (dataTestid: string): any => {
const dataSelector = `[data-testid="${dataTestid}"]`
const element = wrapper.element.querySelector(dataSelector)
return new DOMWrapper(element)
return wrapper.find(dataSelector)
}

return {
Expand Down

0 comments on commit 8a96b73

Please sign in to comment.