Skip to content

Commit

Permalink
change naming in stories
Browse files Browse the repository at this point in the history
  • Loading branch information
kathari00 committed Nov 10, 2024
1 parent 523ac17 commit b64ff39
Show file tree
Hide file tree
Showing 42 changed files with 240 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const decorators = (_: unknown, context: StoryContextLike) => ({
classes: {},
kcContext: getKcContextMock({
pageId: context.globals['pageId'],
overrides: context.globals['overrides']
overrides: context.globals['kcContext']
}),
getI18n: getI18n
})
Expand Down
2 changes: 1 addition & 1 deletion stories/account/KcPageStory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const decorators = (_: unknown, context: StoryContext) => ({
classes: {},
kcContext: getKcContextMock({
pageId: context.globals['pageId'],
overrides: context.globals['overrides']
overrides: context.globals['kcContext']
}),
getI18n: getI18n
})
Expand Down
64 changes: 64 additions & 0 deletions stories/account/pages/KcPageStory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* eslint-disable @angular-eslint/component-class-suffix */
import { Component, inject, OnInit, Type } from '@angular/core';
import { provideKeycloakifyAngular } from '@keycloakify/angular/account/providers/keycloakify-angular';
import { TemplateComponent } from '@keycloakify/angular/account/template';
import { getKcPage } from './KcPage';
import { getI18n } from './i18n';
import { KC_ACCOUNT_CONTEXT } from '@keycloakify/angular/account/tokens/kc-context';
import { createGetKcContextMock } from 'keycloakify/account/KcContext';
import { kcEnvDefaults, themeNames } from '../kc.gen';
import type { KcContextExtension, KcContextExtensionPerPage } from './KcContext';

const kcContextExtension: KcContextExtension = {
themeName: themeNames[0],
properties: {
...kcEnvDefaults
}
};
const kcContextExtensionPerPage: KcContextExtensionPerPage = {};

export const { getKcContextMock } = createGetKcContextMock({
kcContextExtension,
kcContextExtensionPerPage,
overrides: {},
overridesPerPage: {}
});

type StoryContextLike = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
globals: Record<string, any>;
};

export const decorators = (_: unknown, context: StoryContextLike) => ({
applicationConfig: {
providers: [
provideKeycloakifyAngular({
doUseDefaultCss: true,
classes: {},
kcContext: getKcContextMock({
pageId: context.globals['pageId'],
overrides: context.globals['kcContext']
}),
getI18n: getI18n
})
]
}
});

@Component({
selector: 'kc-page-story',
template: `@if (pageComponent) {
<kc-root [page]="pageComponent"></kc-root>
}`,
standalone: true,
imports: [TemplateComponent]
})
export class KcPageStory implements OnInit {
pageComponent: Type<unknown> | undefined;
kcContext = inject(KC_ACCOUNT_CONTEXT);
ngOnInit() {
getKcPage(this.kcContext.pageId).then(kcPage => {
this.pageComponent = kcPage.PageComponent;
});
}
}
12 changes: 6 additions & 6 deletions stories/account/pages/account.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Default: Story = {};

export const UsernameNotEditable: Story = {
globals: {
overrides: {
kcContext: {
account: {
username: 'john_doe',
email: 'john.doe@gmail.com',
Expand All @@ -45,7 +45,7 @@ export const UsernameNotEditable: Story = {

export const WithValidationErrors: Story = {
globals: {
overrides: {
kcContext: {
account: {
username: 'john_doe',
email: '',
Expand Down Expand Up @@ -73,7 +73,7 @@ export const WithValidationErrors: Story = {

export const EmailAsUsername: Story = {
globals: {
overrides: {
kcContext: {
account: {
email: 'john.doe@gmail.com',
firstName: 'John',
Expand All @@ -98,7 +98,7 @@ export const EmailAsUsername: Story = {

export const WithErrorCode: Story = {
globals: {
overrides: {
kcContext: {
code: {
success: false,
error: 'Failed to generate code'
Expand All @@ -109,7 +109,7 @@ export const WithErrorCode: Story = {

export const WithFrenchLanguage: Story = {
globals: {
overrides: {
kcContext: {
locale: {
currentLanguageTag: 'fr'
},
Expand All @@ -123,7 +123,7 @@ export const WithFrenchLanguage: Story = {

export const WithHtmlErrorMessage: Story = {
globals: {
overrides: {
kcContext: {
code: {
success: false,
error: "Something went wrong. <a href='https://example.com'>Try again</a>"
Expand Down
13 changes: 6 additions & 7 deletions stories/account/pages/applications.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Story = StoryObj<KcPageStory>;

export const Default: Story = {
globals: {
overrides: {
kcContext: {
applications: {
applications: [
{
Expand Down Expand Up @@ -72,7 +72,7 @@ export const Default: Story = {

export const NoAvailableRolesOrGrants: Story = {
globals: {
overrides: {
kcContext: {
applications: {
applications: [
{
Expand All @@ -95,7 +95,7 @@ export const NoAvailableRolesOrGrants: Story = {

export const ConsentNotRequired: Story = {
globals: {
overrides: {
kcContext: {
applications: {
applications: [
{
Expand All @@ -118,7 +118,7 @@ export const ConsentNotRequired: Story = {

export const NoRolesButConsentRequired: Story = {
globals: {
overrides: {
kcContext: {
applications: {
applications: [
{
Expand All @@ -141,7 +141,7 @@ export const NoRolesButConsentRequired: Story = {

export const OnlyResourceRolesAvailable: Story = {
globals: {
overrides: {
kcContext: {
applications: {
applications: [
{
Expand Down Expand Up @@ -173,8 +173,7 @@ export const OnlyResourceRolesAvailable: Story = {

export const NoAdditionalGrants: Story = {
globals: {
overrides: {
pageId: 'applications.ftl',
kcContext: {
applications: {
applications: [
{
Expand Down
6 changes: 3 additions & 3 deletions stories/account/pages/federated-identity.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Default: Story = {};

export const NotConnected: Story = {
globals: {
overrides: {
kcContext: {
federatedIdentity: {
identities: [
{
Expand All @@ -35,7 +35,7 @@ export const NotConnected: Story = {

export const RemoveLinkNotPossible: Story = {
globals: {
overrides: {
kcContext: {
federatedIdentity: {
identities: [
{
Expand All @@ -57,7 +57,7 @@ export const RemoveLinkNotPossible: Story = {

export const AddLinkForUnconnectedIdentity: Story = {
globals: {
overrides: {
kcContext: {
federatedIdentity: {
identities: [
{
Expand Down
12 changes: 6 additions & 6 deletions stories/account/pages/log.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Story = StoryObj<KcPageStory>;

export const Default: Story = {
globals: {
overrides: {
kcContext: {
log: {
events: [
{
Expand Down Expand Up @@ -48,7 +48,7 @@ export const Default: Story = {

export const LogsMissingDetails: Story = {
globals: {
overrides: {
kcContext: {
log: {
events: [
{
Expand All @@ -66,7 +66,7 @@ export const LogsMissingDetails: Story = {

export const SingleLogEntry: Story = {
globals: {
overrides: {
kcContext: {
log: {
events: [
{
Expand All @@ -87,7 +87,7 @@ export const SingleLogEntry: Story = {

export const LogsWithLongDetails: Story = {
globals: {
overrides: {
kcContext: {
log: {
events: [
{
Expand Down Expand Up @@ -117,7 +117,7 @@ export const LogsWithLongDetails: Story = {

export const EmptyClientField: Story = {
globals: {
overrides: {
kcContext: {
log: {
events: [
{
Expand All @@ -138,7 +138,7 @@ export const EmptyClientField: Story = {

export const NoLogsAvailable: Story = {
globals: {
overrides: {
kcContext: {
log: {
events: [] // No log events
}
Expand Down
82 changes: 37 additions & 45 deletions stories/account/pages/password.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ export const Default: Story = {};

export const WithMessage: Story = {
globals: {
overrides: {
kcContext: {
message: { type: 'success', summary: 'This is a test message' }
}
kcContext: {
message: { type: 'success', summary: 'This is a test message' }
}
}
};
Expand All @@ -34,19 +32,17 @@ export const WithMessage: Story = {
*/
export const FirstTimePasswordSetup: Story = {
globals: {
overrides: {
kcContext: {
account: {
username: 'john_doe'
},
password: {
passwordSet: false
},
url: {
passwordUrl: '/password'
},
stateChecker: 'state-checker'
}
kcContext: {
account: {
username: 'john_doe'
},
password: {
passwordSet: false
},
url: {
passwordUrl: '/password'
},
stateChecker: 'state-checker'
}
}
};
Expand All @@ -59,20 +55,18 @@ export const FirstTimePasswordSetup: Story = {
*/
export const IncorrectCurrentPassword: Story = {
globals: {
overrides: {
kcContext: {
message: { type: 'error', summary: 'Incorrect current password.' },
account: {
username: 'john_doe'
},
password: {
passwordSet: true
},
url: {
passwordUrl: '/password'
},
stateChecker: 'state-checker'
}
kcContext: {
message: { type: 'error', summary: 'Incorrect current password.' },
account: {
username: 'john_doe'
},
password: {
passwordSet: true
},
url: {
passwordUrl: '/password'
},
stateChecker: 'state-checker'
}
}
};
Expand All @@ -85,20 +79,18 @@ export const IncorrectCurrentPassword: Story = {
*/
export const SubmissionSuccessWithRedirect: Story = {
globals: {
overrides: {
kcContext: {
message: { type: 'success', summary: 'Password successfully changed.' },
account: {
username: 'john_doe'
},
password: {
passwordSet: true
},
url: {
passwordUrl: '/password'
},
stateChecker: 'state-checker'
}
kcContext: {
message: { type: 'success', summary: 'Password successfully changed.' },
account: {
username: 'john_doe'
},
password: {
passwordSet: true
},
url: {
passwordUrl: '/password'
},
stateChecker: 'state-checker'
}
}
};
Loading

0 comments on commit b64ff39

Please sign in to comment.