-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Register top action bar Save and Save All button commands (#3889)
## Description - Addresses #2276 ### Changes - registers the Save and Save All commands to the `CommandCenter` so that they are available in the top action bar - add smoke test for the Save/Save All top action bar buttons and some scaffolding for future top action bar smoke tests - adds `isDisabled()` and `isEnabled()` to `PositronBaseElement` ### Demo https://github.com/posit-dev/positron/assets/25834218/6b6fb56c-5829-4700-8fda-8739cb678d8c ### QA Notes Please add new TestRail items for these new tests. --------- Co-authored-by: Jon Vanausdeln <[email protected]>
- Loading branch information
1 parent
d545aeb
commit e246589
Showing
7 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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,27 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
|
||
import { Code } from '../code'; | ||
import { PositronBaseElement } from './positronBaseElement'; | ||
|
||
const POSITRON_TOP_ACTION_BAR = 'div[id="workbench.parts.positron-top-action-bar"]'; | ||
const POSITRON_TOP_ACTION_SAVE_BUTTON = 'div[id="workbench.parts.positron-top-action-bar"] .action-bar-region-left .action-bar-button[aria-label="Save"]'; | ||
const POSITRON_TOP_ACTION_SAVE_ALL_BUTTON = 'div[id="workbench.parts.positron-top-action-bar"] .action-bar-region-left .action-bar-button[aria-label="Save All"]'; | ||
|
||
/* | ||
* Reuseable Positron top action bar functionality for tests to leverage. | ||
*/ | ||
export class PositronTopActionBar { | ||
topActionBar: PositronBaseElement; | ||
saveButton: PositronBaseElement; | ||
saveAllButton: PositronBaseElement; | ||
|
||
constructor(private code: Code) { | ||
this.topActionBar = new PositronBaseElement(POSITRON_TOP_ACTION_BAR, this.code); | ||
this.saveButton = new PositronBaseElement(POSITRON_TOP_ACTION_SAVE_BUTTON, this.code); | ||
this.saveAllButton = new PositronBaseElement(POSITRON_TOP_ACTION_SAVE_ALL_BUTTON, this.code); | ||
} | ||
} |
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
113 changes: 113 additions & 0 deletions
113
test/smoke/src/areas/positron/top-action-bar/top-action-bar.test.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,113 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { join } from 'path'; | ||
import { expect } from '@playwright/test'; | ||
import { Application, Logger } from '../../../../../automation'; | ||
import { installAllHandlers } from '../../../utils'; | ||
|
||
/* | ||
* Top Action Bar test cases | ||
*/ | ||
export function setup(logger: Logger) { | ||
describe('Top Action Bar', () => { | ||
// Shared before/after handling | ||
installAllHandlers(logger); | ||
|
||
describe('Save Actions', () => { | ||
before(async function () { | ||
|
||
}); | ||
|
||
it('Save and Save All both disabled when no unsaved editors are open [C656253]', async function () { | ||
const app = this.app as Application; | ||
await app.workbench.quickaccess.runCommand('workbench.action.closeAllEditors', { keepOpen: false }); | ||
expect(await app.workbench.positronTopActionBar.saveButton.isDisabled()).toBeTruthy(); | ||
expect(await app.workbench.positronTopActionBar.saveAllButton.isDisabled()).toBeTruthy(); | ||
}); | ||
|
||
it('Save enabled and Save All disabled when a single unsaved file is open [C656254]', async function () { | ||
const app = this.app as Application; | ||
const fileName = 'README.md'; | ||
await app.workbench.quickaccess.runCommand('workbench.action.closeAllEditors', { keepOpen: false }); | ||
await app.workbench.quickaccess.openFile(join(app.workspacePathOrFolder, fileName)); | ||
await app.workbench.quickaccess.runCommand('workbench.action.keepEditor', { keepOpen: false }); | ||
await app.workbench.editors.selectTab(fileName); | ||
await app.workbench.editor.waitForTypeInEditor(fileName, 'Puppies frolicking in a meadow of wildflowers'); | ||
// The file is now "dirty" and the save buttons should be enabled | ||
await app.workbench.editors.waitForTab(fileName, true); | ||
await expect(async () => { | ||
expect(await app.workbench.positronTopActionBar.saveButton.isEnabled()).toBeTruthy(); | ||
expect(await app.workbench.positronTopActionBar.saveAllButton.isEnabled()).toBeTruthy(); | ||
}).toPass({ timeout: 10000 }); | ||
await app.workbench.positronTopActionBar.saveButton.click(); | ||
// The file is now saved, so the file should no longer be "dirty" | ||
await app.workbench.editors.waitForTab(fileName, false); | ||
await expect(async () => { | ||
// The Save button stays enabled even when the active file is not "dirty" | ||
expect(await app.workbench.positronTopActionBar.saveButton.isEnabled()).toBeTruthy(); | ||
// The Save All button is disabled when less than 2 files are "dirty" | ||
expect(await app.workbench.positronTopActionBar.saveAllButton.isDisabled()).toBeTruthy(); | ||
}).toPass({ timeout: 10000 }); | ||
}); | ||
|
||
it('Save and Save All both enabled when multiple unsaved files are open [C656255]', async function () { | ||
const app = this.app as Application; | ||
const fileName1 = 'README.md'; | ||
const fileName2 = 'DESCRIPTION'; | ||
const text = 'Kittens playing with yarn'; | ||
// Open two files and type in some text | ||
await app.workbench.quickaccess.runCommand('workbench.action.closeAllEditors', { keepOpen: false }); | ||
await app.workbench.quickaccess.openFile(join(app.workspacePathOrFolder, fileName1)); | ||
await app.workbench.quickaccess.runCommand('workbench.action.keepEditor', { keepOpen: false }); | ||
await app.workbench.quickaccess.openFile(join(app.workspacePathOrFolder, fileName2)); | ||
await app.workbench.quickaccess.runCommand('workbench.action.keepEditor', { keepOpen: false }); | ||
await app.workbench.editors.selectTab(fileName1); | ||
await app.workbench.editor.waitForTypeInEditor(fileName1, text); | ||
await app.workbench.editors.selectTab(fileName2); | ||
await app.workbench.editor.waitForTypeInEditor(fileName2, text); | ||
// The files are now "dirty" and the save buttons should be enabled | ||
await app.workbench.editors.waitForTab(fileName1, true); | ||
await app.workbench.editors.waitForTab(fileName2, true); | ||
await expect(async () => { | ||
expect(await app.workbench.positronTopActionBar.saveButton.isEnabled()).toBeTruthy(); | ||
expect(await app.workbench.positronTopActionBar.saveAllButton.isEnabled()).toBeTruthy(); | ||
}).toPass({ timeout: 10000 }); | ||
await app.workbench.positronTopActionBar.saveAllButton.click(); | ||
// The files are now saved, so the files should no longer be "dirty" | ||
await app.workbench.editors.waitForTab(fileName1, false); | ||
await app.workbench.editors.waitForTab(fileName2, false); | ||
await expect(async () => { | ||
// The Save button stays enabled even when the active file is not "dirty" | ||
expect(await app.workbench.positronTopActionBar.saveButton.isEnabled()).toBeTruthy(); | ||
// The Save All button is disabled when less than 2 files are "dirty" | ||
expect(await app.workbench.positronTopActionBar.saveAllButton.isDisabled()).toBeTruthy(); | ||
}).toPass({ timeout: 10000 }); | ||
}); | ||
|
||
it('Save and Save All both enabled when an unsaved new file is open [C656253]', async function () { | ||
const app = this.app as Application; | ||
const fileName = 'Untitled-1'; | ||
const text = 'Bunnies hopping through a field of clover'; | ||
// Open a new file and type in some text | ||
await app.workbench.quickaccess.runCommand('workbench.action.closeAllEditors', { keepOpen: false }); | ||
await app.workbench.quickaccess.runCommand('workbench.action.files.newUntitledFile', { keepOpen: false }); | ||
await app.workbench.editors.selectTab(fileName); | ||
await app.workbench.editor.waitForTypeInEditor(fileName, text); | ||
// The file is now "dirty" and the save buttons should be enabled | ||
await app.workbench.editors.waitForTab(fileName, true); | ||
await expect(async () => { | ||
expect(await app.workbench.positronTopActionBar.saveButton.isEnabled()).toBeTruthy(); | ||
expect(await app.workbench.positronTopActionBar.saveAllButton.isEnabled()).toBeTruthy(); | ||
}).toPass({ timeout: 10000 }); | ||
// We won't try to click the Save buttons because a system dialog will pop up and we | ||
// can't automate interactions with the native file dialog | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
} | ||
|
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