From 06ea19ed3aa3a2708cc7376537b5f48e2735a2f4 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 28 May 2022 07:28:12 +0200 Subject: [PATCH] feat(tests): add e2e tests for widgets (#8735) * test(e2e): add baseline for widget tests * chore(repo): enable test running in branch * fix(e2e): set viewport for widget tests * fix(client): add widget identifier classes to widgets * test(e2e): add memo widget test * fix(tests): force select value * fix(tests): force button press for widget addition * fix(tests): invoke select value differently * fix(tests): adjust widget submit * fix(tests): don't explicitly navigate for widget test * fix(tests): click label to hide select popup * fix(tests): just click modal background * fix(tests): adjust modal background selector * fix(tests): click all modal backgrounds * feat(e2e): add test for adding timeline widget * fix(client): add more widget identifier classes * feat(tests): add method abstraction for test cases * fix(tests): force-click overlays * fix(tests): force widget button press * fix(tests): remove timeout from final widget check * feat(tests): add widget removal test case * fix(client): use mk instead of msky as class prefix * fix(tests): check widgets for existence rather than visibility * chore(meta): don't run tests for specific feature branch --- cypress/integration/widgets.js | 84 +++++++++++++++++++ packages/client/src/components/widgets.vue | 4 +- packages/client/src/ui/universal.widgets.vue | 2 +- packages/client/src/widgets/activity.vue | 2 +- packages/client/src/widgets/aichan.vue | 2 +- packages/client/src/widgets/aiscript.vue | 2 +- packages/client/src/widgets/clock.vue | 2 +- packages/client/src/widgets/federation.vue | 2 +- packages/client/src/widgets/memo.vue | 2 +- packages/client/src/widgets/notifications.vue | 2 +- packages/client/src/widgets/photos.vue | 2 +- packages/client/src/widgets/post-form.vue | 2 +- packages/client/src/widgets/rss.vue | 2 +- packages/client/src/widgets/slideshow.vue | 2 +- packages/client/src/widgets/timeline.vue | 2 +- packages/client/src/widgets/trends.vue | 2 +- 16 files changed, 100 insertions(+), 16 deletions(-) create mode 100644 cypress/integration/widgets.js diff --git a/cypress/integration/widgets.js b/cypress/integration/widgets.js new file mode 100644 index 000000000..d63ff274b --- /dev/null +++ b/cypress/integration/widgets.js @@ -0,0 +1,84 @@ +describe('After user signed in', () => { + beforeEach(() => { + cy.window(win => { + win.indexedDB.deleteDatabase('keyval-store'); + }); + cy.viewport('macbook-16'); + cy.request('POST', '/api/reset-db').as('reset'); + cy.get('@reset').its('status').should('equal', 204); + cy.reload(true); + + // インスタンス初期セットアップ + cy.request('POST', '/api/admin/accounts/create', { + username: 'admin', + password: 'pass', + }).its('body').as('admin'); + + // ユーザー作成 + cy.request('POST', '/api/signup', { + username: 'alice', + password: 'alice1234', + }).its('body').as('alice'); + + cy.visit('/'); + + cy.intercept('POST', '/api/signin').as('signin'); + + cy.get('[data-cy-signin]').click(); + cy.get('[data-cy-signin-username] input').type('alice'); + cy.get('[data-cy-signin-password] input').type('alice1234{enter}'); + + cy.wait('@signin').as('signedIn'); + }); + + afterEach(() => { + // テスト終了直前にページ遷移するようなテストケース(例えばアカウント作成)だと、たぶんCypressのバグでブラウザの内容が次のテストケースに引き継がれてしまう(例えばアカウントが作成し終わった段階からテストが始まる)。 + // waitを入れることでそれを防止できる + cy.wait(1000); + }); + + it('widget edit toggle is visible', () => { + cy.get('.mk-widget-edit').should('be.visible'); + }); + + it('widget select should be visible in edit mode', () => { + cy.get('.mk-widget-edit').click(); + cy.get('.mk-widget-select').should('be.visible'); + }); + + it('first widget should be removed', () => { + cy.get('.mk-widget-edit').click(); + cy.get('.customize-container:first-child .remove._button').click(); + cy.get('.customize-container').should('have.length', 2); + }); + + function buildWidgetTest(widgetName) { + it(`${widgetName} widget should get added`, () => { + cy.get('.mk-widget-edit').click(); + cy.get('.mk-widget-select select').select(widgetName, { force: true }); + cy.get('.bg._modalBg.transparent').click({ multiple: true, force: true }); + cy.get('.mk-widget-add').click({ force: true }); + cy.get(`.mkw-${widgetName}`).should('exist'); + }); + } + + buildWidgetTest('memo'); + buildWidgetTest('notifications'); + buildWidgetTest('timeline'); + buildWidgetTest('calendar'); + buildWidgetTest('rss'); + buildWidgetTest('trends'); + buildWidgetTest('clock'); + buildWidgetTest('activity'); + buildWidgetTest('photos'); + buildWidgetTest('digitalClock'); + buildWidgetTest('federation'); + buildWidgetTest('postForm'); + buildWidgetTest('slideshow'); + buildWidgetTest('serverMetric'); + buildWidgetTest('onlineUsers'); + buildWidgetTest('jobQueue'); + buildWidgetTest('button'); + buildWidgetTest('aiscript'); + buildWidgetTest('aichan'); +}); diff --git a/packages/client/src/components/widgets.vue b/packages/client/src/components/widgets.vue index b6835795c..74dd79f73 100644 --- a/packages/client/src/components/widgets.vue +++ b/packages/client/src/components/widgets.vue @@ -2,11 +2,11 @@
diff --git a/packages/client/src/widgets/activity.vue b/packages/client/src/widgets/activity.vue index 631beceb7..7fb9f5894 100644 --- a/packages/client/src/widgets/activity.vue +++ b/packages/client/src/widgets/activity.vue @@ -1,5 +1,5 @@