Skip to content

Commit b7f9055

Browse files
author
Dobromir Hristov
authored
fix: move multiline detection in DeclarationSource after we indent objC code (#395)
closes rdar://97024618
1 parent f318cd4 commit b7f9055

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/components/DocumentationTopic/PrimaryContent/DeclarationSource.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,11 @@ export default {
168168
},
169169
},
170170
async mounted() {
171-
if (hasMultipleLines(this.$refs.declarationGroup)) this.hasMultipleLines = true;
172-
173171
if (this.language === Language.objectiveC.key.api) {
174172
await this.$nextTick();
175173
indentDeclaration(this.$refs.code, this.language);
176174
}
175+
if (hasMultipleLines(this.$refs.declarationGroup)) this.hasMultipleLines = true;
177176
},
178177
};
179178
</script>

tests/unit/components/DocumentationTopic/PrimaryContent/DeclarationSource.spec.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ import DeclarationSource
1414
import { multipleLinesClass } from 'docc-render/constants/multipleLines';
1515
import { hasMultipleLines } from 'docc-render/utils/multipleLines';
1616
import { themeSettingsState } from 'docc-render/utils/theme-settings';
17+
import { indentDeclaration } from 'docc-render/utils/indentation';
18+
import Language from '@/constants/Language';
19+
import { flushPromises } from '../../../../../test-utils';
1720

1821
const { Token } = DeclarationSource.components;
1922
const { TokenKind } = Token.constants;
2023

21-
jest.mock('@/utils/multipleLines', () => ({
22-
hasMultipleLines: jest.fn(),
23-
}));
24+
jest.mock('@/utils/indentation');
25+
jest.mock('@/utils/multipleLines');
26+
27+
hasMultipleLines.mockImplementation(() => false);
2428

2529
describe('DeclarationSource', () => {
2630
let wrapper;
@@ -87,6 +91,27 @@ describe('DeclarationSource', () => {
8791
await wrapper.vm.$nextTick();
8892
expect(wrapper.find({ ref: 'declarationGroup' }).classes()).toContain(multipleLinesClass);
8993
});
94+
95+
it('runs the hasMultipleLines, after `indentDeclaration` for ObjC code', async () => {
96+
const callStack = [];
97+
hasMultipleLines.mockImplementationOnce(() => {
98+
callStack.push('hasMultipleLines');
99+
return true;
100+
});
101+
indentDeclaration.mockImplementationOnce(() => callStack.push('indentDeclaration'));
102+
103+
wrapper = shallowMount(DeclarationSource, {
104+
propsData: {
105+
...propsData,
106+
language: Language.objectiveC.key.api,
107+
},
108+
});
109+
await flushPromises();
110+
expect(indentDeclaration).toHaveBeenCalledTimes(1);
111+
expect(indentDeclaration)
112+
.toHaveBeenCalledWith(wrapper.find({ ref: 'code' }).element, Language.objectiveC.key.api);
113+
expect(callStack).toEqual(['indentDeclaration', 'hasMultipleLines']);
114+
});
90115
});
91116

92117
describe('Swift function/initializer formatting', () => {

0 commit comments

Comments
 (0)