Skip to content

Commit

Permalink
Merge pull request #157 from manifoldco/drosati/add-latest-version-to…
Browse files Browse the repository at this point in the history
…-plan-componenet

add version attribute with latest value for latest product/plan verisons
  • Loading branch information
domenicrosati authored Apr 17, 2020
2 parents ffb6edb + 2e7c877 commit 275bcec
Show file tree
Hide file tree
Showing 9 changed files with 715 additions and 553 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Changed

- Firing a CTAClick event when CTA is clicked
- Add version attribute to get latest product and plan versions (currently only works with "latest" value).

## [0.2.0] - 2020-04-01

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Options are passed to the component in the form of HTML Attributes:
| `client-id` | Y | Your Account identifier (this helps us associate analytics to your account) | `<manifold-plan-table client-id="284ablb7scfm8oxwz9wrxpt2q0jii">` |
| `base-url` | | The URL the buttons link to (plan ID & user selection will be appended to the end of the URL in a query string) | `<manifold-plan-table base-url="/checkout">` |
| `cta-text` | | Change the ”Getting Started” default text. | `<manifold-plan-table cta-text="Buy Now!">` |
| `version` | | The version of your product (omit for latest published product). Use `version="latest"` for the latest draft. | `<manifold-plan-table version="1">` |

## TypeScript + JSX

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@storybook/addon-knobs": "^5.3.17",
"@storybook/addons": "^5.3.17",
"@storybook/html": "^5.3.17",
"@types/jest": "24.0.25",
"@types/jest": "24.9.1",
"@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/parser": "^2.20.0",
"babel-loader": "^8.0.6",
Expand Down
4 changes: 3 additions & 1 deletion src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export namespace Components {
"env"?: "stage" | "local" | "prod";
"gatewayUrl"?: string;
"productId"?: string;
"version"?: string;
}
}
declare global {
Expand All @@ -33,8 +34,9 @@ declare namespace LocalJSX {
"ctaText"?: string;
"env"?: "stage" | "local" | "prod";
"gatewayUrl"?: string;
"onCtaClick"?: (event: CustomEvent<any>) => void;
"onCTAClick"?: (event: CustomEvent<any>) => void;
"productId"?: string;
"version"?: string;
}
interface IntrinsicElements {
"manifold-plan-table": ManifoldPlanTable;
Expand Down
16 changes: 16 additions & 0 deletions src/components/manifold-plan-table/manifold-plan-table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Props {
clientId?: string;
baseUrl?: string;
ctaText?: string;
version?: string;
}

async function setup(props: Props) {
Expand All @@ -27,6 +28,7 @@ async function setup(props: Props) {

component.productId = props.productId;
component.clientId = props.clientId;
component.version = props.version;

const root = page.root as HTMLDivElement;
root.appendChild(component);
Expand Down Expand Up @@ -70,6 +72,20 @@ describe(ManifoldPlanTable.name, () => {
});
afterEach(fetchMock.restore);

it('[version]: when latest is provided it is a latest query', async () => {
fetchMock.mock(GRAPHQL_ENDPOINT, mockJawsDB);
await setup({ productId: 'product-id', clientId: 'client-id', version: 'latest' });
const options = fetchMock.lastOptions();
expect(options.body).toContain('"latest":true');
});

it('[version]: when version is provided it is not a latest query', async () => {
fetchMock.mock(GRAPHQL_ENDPOINT, mockJawsDB);
await setup({ productId: 'product-id', clientId: 'client-id', version: '1' });
const options = fetchMock.lastOptions();
expect(options.body).toContain('"latest":false');
});

it('cta URL', async () => {
// mock jawsDB endpoint
fetchMock.mock(GRAPHQL_ENDPOINT, mockJawsDB);
Expand Down
9 changes: 8 additions & 1 deletion src/components/manifold-plan-table/manifold-plan-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import PlanCost from './plan-cost';
import SkeletonLoader from './skeleton';
import query from './product.graphql';

const LATEST_VERSION_FLAG = 'latest';

// query types
type ProductFixed = ProductQuery['product']['fixedFeatures']['edges'][0]['node'];
type ProductMetered = ProductQuery['product']['meteredFeatures']['edges'][0]['node'];
Expand Down Expand Up @@ -64,6 +66,8 @@ export class ManifoldPlanTable {
// CTA Text for buttons
@Prop() ctaText?: string = 'Get Started';
@Prop() env?: 'stage' | 'local' | 'prod' = 'stage';
// Version label for specifiying which verison of product to display.
@Prop() version?: string;
// Product data
@State() product?: ProductQuery['product'];
// Product features
Expand Down Expand Up @@ -102,7 +106,10 @@ export class ManifoldPlanTable {

// trying to move fetch out for testing.
async setupProduct(productID: string) {
const variables: ProductQueryVariables = { id: productID };
const variables: ProductQueryVariables = {
id: productID,
latest: this.version === LATEST_VERSION_FLAG,
};
const res = await this.connection.graphqlFetch<ProductQuery>({ query, variables });
const { data } = res;

Expand Down
4 changes: 2 additions & 2 deletions src/components/manifold-plan-table/product.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query PRODUCT($id: ID!) {
product(id: $id) {
query PRODUCT($id: ID!, $latest: Boolean) {
product(id: $id, latest: $latest) {
id
displayName
fixedFeatures(first: 25) {
Expand Down
Loading

0 comments on commit 275bcec

Please sign in to comment.