-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed CR issues, added stories and unit tests.
- Loading branch information
tolerants
committed
Sep 6, 2024
1 parent
c5c5ed8
commit 8a65c3b
Showing
6 changed files
with
188 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
libs/domain/product/variant-selector/stories/demo.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { MockProductService } from '@oryx-frontend/product/mocks'; | ||
import { Meta, Story } from '@storybook/web-components'; | ||
import { TemplateResult, html } from 'lit'; | ||
import { storybookPrefix } from '../../.constants'; | ||
|
||
export default { | ||
title: `${storybookPrefix}/Variant selector`, | ||
parameters: { | ||
chromatic: { | ||
disableSnapshot: true, | ||
}, | ||
}, | ||
} as Meta; | ||
|
||
const Template: Story = (): TemplateResult => { | ||
return html`<oryx-product-variant-selector sku="variant-selector"></oryx-product-variant-selector>`; | ||
}; | ||
|
||
export const Demo = Template.bind({}); |
26 changes: 26 additions & 0 deletions
26
libs/domain/product/variant-selector/stories/static.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { MockProductService } from '@oryx-frontend/product/mocks'; | ||
import { Meta, Story } from '@storybook/web-components'; | ||
import { TemplateResult, html } from 'lit'; | ||
import { storybookPrefix } from '../../.constants'; | ||
|
||
export default { | ||
title: `${storybookPrefix}/Variant selector/Static`, | ||
} as unknown as Meta; | ||
|
||
const Template: Story<unknown> = (): TemplateResult => { | ||
return html` | ||
<section> | ||
<h3>3 variants:</h3> | ||
<oryx-product-variant-selector sku="variant-selector"></oryx-product-variant-selector> | ||
</section> | ||
<section> | ||
<h3>2 variants:</h3> | ||
<oryx-product-variant-selector sku="1"></oryx-product-variant-selector> | ||
</section> | ||
<section> | ||
<h3>Color variants disabled:</h3> | ||
<oryx-product-variant-selector sku="2"></oryx-product-variant-selector> | ||
</section> | ||
`; | ||
} | ||
export const Variations = Template.bind({}); |
63 changes: 63 additions & 0 deletions
63
libs/domain/product/variant-selector/variant-selector.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { fixture } from '@open-wc/testing-helpers'; | ||
import { createInjector, destroyInjector } from '@oryx-frontend/di'; | ||
import { mockProductProviders, MockProductService } from '@oryx-frontend/product/mocks'; | ||
import { useComponent } from '@oryx-frontend/utilities'; | ||
import { html } from 'lit'; | ||
import { ProductVariantSelectorComponent } from './variant-selector.component'; | ||
import { productVariantSelectorComponent } from './variant-selector.def'; | ||
import { ProductService } from '@oryx-frontend/product'; | ||
import { ContextService, DefaultContextService } from '@oryx-frontend/core'; | ||
import { beforeEach } from 'vitest'; | ||
|
||
describe('ProductVariantSelectorComponent', () => { | ||
let element: ProductVariantSelectorComponent; | ||
let productService: MockProductService; | ||
|
||
beforeAll(async () => { | ||
await useComponent(productVariantSelectorComponent); | ||
}); | ||
|
||
beforeEach(async () => { | ||
const injector = createInjector({ | ||
providers: [ | ||
{ | ||
provide: ProductService, | ||
useClass: MockProductService | ||
}, | ||
{ | ||
provide: ContextService, | ||
useClass: DefaultContextService, | ||
}, | ||
], | ||
}); | ||
|
||
productService = injector.inject<MockProductService>(ProductService); | ||
|
||
|
||
}); | ||
|
||
afterEach(() => { | ||
destroyInjector(); | ||
}); | ||
|
||
describe('when the component is created', () => { | ||
beforeEach(async () => { | ||
element = await fixture( | ||
html` | ||
<oryx-product-variant-selector sku="variant-selector"></oryx-product-variant-selector>` | ||
); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(element).toBeInstanceOf(ProductVariantSelectorComponent); | ||
}); | ||
|
||
it('passes the a11y audit', async () => { | ||
expect(element).shadowDom.to.be.accessible(); | ||
}); | ||
|
||
it('should render a toggle variants', () => { | ||
expect(element).toContainElement('oryx-toggle-icon'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters