Skip to content

Commit

Permalink
Fix Workspace specs
Browse files Browse the repository at this point in the history
  • Loading branch information
savetheclocktower committed Dec 27, 2024
1 parent 88ef218 commit 6989391
Showing 1 changed file with 84 additions and 100 deletions.
184 changes: 84 additions & 100 deletions spec/workspace-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,118 +38,106 @@ describe('Workspace', () => {
}
});

function simulateReload() {
waitsForPromise(() => {
const workspaceState = workspace.serialize();
const projectState = atom.project.serialize({ isUnloading: true });
workspace.destroy();
atom.project.destroy();
atom.project = new Project({
notificationManager: atom.notifications,
async function simulateReload() {
const workspaceState = workspace.serialize();
const projectState = atom.project.serialize({ isUnloading: true });
workspace.destroy();
atom.project.destroy();
atom.project = new Project({
notificationManager: atom.notifications,
packageManager: atom.packages,
confirm: atom.confirm.bind(atom),
applicationDelegate: atom.applicationDelegate,
grammarRegistry: atom.grammars
});

return atom.project.deserialize(projectState).then(() => {
workspace = atom.workspace = new Workspace({
config: atom.config,
project: atom.project,
packageManager: atom.packages,
confirm: atom.confirm.bind(atom),
grammarRegistry: atom.grammars,
styleManager: atom.styles,
deserializerManager: atom.deserializers,
notificationManager: atom.notifications,
applicationDelegate: atom.applicationDelegate,
grammarRegistry: atom.grammars
});
return atom.project.deserialize(projectState).then(() => {
workspace = atom.workspace = new Workspace({
config: atom.config,
project: atom.project,
packageManager: atom.packages,
grammarRegistry: atom.grammars,
styleManager: atom.styles,
deserializerManager: atom.deserializers,
notificationManager: atom.notifications,
applicationDelegate: atom.applicationDelegate,
viewRegistry: atom.views,
assert: atom.assert.bind(atom),
textEditorRegistry: atom.textEditors
});
workspace.deserialize(workspaceState, atom.deserializers);
viewRegistry: atom.views,
assert: atom.assert.bind(atom),
textEditorRegistry: atom.textEditors
});
workspace.deserialize(workspaceState, atom.deserializers);
});
}

describe('serialization', () => {
describe('when the workspace contains text editors', () => {
it('constructs the view with the same panes', () => {
it('constructs the view with the same panes', async () => {
jasmine.useRealClock();
const pane1 = atom.workspace.getActivePane();
const pane2 = pane1.splitRight({ copyActiveItem: true });
const pane3 = pane2.splitRight({ copyActiveItem: true });
let pane4 = null;

waitsForPromise(() =>
atom.workspace
.open(null)
.then(editor => editor.setText('An untitled editor.'))
);
await atom.workspace
.open(null)
.then(editor => editor.setText('An untitled editor.'));

waitsForPromise(() =>
atom.workspace
.open('b')
.then(editor => pane2.activateItem(editor.copy()))
);
await atom.workspace
.open('b')
.then(editor => pane2.activateItem(editor.copy()));

waitsForPromise(() =>
atom.workspace
.open('../sample.js')
.then(editor => pane3.activateItem(editor))
);
await atom.workspace
.open('../sample.js')
.then(editor => pane3.activateItem(editor));

runs(() => {
pane3.activeItem.setCursorScreenPosition([2, 4]);
pane4 = pane2.splitDown();
});

waitsForPromise(() =>
atom.workspace
.open('../sample.txt')
.then(editor => pane4.activateItem(editor))
);
pane3.activeItem.setCursorScreenPosition([2, 4]);
pane4 = pane2.splitDown();

runs(() => {
pane4.getActiveItem().setCursorScreenPosition([0, 2]);
pane2.activate();
});
await atom.workspace
.open('../sample.txt')
.then(editor => pane4.activateItem(editor));

simulateReload();

runs(() => {
expect(atom.workspace.getTextEditors().length).toBe(5);
const [
editor1,
editor2,
untitledEditor,
editor3,
editor4
] = atom.workspace.getTextEditors();
const firstDirectory = atom.project.getDirectories()[0];
expect(firstDirectory).toBeDefined();
expect(editor1.getPath()).toBe(firstDirectory.resolve('b'));
expect(editor2.getPath()).toBe(
firstDirectory.resolve('../sample.txt')
);
expect(editor2.getCursorScreenPosition()).toEqual([0, 2]);
expect(editor3.getPath()).toBe(firstDirectory.resolve('b'));
expect(editor4.getPath()).toBe(
firstDirectory.resolve('../sample.js')
);
expect(editor4.getCursorScreenPosition()).toEqual([2, 4]);
expect(untitledEditor.getPath()).toBeUndefined();
expect(untitledEditor.getText()).toBe('An untitled editor.');
pane4.getActiveItem().setCursorScreenPosition([0, 2]);
pane2.activate();

expect(atom.workspace.getActiveTextEditor().getPath()).toBe(
editor3.getPath()
);
const pathEscaped = fs.tildify(
escapeStringRegex(atom.project.getPaths()[0])
);
expect(document.title).toMatch(
new RegExp(
`^${path.basename(editor3.getLongTitle())} \\u2014 ${pathEscaped}`
)
);
});
await simulateReload();

expect(atom.workspace.getTextEditors().length).toBe(5);
const [
editor1,
editor2,
untitledEditor,
editor3,
editor4
] = atom.workspace.getTextEditors();
const firstDirectory = atom.project.getDirectories()[0];
expect(firstDirectory).toBeDefined();
expect(editor1.getPath()).toBe(firstDirectory.resolve('b'));
expect(editor2.getPath()).toBe(
firstDirectory.resolve('../sample.txt')
);
expect(editor2.getCursorScreenPosition()).toEqual([0, 2]);
expect(editor3.getPath()).toBe(firstDirectory.resolve('b'));
expect(editor4.getPath()).toBe(
firstDirectory.resolve('../sample.js')
);
expect(editor4.getCursorScreenPosition()).toEqual([2, 4]);
expect(untitledEditor.getPath()).toBeUndefined();
expect(untitledEditor.getText()).toBe('An untitled editor.');

expect(atom.workspace.getActiveTextEditor().getPath()).toBe(
editor3.getPath()
);
const pathEscaped = fs.tildify(
escapeStringRegex(atom.project.getPaths()[0])
);
expect(document.title).toMatch(
new RegExp(
`^${path.basename(editor3.getLongTitle())} \\u2014 ${pathEscaped}`
)
);
});
});

Expand Down Expand Up @@ -1948,13 +1936,12 @@ describe('Workspace', () => {
it('invokes the observer when closing the one and only text editor after deserialization', async () => {
pane.activateItem(new TextEditor());

simulateReload();
await simulateReload();

workspace.onDidChangeActiveTextEditor(editor => observed.push(editor));
workspace.closeActivePaneItemOrEmptyPaneOrWindow();
expect(observed).toEqual([undefined]);

runs(() => {
workspace.onDidChangeActiveTextEditor(editor => observed.push(editor));
workspace.closeActivePaneItemOrEmptyPaneOrWindow();
expect(observed).toEqual([undefined]);
});
});
});

Expand Down Expand Up @@ -2027,14 +2014,11 @@ describe('Workspace', () => {
'source.coffee',
'source.js', // Tree-sitter grammars also load
'source.js',
'source.js',
'source.js.regexp',
'source.js.regexp',
'source.js.regexp',
'source.js.regexp.replacement',
'source.jsdoc',
'source.jsdoc',
'source.jsdoc',
'source.litcoffee',
'text.plain.null-grammar',
'text.todo',
Expand Down

0 comments on commit 6989391

Please sign in to comment.