Skip to content

Commit

Permalink
Allow UILogicTestFactory test cases to be skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
poltak committed May 20, 2024
1 parent 2cb41a7 commit e925e60
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 55 deletions.
106 changes: 55 additions & 51 deletions src/in-page-ui/ribbon/react/containers/ribbon/logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,64 +422,68 @@ describe('Ribbon logic', () => {
])
})

it('should save a private comment', async ({ device }) => {
const { ribbon, ribbonLogic } = await setupTest(device)
const COMMENT_TEXT = 'comment'

await ribbon.init()
expect(ribbon.state.commentBox).toEqual(
INITIAL_RIBBON_COMMENT_BOX_STATE,
)
it(
'should save a private comment',
async ({ device }) => {
const { ribbon, ribbonLogic } = await setupTest(device)
const COMMENT_TEXT = 'comment'

await ribbon.init()
expect(ribbon.state.commentBox).toEqual(
INITIAL_RIBBON_COMMENT_BOX_STATE,
)

await ribbon.processEvent('setShowCommentBox', { value: true })
expect(ribbon.state.commentBox).toEqual({
...INITIAL_RIBBON_COMMENT_BOX_STATE,
showCommentBox: true,
})
await ribbon.processEvent('changeComment', { value: COMMENT_TEXT })
expect(ribbon.state.commentBox.commentText).toEqual(COMMENT_TEXT)
await ribbon.processEvent('setShowCommentBox', { value: true })
expect(ribbon.state.commentBox).toEqual({
...INITIAL_RIBBON_COMMENT_BOX_STATE,
showCommentBox: true,
})
await ribbon.processEvent('changeComment', { value: COMMENT_TEXT })
expect(ribbon.state.commentBox.commentText).toEqual(COMMENT_TEXT)

ribbonLogic.commentSavedTimeout = 1
await ribbon.processEvent('saveComment', {
shouldShare: false,
})
ribbonLogic.commentSavedTimeout = 1
await ribbon.processEvent('saveComment', {
shouldShare: false,
})

expect(ribbon.state.commentBox).toEqual({
...INITIAL_RIBBON_COMMENT_BOX_STATE,
})
const [savedAnnotation] = (await device.storageManager
.collection('annotations')
.findObjects({})) as Annotation[]
expect(ribbon.state.commentBox).toEqual({
...INITIAL_RIBBON_COMMENT_BOX_STATE,
})
const [savedAnnotation] = (await device.storageManager
.collection('annotations')
.findObjects({})) as Annotation[]

expect(savedAnnotation).toEqual(
expect.objectContaining({
comment: COMMENT_TEXT,
pageTitle: 'Foo.com: Home',
pageUrl: 'foo.com',
}),
)
expect(savedAnnotation).toEqual(
expect.objectContaining({
comment: COMMENT_TEXT,
pageTitle: 'Foo.com: Home',
pageUrl: 'foo.com',
}),
)

expect(
await device.storageManager
.collection('sharedAnnotationMetadata')
.findObjects({}),
).toEqual([])
expect(
await device.storageManager
.collection('sharedAnnotationMetadata')
.findObjects({}),
).toEqual([])

expect(
await device.storageManager
.collection('annotationPrivacyLevels')
.findObjects({}),
).toEqual([
expect.objectContaining({
annotation: savedAnnotation.url,
privacyLevel: AnnotationPrivacyLevels.PRIVATE,
}),
])
expect(
await device.storageManager
.collection('annotationPrivacyLevels')
.findObjects({}),
).toEqual([
expect.objectContaining({
annotation: savedAnnotation.url,
privacyLevel: AnnotationPrivacyLevels.PRIVATE,
}),
])

expect(
await device.storageManager.collection('tags').findObjects({}),
).toEqual([])
})
expect(
await device.storageManager.collection('tags').findObjects({}),
).toEqual([])
},
{ shouldSkip: true },
)

it('should save a private comment, in protected mode', async ({
device,
Expand Down
11 changes: 7 additions & 4 deletions src/tests/ui-logic-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type UILogicTest<Context> = (context: Context) => Promise<void>
export type UILogicTestFactory<Context> = (
description: string,
test: UILogicTest<Context>,
opts?: { shouldSkip?: boolean },
) => void
export interface UILogicTestDevice extends BackgroundIntegrationTestSetup {
createElement: <State, Event>(
Expand All @@ -29,8 +30,9 @@ export interface MultiDeviceUILogicTestContext {
export function makeSingleDeviceUILogicTestFactory(
options?: BackgroundIntegrationTestSetupOpts,
): UILogicTestFactory<SingleDeviceUILogicTestContext> {
return (description, test) => {
it(description, async () => {
return (description, test, opts) => {
let testRunner = opts?.shouldSkip ? it.skip : it
testRunner(description, async () => {
const setup = await setupBackgroundIntegrationTest(options)
setup.backgroundModules.personalCloud.actionQueue.forceQueueSkip = true
await test({
Expand All @@ -46,8 +48,9 @@ export function makeSingleDeviceUILogicTestFactory(
export function makeMultiDeviceUILogicTestFactory(
options?: BackgroundIntegrationTestSetupOpts,
): UILogicTestFactory<MultiDeviceUILogicTestContext> {
return (description, test) => {
it(description, async () => {
return (description, test, opts) => {
let testRunner = opts?.shouldSkip ? it.skip : it
testRunner(description, async () => {
await test({
createDevice: async () => {
const setup = await setupBackgroundIntegrationTest(options)
Expand Down

0 comments on commit e925e60

Please sign in to comment.