addons/isl/src/__tests__/SuggestedRebase.test.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import {act, fireEvent, render, screen, within} from '@testing-library/react';
b69ab319import App from '../App';
b69ab3110import {bookmarksDataStorage} from '../BookmarksData';
b69ab3111import {writeAtom} from '../jotaiUtils';
b69ab3112import {
b69ab3113 COMMIT,
b69ab3114 closeCommitInfoSidebar,
b69ab3115 expectMessageSentToServer,
b69ab3116 resetTestMessages,
b69ab3117 simulateCommits,
b69ab3118 simulateRepoConnected,
b69ab3119} from '../testUtils';
b69ab3120import {succeedableRevset} from '../types';
b69ab3121
b69ab3122describe('Suggested Rebase button', () => {
b69ab3123 beforeEach(() => {
b69ab3124 resetTestMessages();
b69ab3125 render(<App />);
b69ab3126 act(() => {
b69ab3127 simulateRepoConnected();
b69ab3128 closeCommitInfoSidebar();
b69ab3129 expectMessageSentToServer({
b69ab3130 type: 'subscribe',
b69ab3131 kind: 'smartlogCommits',
b69ab3132 subscriptionID: expect.anything(),
b69ab3133 });
b69ab3134 simulateCommits({
b69ab3135 value: [
b69ab3136 COMMIT('1', 'some public base', '0', {phase: 'public'}),
b69ab3137 COMMIT('a', 'My Commit', '1'),
b69ab3138 COMMIT('b', 'Another Commit', 'a', {isDot: true}),
b69ab3139 ],
b69ab3140 });
b69ab3141 });
b69ab3142 });
b69ab3143
b69ab3144 it('shows suggested rebase button', () => {
b69ab3145 act(() => {
b69ab3146 simulateCommits({
b69ab3147 value: [
b69ab3148 COMMIT('main', 'main', '2', {phase: 'public', remoteBookmarks: ['remote/main']}),
b69ab3149 COMMIT('1', 'some public base', '0', {phase: 'public'}),
b69ab3150 COMMIT('a', 'My Commit', '1'),
b69ab3151 COMMIT('b', 'Another Commit', 'a', {isDot: true}),
b69ab3152 ],
b69ab3153 });
b69ab3154 });
b69ab3155
b69ab3156 expect(screen.getByText(`Rebase onto…`)).toBeInTheDocument();
b69ab3157 });
b69ab3158
b69ab3159 it('does not show suggested rebase button on commits already on a remote bookmark', () => {
b69ab3160 act(() => {
b69ab3161 simulateCommits({
b69ab3162 value: [
b69ab3163 COMMIT('main', 'main', '2', {phase: 'public', remoteBookmarks: ['remote/main']}),
b69ab3164 COMMIT('1', 'some public base', '0', {phase: 'public'}),
b69ab3165 COMMIT('a', 'My Commit', '2'), // on remote/main
b69ab3166 COMMIT('b', 'Another Commit', 'a', {isDot: true}),
b69ab3167 ],
b69ab3168 });
b69ab3169 });
b69ab3170
b69ab3171 expect(screen.queryByText('Rebase onto…')).not.toBeInTheDocument();
b69ab3172 });
b69ab3173
b69ab3174 it('does not show suggested rebase button on commits already on a stable location', () => {
b69ab3175 act(() => {
b69ab3176 simulateCommits({
b69ab3177 value: [
b69ab3178 COMMIT('main', 'main', '2', {
b69ab3179 phase: 'public',
b69ab3180 stableCommitMetadata: [{value: 'pulled here', description: ''}],
b69ab3181 }),
b69ab3182 COMMIT('1', 'some public base', '0', {phase: 'public'}),
b69ab3183 COMMIT('a', 'My Commit', '2'), // on stable
b69ab3184 COMMIT('b', 'Another Commit', 'a', {isDot: true}),
b69ab3185 ],
b69ab3186 });
b69ab3187 });
b69ab3188
b69ab3189 expect(screen.queryByText('Rebase onto…')).not.toBeInTheDocument();
b69ab3190 });
b69ab3191
b69ab3192 it('shows remote bookmarks as destinations in dropdown', () => {
b69ab3193 act(() => {
b69ab3194 simulateCommits({
b69ab3195 value: [
b69ab3196 COMMIT('main', 'main', '2', {
b69ab3197 phase: 'public',
b69ab3198 remoteBookmarks: ['remote/main'],
b69ab3199 }),
b69ab31100 COMMIT('1', 'some public base', '0', {phase: 'public'}),
b69ab31101 COMMIT('a', 'My Commit', '1'),
b69ab31102 COMMIT('b', 'Another Commit', 'a', {isDot: true}),
b69ab31103 ],
b69ab31104 });
b69ab31105 });
b69ab31106
b69ab31107 const rebaseOntoButton = screen.getByText('Rebase onto…');
b69ab31108 fireEvent.click(rebaseOntoButton);
b69ab31109
b69ab31110 expect(
b69ab31111 within(screen.getByTestId('context-menu-container')).getByText('remote/main'),
b69ab31112 ).toBeInTheDocument();
b69ab31113 });
b69ab31114
b69ab31115 it('shows stable locations as destinations in dropdown', () => {
b69ab31116 act(() => {
b69ab31117 simulateCommits({
b69ab31118 value: [
b69ab31119 COMMIT('main', 'main', '2', {
b69ab31120 phase: 'public',
b69ab31121 stableCommitMetadata: [{value: 'pulled here', description: ''}],
b69ab31122 }),
b69ab31123 COMMIT('1', 'some public base', '0', {phase: 'public'}),
b69ab31124 COMMIT('a', 'My Commit', '1'),
b69ab31125 COMMIT('b', 'Another Commit', 'a', {isDot: true}),
b69ab31126 ],
b69ab31127 });
b69ab31128 });
b69ab31129
b69ab31130 const rebaseOntoButton = screen.getByText(`Rebase onto…`);
b69ab31131 fireEvent.click(rebaseOntoButton);
b69ab31132
b69ab31133 expect(
b69ab31134 within(screen.getByTestId('context-menu-container')).getByText('pulled here'),
b69ab31135 ).toBeInTheDocument();
b69ab31136 });
b69ab31137
b69ab31138 it('clicking suggestion rebase runs operation', () => {
b69ab31139 act(() => {
b69ab31140 simulateCommits({
b69ab31141 value: [
b69ab31142 COMMIT('main', 'main', '2', {
b69ab31143 phase: 'public',
b69ab31144 remoteBookmarks: ['remote/main'],
b69ab31145 }),
b69ab31146 COMMIT('1', 'some public base', '0', {phase: 'public'}),
b69ab31147 COMMIT('a', 'My Commit', '1'),
b69ab31148 COMMIT('b', 'Another Commit', 'a', {isDot: true}),
b69ab31149 ],
b69ab31150 });
b69ab31151 });
b69ab31152
b69ab31153 const rebaseOntoButton = screen.getByText('Rebase onto…');
b69ab31154 fireEvent.click(rebaseOntoButton);
b69ab31155
b69ab31156 const suggestion = within(screen.getByTestId('context-menu-container')).getByText(
b69ab31157 'remote/main',
b69ab31158 );
b69ab31159 fireEvent.click(suggestion);
b69ab31160
b69ab31161 expectMessageSentToServer({
b69ab31162 type: 'runOperation',
b69ab31163 operation: expect.objectContaining({
b69ab31164 args: ['rebase', '-s', succeedableRevset('a'), '-d', succeedableRevset('remote/main')],
b69ab31165 }),
b69ab31166 });
b69ab31167 });
b69ab31168
b69ab31169 it('uses hash to run rebase operation if not a remote bookmark', () => {
b69ab31170 act(() => {
b69ab31171 simulateCommits({
b69ab31172 value: [
b69ab31173 COMMIT('3', 'main', '2', {
b69ab31174 phase: 'public',
b69ab31175 stableCommitMetadata: [{value: 'pulled here', description: ''}],
b69ab31176 }),
b69ab31177 COMMIT('1', 'some public base', '0', {phase: 'public'}),
b69ab31178 COMMIT('a', 'My Commit', '1'),
b69ab31179 COMMIT('b', 'Another Commit', 'a', {isDot: true}),
b69ab31180 ],
b69ab31181 });
b69ab31182 });
b69ab31183
b69ab31184 const rebaseOntoButton = screen.getByText('Rebase onto…');
b69ab31185 fireEvent.click(rebaseOntoButton);
b69ab31186
b69ab31187 const suggestion = within(screen.getByTestId('context-menu-container')).getByText(
b69ab31188 'pulled here',
b69ab31189 );
b69ab31190 fireEvent.click(suggestion);
b69ab31191
b69ab31192 expectMessageSentToServer({
b69ab31193 type: 'runOperation',
b69ab31194 operation: expect.objectContaining({
b69ab31195 args: ['rebase', '-s', succeedableRevset('a'), '-d', succeedableRevset('3')],
b69ab31196 }),
b69ab31197 });
b69ab31198 });
b69ab31199
b69ab31200 it('includes current stack base as a destination', () => {
b69ab31201 act(() => {
b69ab31202 simulateCommits({
b69ab31203 value: [
b69ab31204 COMMIT('3', 'main', '2', {phase: 'public'}),
b69ab31205 COMMIT('x', 'Commit X', '2', {isDot: true}),
b69ab31206 COMMIT('2', 'some public base 2', '0', {
b69ab31207 phase: 'public',
b69ab31208 remoteBookmarks: ['remote/main'],
b69ab31209 }),
b69ab31210 COMMIT('1', 'some public base', '0', {phase: 'public'}),
b69ab31211 COMMIT('b', 'Another Commit', 'a'),
b69ab31212 COMMIT('a', 'My Commit', '1'),
b69ab31213 ],
b69ab31214 });
b69ab31215 });
b69ab31216
b69ab31217 const rebaseOntoButton = screen.getByText('Rebase onto…');
b69ab31218 fireEvent.click(rebaseOntoButton);
b69ab31219
b69ab31220 const suggestion = within(screen.getByTestId('context-menu-container')).getByText(
b69ab31221 /Current Stack Base \(.*\), remote\/main/,
b69ab31222 );
b69ab31223 fireEvent.click(suggestion);
b69ab31224
b69ab31225 expectMessageSentToServer({
b69ab31226 type: 'runOperation',
b69ab31227 operation: expect.objectContaining({
b69ab31228 args: ['rebase', '-s', succeedableRevset('a'), '-d', succeedableRevset('remote/main')],
b69ab31229 }),
b69ab31230 });
b69ab31231 });
b69ab31232
b69ab31233 it('deselected remote bookmarks in bookmark manager hides them as suggested rebases', () => {
b69ab31234 act(() => {
b69ab31235 writeAtom(bookmarksDataStorage, data => ({
b69ab31236 ...data,
b69ab31237 useRecommendedBookmark: false,
b69ab31238 }));
b69ab31239
b69ab31240 simulateCommits({
b69ab31241 value: [
b69ab31242 COMMIT('3', 'main', '000', {phase: 'public', remoteBookmarks: ['remote/main']}),
b69ab31243 COMMIT('2', 'something else', '00', {phase: 'public', remoteBookmarks: ['remote/foo']}),
b69ab31244 COMMIT('1', 'base', '0', {phase: 'public'}),
b69ab31245 COMMIT('a', 'My Commit', '1'),
b69ab31246 COMMIT('b', 'Another Commit', 'a', {isDot: true}),
b69ab31247 ],
b69ab31248 });
b69ab31249 });
b69ab31250
b69ab31251 fireEvent.click(screen.getByTestId('bookmarks-manager-button'));
b69ab31252
b69ab31253 const fooBookmark = within(screen.getByTestId('bookmarks-manager-dropdown')).getByText(
b69ab31254 'remote/foo',
b69ab31255 );
b69ab31256 expect(fooBookmark).toBeInTheDocument();
b69ab31257 fireEvent.click(fooBookmark); // deselect
b69ab31258
b69ab31259 const rebaseOntoButton = screen.getByText(`Rebase onto…`);
b69ab31260 fireEvent.click(rebaseOntoButton);
b69ab31261
b69ab31262 expect(
b69ab31263 within(screen.getByTestId('context-menu-container')).queryByText('remote/foo'),
b69ab31264 ).not.toBeInTheDocument();
b69ab31265 });
b69ab31266});