-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9314fc5
commit d90e150
Showing
4 changed files
with
168 additions
and
10 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
projects/client/src/lib/sections/summary/components/comments/_internal/setScrollInfo.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,76 @@ | ||
import { setScrollInfo } from '$lib/sections/summary/components/comments/_internal/setScrollInfo.ts'; | ||
import { renderStore } from '$test/beds/store/renderStore.ts'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
describe('action: setScrollInfo', () => { | ||
function scrollTo( | ||
node: HTMLDivElement, | ||
location: 'top' | 'middle' | 'bottom', | ||
) { | ||
vi.spyOn(node, 'scrollHeight', 'get') | ||
.mockReturnValueOnce(100); | ||
|
||
vi.spyOn(node, 'clientHeight', 'get') | ||
.mockReturnValueOnce(50); | ||
|
||
switch (location) { | ||
case 'top': | ||
node.scrollTop = 0; | ||
break; | ||
case 'middle': | ||
node.scrollTop = 25; | ||
break; | ||
case 'bottom': | ||
node.scrollTop = 50; | ||
break; | ||
} | ||
|
||
node.dispatchEvent(new Event('scroll')); | ||
} | ||
|
||
it('should not add scroll info if the node has no overflow', async () => { | ||
const node = document.createElement('div'); | ||
const component = await renderStore(() => setScrollInfo(node)); | ||
|
||
expect(node.classList).not.toContain('scrolled-down'); | ||
expect(node.classList).not.toContain('scrolled-up'); | ||
|
||
component.destroy(); | ||
}); | ||
|
||
it('should indicate it scrolled down to the bottom', async () => { | ||
const node = document.createElement('div'); | ||
const component = await renderStore(() => setScrollInfo(node)); | ||
|
||
scrollTo(node, 'bottom'); | ||
|
||
expect(node.classList).toContain('scrolled-down'); | ||
expect(node.classList).not.toContain('scrolled-up'); | ||
|
||
component.destroy(); | ||
}); | ||
|
||
it('should indicate it scrolled up to the top', async () => { | ||
const node = document.createElement('div'); | ||
const component = await renderStore(() => setScrollInfo(node)); | ||
|
||
scrollTo(node, 'top'); | ||
|
||
expect(node.classList).not.toContain('scrolled-down'); | ||
expect(node.classList).toContain('scrolled-up'); | ||
|
||
component.destroy(); | ||
}); | ||
|
||
it('should indicate it scrolled a little', async () => { | ||
const node = document.createElement('div'); | ||
const component = await renderStore(() => setScrollInfo(node)); | ||
|
||
scrollTo(node, 'middle'); | ||
|
||
expect(node.classList).toContain('scrolled-down'); | ||
expect(node.classList).toContain('scrolled-up'); | ||
|
||
component.destroy(); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
projects/client/src/lib/sections/summary/components/comments/_internal/spoilMeAnyway.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,32 @@ | ||
import { SPOILER_CLASS_NAME } from '$lib/features/spoilers/constants.ts'; | ||
import { spoilMeAnyway } from '$lib/sections/summary/components/comments/_internal/spoilMeAnyway.ts'; | ||
import { renderStore } from '$test/beds/store/renderStore.ts'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
describe('action: spoilMeAnyway', () => { | ||
it('should remove spoilers on the entire comment', async () => { | ||
const commentNode = document.createElement('div'); | ||
commentNode.classList.add(SPOILER_CLASS_NAME); | ||
|
||
const component = await renderStore(() => spoilMeAnyway(commentNode)); | ||
commentNode.dispatchEvent(new Event('click')); | ||
|
||
expect(commentNode.classList).not.toContain(SPOILER_CLASS_NAME); | ||
|
||
component.destroy(); | ||
}); | ||
|
||
it('should remove spoilers in a comment', async () => { | ||
const commentNode = document.createElement('div'); | ||
const spoilerNode = document.createElement('div'); | ||
commentNode.appendChild(spoilerNode); | ||
spoilerNode.classList.add(SPOILER_CLASS_NAME); | ||
|
||
const component = await renderStore(() => spoilMeAnyway(commentNode)); | ||
spoilerNode.dispatchEvent(new Event('click', { bubbles: true })); | ||
|
||
expect(spoilerNode.classList).not.toContain(SPOILER_CLASS_NAME); | ||
|
||
component.destroy(); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
...ts/client/src/lib/sections/summary/components/comments/_internal/spoilerExtension.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,35 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { | ||
matchSpoilerTag, | ||
matchSpoilerTagStart, | ||
spoilerRenderer, | ||
} from './spoilerExtension.ts'; | ||
|
||
describe('spoilerExtension', () => { | ||
it('should match the start of a spoiler tag', () => { | ||
const index = matchSpoilerTagStart('[spoiler]'); | ||
expect(index).to.equal(0); | ||
}); | ||
|
||
it('should match the a spoiler tag', () => { | ||
const match = matchSpoilerTag('[spoiler]test[/spoiler]'); | ||
expect(match).to.deep.equal(['[spoiler]test[/spoiler]', 'test']); | ||
}); | ||
|
||
it('should not match the another tag', () => { | ||
const match = matchSpoilerTag('[bold]test[/bold]'); | ||
expect(match).to.deep.equal(null); | ||
}); | ||
|
||
it('should render a spoiler tag', () => { | ||
const renderedResult = spoilerRenderer('test', false); | ||
|
||
expect(renderedResult).to.equal("<p class='trakt-spoiler'>test</p>"); | ||
}); | ||
|
||
it('should not render a spoiler tag if the entire comment is a spoiler', () => { | ||
const renderedResult = spoilerRenderer('test', true); | ||
|
||
expect(renderedResult).to.equal('<p>test</p>'); | ||
}); | ||
}); |
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