|
| 1 | +import { |
| 2 | + init, |
| 3 | + cleanup, |
| 4 | + screenshotIfFailed, |
| 5 | + DEFAULT_CONNECTION_NAME_1, |
| 6 | +} from '../helpers/compass'; |
| 7 | +import { expect } from 'chai'; |
| 8 | +import * as Selectors from '../helpers/selectors'; |
| 9 | +import { createNumbersCollection } from '../helpers/insert-data'; |
| 10 | +import type { Compass } from '../helpers/compass'; |
| 11 | +import type { CompassBrowser } from '../helpers/compass-browser'; |
| 12 | + |
| 13 | +describe('readWrite: true', function () { |
| 14 | + let compass: Compass; |
| 15 | + let browser: CompassBrowser; |
| 16 | + let connId: string; |
| 17 | + |
| 18 | + beforeEach(async function () { |
| 19 | + compass = await init(this.test?.fullTitle()); |
| 20 | + browser = compass.browser; |
| 21 | + await browser.setFeature('readWrite', false); |
| 22 | + await browser.setupDefaultConnections(); |
| 23 | + await createNumbersCollection('numbers', 1000, true); |
| 24 | + await browser.connectToDefaults(); |
| 25 | + connId = await browser.getConnectionIdByName(DEFAULT_CONNECTION_NAME_1); |
| 26 | + }); |
| 27 | + |
| 28 | + afterEach(async function () { |
| 29 | + if (compass) { |
| 30 | + await screenshotIfFailed(compass, this.currentTest); |
| 31 | + await browser.setFeature('readWrite', false); |
| 32 | + await cleanup(compass); |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + describe('in sidebar navigation', function () { |
| 37 | + it('should hide delete / rename controls for databases and collections, modify for views', async function () { |
| 38 | + await browser.setFeature('readWrite', true); |
| 39 | + |
| 40 | + const dbItem = browser.$(Selectors.sidebarDatabase(connId, 'test')); |
| 41 | + |
| 42 | + // Expand database list |
| 43 | + await browser.clickVisible(dbItem); |
| 44 | + |
| 45 | + const collItem = browser.$( |
| 46 | + Selectors.sidebarCollection(connId, 'test', 'numbers') |
| 47 | + ); |
| 48 | + const viewItem = browser.$( |
| 49 | + Selectors.sidebarCollection(connId, 'test', 'numbers_view') |
| 50 | + ); |
| 51 | + |
| 52 | + // Wait for collections to load |
| 53 | + await Promise.all([ |
| 54 | + collItem.waitForDisplayed(), |
| 55 | + viewItem.waitForDisplayed(), |
| 56 | + ]); |
| 57 | + |
| 58 | + // Check that drop db action is not available |
| 59 | + expect(await dbItem.$('aria/Drop database').isExisting()).to.eq( |
| 60 | + false, |
| 61 | + 'Expected "Drop database" button to NOT exist' |
| 62 | + ); |
| 63 | + |
| 64 | + // For collections only "open in" action is left, so "Show actions" |
| 65 | + // shouldn't be displayed |
| 66 | + await browser.clickVisible(collItem); |
| 67 | + expect(await collItem.$('aria/Show actions').isExisting()).to.eq( |
| 68 | + false, |
| 69 | + 'Expected extended actions menu for collection to NOT exist (all items are hidden)' |
| 70 | + ); |
| 71 | + |
| 72 | + await browser.clickVisible(viewItem); |
| 73 | + await browser.clickVisible(viewItem.$('aria/Show actions')); |
| 74 | + await viewItem.$('[role=menu]').waitForStable(); |
| 75 | + |
| 76 | + // For views you should still be able to duplicate them |
| 77 | + await viewItem.$('aria/Duplicate view').waitForDisplayed({ |
| 78 | + timeoutMsg: 'Expected "Duplicate view" action item to exist', |
| 79 | + }); |
| 80 | + |
| 81 | + // ... but everything else is not available |
| 82 | + expect(await viewItem.$('aria/Drop view').isExisting()).to.eq( |
| 83 | + false, |
| 84 | + 'Expected "Drop view" action item to NOT exist' |
| 85 | + ); |
| 86 | + expect(await viewItem.$('aria/Modify view').isExisting()).to.eq( |
| 87 | + false, |
| 88 | + 'Expected "Modify view" action item to NOT exist' |
| 89 | + ); |
| 90 | + }); |
| 91 | + }); |
| 92 | + |
| 93 | + describe('in view workspace', function () { |
| 94 | + it('should hide "Edit Pipeline" button', async function () { |
| 95 | + await browser.navigateToCollectionTab( |
| 96 | + DEFAULT_CONNECTION_NAME_1, |
| 97 | + 'test', |
| 98 | + 'numbers_view', |
| 99 | + 'Documents' |
| 100 | + ); |
| 101 | + |
| 102 | + // Should exist before we switch the option |
| 103 | + await browser.$('aria/Edit Pipeline').waitForDisplayed({ |
| 104 | + timeoutMsg: 'Expected "Edit Pipeline" action item to exist', |
| 105 | + }); |
| 106 | + |
| 107 | + void browser.setFeature('readWrite', true); |
| 108 | + |
| 109 | + // Should be hidden after that |
| 110 | + await browser.$('aria/Edit Pipeline').waitForExist({ |
| 111 | + reverse: true, |
| 112 | + timeoutMsg: 'Expected "Edit Pipeline" action item to NOT exist', |
| 113 | + }); |
| 114 | + }); |
| 115 | + }); |
| 116 | + |
| 117 | + describe('in Indexes collection sub tab', function () { |
| 118 | + it('should hide "Create Index" controls', async function () { |
| 119 | + await browser.navigateToCollectionTab( |
| 120 | + DEFAULT_CONNECTION_NAME_1, |
| 121 | + 'test', |
| 122 | + 'numbers', |
| 123 | + 'Indexes' |
| 124 | + ); |
| 125 | + |
| 126 | + let createIndexButtonLabel = 'Create'; |
| 127 | + |
| 128 | + // Should exist before we switch the option |
| 129 | + try { |
| 130 | + await browser.$(`aria/${createIndexButtonLabel}`).waitForDisplayed({ |
| 131 | + timeout: 10_000, |
| 132 | + timeoutMsg: 'Expected "Create" button to exist', |
| 133 | + }); |
| 134 | + } catch { |
| 135 | + createIndexButtonLabel = 'Create Index'; |
| 136 | + await browser.$(`aria/${createIndexButtonLabel}`).waitForDisplayed({ |
| 137 | + timeoutMsg: 'Expected "Create" or "Create Index" button to exist', |
| 138 | + }); |
| 139 | + } |
| 140 | + |
| 141 | + void browser.setFeature('readWrite', true); |
| 142 | + |
| 143 | + // Should be hidden after that |
| 144 | + await browser.$(`aria/${createIndexButtonLabel}`).waitForExist({ |
| 145 | + reverse: true, |
| 146 | + timeoutMsg: `Expected "${createIndexButtonLabel}" button to NOT exist`, |
| 147 | + }); |
| 148 | + }); |
| 149 | + }); |
| 150 | +}); |
0 commit comments