From e925e60928926cbf1f252b42fba36a424561941f Mon Sep 17 00:00:00 2001 From: Jonathan Poltak Samosir Date: Mon, 20 May 2024 21:18:10 +0700 Subject: [PATCH] Allow UILogicTestFactory test cases to be skipped --- .../react/containers/ribbon/logic.test.ts | 106 +++++++++--------- src/tests/ui-logic-tests.ts | 11 +- 2 files changed, 62 insertions(+), 55 deletions(-) diff --git a/src/in-page-ui/ribbon/react/containers/ribbon/logic.test.ts b/src/in-page-ui/ribbon/react/containers/ribbon/logic.test.ts index 1b71c31c92..5f4702fb2d 100644 --- a/src/in-page-ui/ribbon/react/containers/ribbon/logic.test.ts +++ b/src/in-page-ui/ribbon/react/containers/ribbon/logic.test.ts @@ -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, diff --git a/src/tests/ui-logic-tests.ts b/src/tests/ui-logic-tests.ts index 145fd35e10..58d93a0748 100644 --- a/src/tests/ui-logic-tests.ts +++ b/src/tests/ui-logic-tests.ts @@ -12,6 +12,7 @@ export type UILogicTest = (context: Context) => Promise export type UILogicTestFactory = ( description: string, test: UILogicTest, + opts?: { shouldSkip?: boolean }, ) => void export interface UILogicTestDevice extends BackgroundIntegrationTestSetup { createElement: ( @@ -29,8 +30,9 @@ export interface MultiDeviceUILogicTestContext { export function makeSingleDeviceUILogicTestFactory( options?: BackgroundIntegrationTestSetupOpts, ): UILogicTestFactory { - 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({ @@ -46,8 +48,9 @@ export function makeSingleDeviceUILogicTestFactory( export function makeMultiDeviceUILogicTestFactory( options?: BackgroundIntegrationTestSetupOpts, ): UILogicTestFactory { - 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)