Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 07aa3e3

Browse files
myan9starpit
authored andcommitted
fix(packages/core): sidecar basic function should not require plugins
Fixes #3172
1 parent 64347ee commit 07aa3e3

File tree

6 files changed

+150
-44
lines changed

6 files changed

+150
-44
lines changed

clients/test/plugins/plugin-test/src/test/response/mmr-mode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ const test = new TestMMR(
2424
})
2525
)
2626

27-
test.modes()
27+
test.modes({ windowButtons: true })

packages/core/src/webapp/views/sidecar-init.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,51 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import Debug from 'debug'
17+
const debug = Debug('webapp/views/sidecar-init')
1618

1719
import { keys } from '../keys'
1820
import { isPopup } from '../popup-core'
19-
import { getTabFromTarget } from '../tab'
21+
import { getTabFromTarget, Tab, getCurrentTab } from '../tab'
2022
import { scrollIntoView } from '../scroll'
2123
import sidecarSelector from './sidecar-selector'
24+
import eventBus from '../../core/events'
2225

23-
import { isVisible, toggle } from './sidecar-visibility'
26+
import { isVisible, toggle, toggleMaximization, clearSelection } from './sidecar-visibility'
2427

28+
/**
29+
* Add onclick handlers to Sidecar Buttons
30+
*
31+
*/
32+
const registerWindowButtonsListeners = (tab: Tab) => {
33+
// maximize button
34+
sidecarSelector(tab, '.toggle-sidecar-maximization-button').onclick = () => {
35+
debug('toggle sidecar maximization')
36+
// indicate that the user requested maximization
37+
toggleMaximization(tab, 'user')
38+
}
39+
40+
// close button
41+
sidecarSelector(tab, '.toggle-sidecar-button').onclick = () => {
42+
debug('toggle sidecar visibility')
43+
toggle(tab)
44+
}
45+
46+
// quit button
47+
sidecarSelector(tab, '.sidecar-bottom-stripe-quit').onclick = () => {
48+
try {
49+
if (isPopup()) {
50+
debug('quit button click')
51+
window.close()
52+
} else {
53+
debug('close sidecar button click')
54+
clearSelection(tab)
55+
}
56+
} catch (err) {
57+
console.error('error handling quit button click', err)
58+
}
59+
}
60+
}
2561
/**
2662
* One-time initialization of sidecar view
2763
*
@@ -67,4 +103,10 @@ export default async () => {
67103
}
68104
}
69105
})
106+
107+
registerWindowButtonsListeners(getCurrentTab())
108+
109+
eventBus.on('/tab/new', (tab: Tab) => {
110+
registerWindowButtonsListeners(tab)
111+
})
70112
}

packages/test/src/api/mmr.ts

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import * as Common from './common'
1717
import * as CLI from './cli'
1818
import * as ReplExpect from './repl-expect'
1919
import * as SidecarExpect from './sidecar-expect'
20+
import * as Selectors from './selectors'
21+
import { keys as Keys } from './keys'
2022

2123
type Param = Command & MMRParam
2224

@@ -38,13 +40,25 @@ interface ModeParam {
3840
label?: string
3941
}
4042

43+
interface TestModeOptions {
44+
windowButtons?: boolean
45+
}
46+
47+
enum SidecarState {
48+
minimized = 'minimized',
49+
quited = 'quited',
50+
maximized = 'maximized'
51+
}
52+
53+
type SidecarStateParam = 'minimized' | 'quited' | 'maximized'
54+
4155
export class TestMMR {
4256
// eslint-disable-next-line no-useless-constructor
4357
public constructor(public readonly param: Param) {}
4458

4559
public name() {
4660
const { command, metadata } = this.param
47-
describe(`multi model response ${process.env.MOCHA_RUN_TARGET || ''}`, function(this: Common.ISuite) {
61+
describe(`mmr name ${process.env.MOCHA_RUN_TARGET || ''}`, function(this: Common.ISuite) {
4862
before(Common.before(this))
4963
after(Common.after(this))
5064

@@ -59,7 +73,7 @@ export class TestMMR {
5973

6074
public namespace() {
6175
const { command, metadata } = this.param
62-
describe(`multi model response ${process.env.MOCHA_RUN_TARGET || ''}`, function(this: Common.ISuite) {
76+
describe(`mmr namespace ${process.env.MOCHA_RUN_TARGET || ''}`, function(this: Common.ISuite) {
6377
before(Common.before(this))
6478
after(Common.after(this))
6579

@@ -74,7 +88,7 @@ export class TestMMR {
7488

7589
public kind() {
7690
const { command, kind } = this.param
77-
describe(`multi model response ${process.env.MOCHA_RUN_TARGET || ''}`, function(this: Common.ISuite) {
91+
describe(`mmr kind ${process.env.MOCHA_RUN_TARGET || ''}`, function(this: Common.ISuite) {
7892
before(Common.before(this))
7993
after(Common.after(this))
8094

@@ -87,7 +101,7 @@ export class TestMMR {
87101
})
88102
}
89103

90-
public modes() {
104+
public modes(options?: TestModeOptions) {
91105
const { command, modes } = this.param
92106

93107
describe(`mmr modes ${process.env.MOCHA_RUN_TARGET || ''}`, function(this: Common.ISuite) {
@@ -102,12 +116,91 @@ export class TestMMR {
102116
.then(SidecarExpect.modes(modes))
103117
.catch(Common.oops(this, true)))
104118

105-
const closeSidecar = () =>
106-
it('should minimize the sidecar', () => SidecarExpect.keyToClose(this.app).catch(Common.oops(this, true)))
119+
const toggleSidecarWithESC = (expectOpen = false) =>
120+
it(`should hit ESCAPE key and expect sidecar ${expectOpen ? 'open' : 'closed'}`, async () => {
121+
try {
122+
await this.app.client.keys(Keys.ESCAPE)
123+
expectOpen ? await SidecarExpect.open(this.app) : await SidecarExpect.closed(this.app)
124+
} catch (err) {
125+
await Common.oops(this, true)
126+
}
127+
})
128+
129+
const quit = () =>
130+
it('should fully close the sidecar', async () => {
131+
try {
132+
await this.app.client.waitForVisible(Selectors.SIDECAR_FULLY_CLOSE_BUTTON)
133+
await this.app.client.click(Selectors.SIDECAR_FULLY_CLOSE_BUTTON)
134+
await SidecarExpect.fullyClosed(this.app)
135+
} catch (err) {
136+
await Common.oops(this, true)
137+
}
138+
})
139+
140+
const maximize = () =>
141+
it('should maximize the sidecar', async () => {
142+
try {
143+
await this.app.client.waitForVisible(Selectors.SIDECAR_MAXIMIZE_BUTTON)
144+
await this.app.client.click(Selectors.SIDECAR_MAXIMIZE_BUTTON)
145+
await SidecarExpect.fullscreen(this.app)
146+
} catch (err) {
147+
await Common.oops(this, true)
148+
}
149+
})
150+
151+
const minimize = () => {
152+
it('should toggle the sidebar closed with close button click', async () => {
153+
try {
154+
await this.app.client.waitForVisible(Selectors.SIDECAR_CLOSE_BUTTON)
155+
await this.app.client.click(Selectors.SIDECAR_CLOSE_BUTTON)
156+
await SidecarExpect.closed(this.app)
157+
} catch (err) {
158+
await Common.oops(this, true)
159+
}
160+
})
161+
}
162+
163+
const backToOpen = (prevState: SidecarStateParam) => {
164+
const button =
165+
prevState === SidecarState.minimized
166+
? Selectors.SIDECAR_RESUME_FROM_CLOSE_BUTTON
167+
: Selectors.SIDECAR_MAXIMIZE_BUTTON
168+
169+
if (prevState === SidecarState.minimized || prevState === SidecarState.maximized) {
170+
it(`should resume the sidecar from ${prevState} to open`, async () => {
171+
try {
172+
await this.app.client.waitForVisible(button)
173+
await this.app.client.click(button)
174+
await SidecarExpect.open(this.app)
175+
} catch (err) {
176+
await Common.oops(this, true)
177+
}
178+
})
179+
}
180+
}
107181

108182
showModes()
109-
closeSidecar()
110-
showModes()
183+
184+
if (options && options.windowButtons === true) {
185+
toggleSidecarWithESC()
186+
toggleSidecarWithESC(true)
187+
188+
toggleSidecarWithESC()
189+
showModes()
190+
191+
minimize()
192+
backToOpen(SidecarState.minimized)
193+
194+
minimize()
195+
showModes()
196+
197+
maximize()
198+
backToOpen(SidecarState.maximized)
199+
showModes()
200+
201+
quit()
202+
showModes()
203+
}
111204
})
112205
}
113206
}

packages/test/src/api/selectors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const SIDECAR_MODE_BUTTON_SELECTED = (mode: string) =>
3535
export const SIDECAR_BACK_BUTTON = `${SIDECAR} .sidecar-bottom-stripe-back-button` // back button in the bottom stripe
3636
export const SIDECAR_MAXIMIZE_BUTTON = `${SIDECAR} .toggle-sidecar-maximization-button` // maximize button in the bottom stripe
3737
export const SIDECAR_CLOSE_BUTTON = `${SIDECAR} .sidecar-bottom-stripe-close` // close button in the bottom stripe
38+
export const SIDECAR_RESUME_FROM_CLOSE_BUTTON = `${SIDECAR_BASE} .sidecar-bottom-stripe-close` // resume button in minimized mode
3839
export const SIDECAR_FULLY_CLOSE_BUTTON = `${SIDECAR} .sidecar-bottom-stripe-quit` // fully close button in the bottom stripe
3940
export const PROCESSING_PROMPT_BLOCK = `${PROMPT_BLOCK}.repl-active`
4041
export const CURRENT_PROMPT_BLOCK = `${PROMPT_BLOCK}.repl-active`

packages/test/src/api/sidecar-expect.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ const show = (expected: string, selector: string) => async (app: Application) =>
131131
.then(() => app.client.getText(selector))
132132
.then(text => text === expected)
133133
})
134+
135+
return app
134136
}
135137

136138
export const name = (expectedName: string) => show(expectedName, Selectors.SIDECAR_TITLE)

plugins/plugin-core-support/src/lib/new-tab.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ import Models from '@kui-shell/core/api/models'
2727
import Settings from '@kui-shell/core/api/settings'
2828
import * as UI from '@kui-shell/core/api/ui-lite'
2929

30-
import {
31-
isVisible as isSidecarVisible,
32-
toggle,
33-
toggleMaximization
34-
} from '@kui-shell/core/webapp/views/sidecar-visibility'
30+
import { isVisible as isSidecarVisible } from '@kui-shell/core/webapp/views/sidecar-visibility'
3531
import sidecarSelector from '@kui-shell/core/webapp/views/sidecar-selector'
3632
import { listen } from '@kui-shell/core/webapp/listen'
3733
import { setStatus, Status } from '@kui-shell/core/webapp/status'
@@ -306,34 +302,6 @@ const perTabInit = (tab: UI.Tab, tabButton: HTMLElement, doListen = true) => {
306302
return closeTab(tab)
307303
}
308304

309-
// maximize button
310-
sidecarSelector(tab, '.toggle-sidecar-maximization-button').onclick = () => {
311-
debug('toggle sidecar maximization')
312-
// indicate that the user requested maximization
313-
toggleMaximization(tab, 'user')
314-
}
315-
316-
// close button
317-
sidecarSelector(tab, '.toggle-sidecar-button').onclick = () => {
318-
debug('toggle sidecar visibility')
319-
toggle(tab)
320-
}
321-
322-
// quit button
323-
sidecarSelector(tab, '.sidecar-bottom-stripe-quit').onclick = () => {
324-
try {
325-
if (UI.isPopup()) {
326-
debug('quit button click')
327-
window.close()
328-
} else {
329-
debug('close sidecar button click')
330-
Models.Selection.clear(tab)
331-
}
332-
} catch (err) {
333-
console.error('error handling quit button click', err)
334-
}
335-
}
336-
337305
// screenshot button
338306
sidecarSelector(tab, '.sidecar-screenshot-button').onclick = () => {
339307
debug('sidecar screenshot')

0 commit comments

Comments
 (0)