Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable format button without Prettier applied #3545

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -36,7 +36,12 @@
/>
</div>
<div class="jhlite-vertical-space--slot">
<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
2 changes: 1 addition & 1 deletion src/test/javascript/spec/module/domain/Modules.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const defaultProjectHistory = (): ProjectHistory => ({
});

export const projectHistoryWithInit = (): ProjectHistory => ({
modules: [moduleSlug('init')],
modules: [moduleSlug('init'), moduleSlug('prettier')],
properties: appliedModuleProperties(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const defaultLandscape = (): Landscape =>
elements: [
initialModule('infinitest', 'Add infinitest filters', [applicationBaseNamePropertyDefinition()], []),
initialModule('init', 'Add some initial tools', [applicationBaseNamePropertyDefinition()], []),
initialModule('prettier', 'Add prettier', [applicationBaseNamePropertyDefinition()], []),
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ describe('Landscape', () => {

assertSelectedConnectorsCount(wrapper, 1);
expect(wrapper.find(wrappedElement('modules-apply-new-button')).text()).toContain('(1)');
expect(wrapper.find(wrappedElement('modules-apply-all-button')).text()).toContain('(2)');
expect(wrapper.find(wrappedElement('modules-apply-all-button')).text()).toContain('(3)');
});

it('Should not select not selectable module', async () => {
Expand Down 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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe another assert with a not applied one?

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
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const restLandscape = (): RestLandscape => ({
elements: [
landscapeModule('infinitest', 'Add infinitest filters', applicationBaseNameProperties()),
landscapeModule('init', 'Add some initial tools', applicationBaseNameProperties()),
landscapeModule('prettier', 'Add prettier', applicationBaseNameProperties()),
],
},
{
Expand Down