Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -37,7 +37,7 @@ describe('CredentialsLogic', () => {
isCredentialsDetailsComplete: false,
meta: {},
nameInputBlurred: false,
showCredentialsForm: false,
shouldShowCredentialsForm: false,
};

const mount = (defaults?: object) => {
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('CredentialsLogic', () => {
apiTokens: expect.any(Array),
activeApiToken: expect.any(Object),
activeApiTokenRawName: expect.any(String),
showCredentialsForm: expect.any(Boolean),
shouldShowCredentialsForm: expect.any(Boolean),
formErrors: expect.any(Array),
};

Expand Down Expand Up @@ -310,16 +310,16 @@ describe('CredentialsLogic', () => {
});
});

describe('showCredentialsForm', () => {
describe('shouldShowCredentialsForm', () => {
it('should reset to the default value, which closes the credentials form', () => {
mount({
showCredentialsForm: true,
shouldShowCredentialsForm: true,
});

CredentialsLogic.actions.onApiTokenCreateSuccess(newToken);
expect(CredentialsLogic.values).toEqual({
...values,
showCredentialsForm: false,
shouldShowCredentialsForm: false,
});
});
});
Expand Down Expand Up @@ -366,7 +366,7 @@ describe('CredentialsLogic', () => {
apiTokens: expect.any(Array),
activeApiToken: expect.any(Object),
activeApiTokenRawName: expect.any(String),
showCredentialsForm: expect.any(Boolean),
shouldShowCredentialsForm: expect.any(Boolean),
};

describe('apiTokens', () => {
Expand Down Expand Up @@ -437,16 +437,16 @@ describe('CredentialsLogic', () => {
});
});

describe('showCredentialsForm', () => {
describe('shouldShowCredentialsForm', () => {
it('should reset to the default value, which closes the credentials form', () => {
mount({
showCredentialsForm: true,
shouldShowCredentialsForm: true,
});

CredentialsLogic.actions.onApiTokenUpdateSuccess({ ...newToken, type: ADMIN });
expect(CredentialsLogic.values).toEqual({
...values,
showCredentialsForm: false,
shouldShowCredentialsForm: false,
});
});
});
Expand Down Expand Up @@ -849,32 +849,32 @@ describe('CredentialsLogic', () => {
});
});

describe('toggleCredentialsForm', () => {
describe('showCredentialsForm', () => {
const values = {
...DEFAULT_VALUES,
activeApiTokenIsExisting: expect.any(Boolean),
activeApiToken: expect.any(Object),
activeApiTokenRawName: expect.any(String),
formErrors: expect.any(Array),
showCredentialsForm: expect.any(Boolean),
shouldShowCredentialsForm: expect.any(Boolean),
};

describe('showCredentialsForm', () => {
it('should toggle `showCredentialsForm`', () => {
describe('shouldShowCredentialsForm', () => {
it('should toggle `shouldShowCredentialsForm`', () => {
mount({
showCredentialsForm: false,
shouldShowCredentialsForm: false,
});

CredentialsLogic.actions.toggleCredentialsForm();
CredentialsLogic.actions.showCredentialsForm();
expect(CredentialsLogic.values).toEqual({
...values,
showCredentialsForm: true,
shouldShowCredentialsForm: true,
});

CredentialsLogic.actions.toggleCredentialsForm();
CredentialsLogic.actions.showCredentialsForm();
expect(CredentialsLogic.values).toEqual({
...values,
showCredentialsForm: false,
shouldShowCredentialsForm: false,
});
});
});
Expand All @@ -885,7 +885,7 @@ describe('CredentialsLogic', () => {
formErrors: ['I am an error'],
});

CredentialsLogic.actions.toggleCredentialsForm();
CredentialsLogic.actions.showCredentialsForm();
expect(CredentialsLogic.values).toEqual({
...values,
formErrors: [],
Expand All @@ -897,7 +897,7 @@ describe('CredentialsLogic', () => {
it('should set `activeApiTokenRawName` to the name of the provided token', () => {
mount();

CredentialsLogic.actions.toggleCredentialsForm(newToken);
CredentialsLogic.actions.showCredentialsForm(newToken);
expect(CredentialsLogic.values).toEqual({
...values,
activeApiTokenRawName: 'myToken',
Expand All @@ -907,7 +907,7 @@ describe('CredentialsLogic', () => {
it('should set `activeApiTokenRawName` to the default value if no token is provided', () => {
mount();

CredentialsLogic.actions.toggleCredentialsForm();
CredentialsLogic.actions.showCredentialsForm();
expect(CredentialsLogic.values).toEqual({
...values,
activeApiTokenRawName: DEFAULT_VALUES.activeApiTokenRawName,
Expand All @@ -918,8 +918,8 @@ describe('CredentialsLogic', () => {
// used value... to be honest, this should probably just be a selector
// it('should set `activeApiTokenRawName` back to the default value if no token is provided', () => {
// mount();
// CredentialsLogic.actions.toggleCredentialsForm(newToken);
// CredentialsLogic.actions.toggleCredentialsForm();
// CredentialsLogic.actions.showCredentialsForm(newToken);
// CredentialsLogic.actions.showCredentialsForm();
// expect(CredentialsLogic.values).toEqual({
// ...values,
// activeApiTokenRawName: DEFAULT_VALUES.activeApiTokenRawName,
Expand All @@ -931,7 +931,7 @@ describe('CredentialsLogic', () => {
it('should set `activeApiToken` to the provided token', () => {
mount();

CredentialsLogic.actions.toggleCredentialsForm(newToken);
CredentialsLogic.actions.showCredentialsForm(newToken);
expect(CredentialsLogic.values).toEqual({
...values,
activeApiToken: newToken,
Expand All @@ -943,7 +943,7 @@ describe('CredentialsLogic', () => {
activeApiToken: newToken,
});

CredentialsLogic.actions.toggleCredentialsForm();
CredentialsLogic.actions.showCredentialsForm();
expect(CredentialsLogic.values).toEqual({
...values,
activeApiToken: DEFAULT_VALUES.activeApiToken,
Expand All @@ -958,7 +958,7 @@ describe('CredentialsLogic', () => {
activeApiTokenIsExisting: false,
});

CredentialsLogic.actions.toggleCredentialsForm(newToken);
CredentialsLogic.actions.showCredentialsForm(newToken);
expect(CredentialsLogic.values).toEqual({
...values,
activeApiTokenIsExisting: true,
Expand All @@ -971,7 +971,7 @@ describe('CredentialsLogic', () => {
});
const { id, ...newTokenWithoutId } = newToken;

CredentialsLogic.actions.toggleCredentialsForm(newTokenWithoutId);
CredentialsLogic.actions.showCredentialsForm(newTokenWithoutId);
expect(CredentialsLogic.values).toEqual({
...values,
activeApiTokenIsExisting: false,
Expand All @@ -983,7 +983,7 @@ describe('CredentialsLogic', () => {
activeApiTokenIsExisting: true,
});

CredentialsLogic.actions.toggleCredentialsForm();
CredentialsLogic.actions.showCredentialsForm();
expect(CredentialsLogic.values).toEqual({
...values,
activeApiTokenIsExisting: false,
Expand All @@ -995,7 +995,7 @@ describe('CredentialsLogic', () => {
describe('hideCredentialsForm', () => {
const values = {
...DEFAULT_VALUES,
showCredentialsForm: expect.any(Boolean),
shouldShowCredentialsForm: expect.any(Boolean),
activeApiTokenRawName: expect.any(String),
};

Expand All @@ -1013,16 +1013,16 @@ describe('CredentialsLogic', () => {
});
});

describe('showCredentialsForm', () => {
describe('shouldShowCredentialsForm', () => {
it('resets this value', () => {
mount({
showCredentialsForm: true,
shouldShowCredentialsForm: true,
});

CredentialsLogic.actions.hideCredentialsForm();
expect(CredentialsLogic.values).toEqual({
...values,
showCredentialsForm: false,
shouldShowCredentialsForm: false,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface ICredentialsLogicActions {
setTokenReadWrite(tokenReadWrite: ITokenReadWrite): ITokenReadWrite;
setTokenName(name: string): string;
setTokenType(tokenType: string): string;
toggleCredentialsForm(apiToken?: IApiToken): IApiToken;
showCredentialsForm(apiToken?: IApiToken): IApiToken;
hideCredentialsForm(): { value: boolean };
resetCredentials(): { value: boolean };
initializeCredentialsData(): { value: boolean };
Expand All @@ -66,7 +66,7 @@ export interface ICredentialsLogicValues {
fullEngineAccessChecked: boolean;
meta: Partial<IMeta>;
nameInputBlurred: boolean;
showCredentialsForm: boolean;
shouldShowCredentialsForm: boolean;
}

export const CredentialsLogic = kea<
Expand All @@ -90,7 +90,7 @@ export const CredentialsLogic = kea<
}),
setTokenName: (name) => name,
setTokenType: (tokenType) => tokenType,
toggleCredentialsForm: (apiToken = { ...defaultApiToken }) => apiToken,
showCredentialsForm: (apiToken = { ...defaultApiToken }) => apiToken,
hideCredentialsForm: false,
resetCredentials: false,
initializeCredentialsData: true,
Expand Down Expand Up @@ -175,14 +175,14 @@ export const CredentialsLogic = kea<
read: tokenType === PRIVATE,
type: tokenType,
}),
toggleCredentialsForm: (_, activeApiToken) => activeApiToken,
showCredentialsForm: (_, activeApiToken) => activeApiToken,
},
],
activeApiTokenRawName: [
'',
{
setTokenName: (_, activeApiTokenRawName) => activeApiTokenRawName,
toggleCredentialsForm: (activeApiTokenRawName, activeApiToken) =>
showCredentialsForm: (activeApiTokenRawName, activeApiToken) =>
activeApiToken.name || activeApiTokenRawName,
hideCredentialsForm: () => '',
onApiTokenCreateSuccess: () => '',
Expand All @@ -192,13 +192,13 @@ export const CredentialsLogic = kea<
activeApiTokenIsExisting: [
false,
{
toggleCredentialsForm: (_, activeApiToken) => !!activeApiToken.id,
showCredentialsForm: (_, activeApiToken) => !!activeApiToken.id,
},
],
showCredentialsForm: [
shouldShowCredentialsForm: [
false,
{
toggleCredentialsForm: (showCredentialsForm) => !showCredentialsForm,
showCredentialsForm: (shouldShowCredentialsForm) => !shouldShowCredentialsForm,
hideCredentialsForm: () => false,
onApiTokenCreateSuccess: () => false,
onApiTokenUpdateSuccess: () => false,
Expand All @@ -209,7 +209,7 @@ export const CredentialsLogic = kea<
{
onApiTokenError: (_, formErrors) => formErrors,
onApiTokenCreateSuccess: () => [],
toggleCredentialsForm: () => [],
showCredentialsForm: () => [],
resetCredentials: () => [],
},
],
Expand Down