Skip to content

Commit

Permalink
Disable format button without Prettier applied
Browse files Browse the repository at this point in the history
  • Loading branch information
wmarques committed Sep 14, 2022
1 parent 198c962 commit d4fa0a4
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ export default defineComponent({
operationInProgress.value = false;
};

const isApplied = (moduleId: string): boolean => {
return landscapeValue().isApplied(new ModuleSlug(moduleId));
};

return {
levels,
isFeature,
Expand Down Expand Up @@ -397,6 +401,7 @@ export default defineComponent({
applyNewModules,
operationStarted,
operationEnded,
isApplied,
};
},
});
7 changes: 6 additions & 1 deletion src/main/webapp/app/module/primary/landscape/Landscape.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
@propertyDeleted="deleteProperty"
/>

<ProjectActionsVue :folderPath="folderPath" @operationStarted="operationStarted()" @operationEnded="operationEnded()">
<ProjectActionsVue
:folderPath="folderPath"
:isPrettierButtonEnabled="isApplied('prettier')"
@operationStarted="operationStarted()"
@operationEnded="operationEnded()"
>
<div class="jhlite-vertical-space--slot">
<button
class="jhlite-button -block"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
@propertyDeleted="deleteProperty"
/>

<ProjectActionsVue :folderPath="folderPath" @operationStarted="operationStarted()" @operationEnded="operationEnded()" />
<ProjectActionsVue
:folderPath="folderPath"
:isPrettierButtonEnabled="true"
@operationStarted="operationStarted()"
@operationEnded="operationEnded()"
/>
</aside>

<div class="jhipster-modules-list">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default defineComponent({
type: String,
required: true,
},
isPrettierButtonEnabled: {
type: Boolean,
required: true,
},
},
emits: ['operationStarted', 'operationEnded'],
setup(props, { emit }) {
Expand All @@ -27,6 +31,10 @@ export default defineComponent({
return operationInProgress.value || empty(props.folderPath);
};

const disabledPrettier = (): boolean => {
return disabledActions() || !props.isPrettierButtonEnabled;
};

const formatProject = (): void => {
startOperation();

Expand Down Expand Up @@ -85,6 +93,7 @@ export default defineComponent({

return {
disabledActions,
disabledPrettier,
formatProject,
downloadProject,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
tabindex="5"
class="jhlite-button -block"
@click="formatProject()"
:disabled="disabledActions()"
:disabled="disabledPrettier()"
data-selector="format-button"
>
<IconVue name="code" aria-label="Icon code" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ describe('Landscape', () => {
const [appliedModules] = modules.applyAll.lastCall.args as ModulesToApply[];
expect(appliedModules.modules.map(slug => slug.get())).toEqual(['vue']);
expect(wrapper.find(wrappedElement('modules-apply-new-button')).attributes('disabled')).toBeDefined();

const component: any = wrapper.vm;
expect(component.isApplied('vue')).toBeTruthy();
expect(component.isApplied('angular')).toBeFalsy();
const [message] = alertBus.success.lastCall.args;
expect(message).toBe('Modules applied');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ import sinon from 'sinon';

interface WrapperOptions {
folderPath: string;
isPrettierButtonEnabled: boolean;
modules: ModulesRepository;
}

const alertBus = stubAlertBus();
const windowStub = stubWindow();

const wrap = (options?: Partial<WrapperOptions>): VueWrapper => {
const { modules, folderPath }: WrapperOptions = {
const { modules, folderPath, isPrettierButtonEnabled }: WrapperOptions = {
folderPath: '/dummy',
modules: stubModulesRepository(),
isPrettierButtonEnabled: true,
...options,
};

return shallowMount(ProjectActionsVue, {
props: {
folderPath,
isPrettierButtonEnabled,
},
global: { provide: { modules, alertBus, globalWindow: windowStub } },
});
Expand All @@ -45,6 +48,18 @@ describe('Project actions', () => {

expect(wrapper.find(wrappedElement('format-button')).attributes('disabled')).toBeDefined();
});

it('should disable format button according to prop', async () => {
const wrapper = wrap({ isPrettierButtonEnabled: false });

expect(wrapper.find(wrappedElement('format-button')).attributes('disabled')).toBeDefined();
});

it('should enable format button according to prop', async () => {
const wrapper = wrap({ isPrettierButtonEnabled: true });

expect(wrapper.find(wrappedElement('format-button')).attributes('disabled')).toBeUndefined();
});
});

it('Should format file using repository', async () => {
Expand Down

0 comments on commit d4fa0a4

Please sign in to comment.