Skip to content

Commit

Permalink
Merge pull request #476 from georgetown-cset/test-coverage
Browse files Browse the repository at this point in the history
Increase test coverage
  • Loading branch information
jmelot authored Sep 11, 2023
2 parents 88a3400 + 7ba766a commit 93ddfa1
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 6 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/*
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
"root": true
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ coverage/*.xml

Pipfile
Pipfile.lock

# Test output files
tests/N1.mdx
tests/N2.mdx
tests/S1.mdx
tests/provision.js
14 changes: 9 additions & 5 deletions scripts/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@


class Preprocess:
def __init__(self, args, is_test=False):
def __init__(self, args, is_test=False): # pragma: no cover
self.node_to_meta = {}
self.provider_to_meta = {}
self.variants = {}
Expand Down Expand Up @@ -185,7 +185,7 @@ def generate_graph(self, lines: iter) -> tuple:
self.node_to_meta[child][node_type].append(parent)
return graph, graph_reverse

def write_graphs(self, sequence: str, output_dir: str) -> None:
def write_graphs(self, sequence: str, output_dir: str) -> None: # pragma: no cover
"""
Parses a csv that specifies node type, the edges between nodes, and node variants
:param sequence: sequence csv
Expand Down Expand Up @@ -425,7 +425,9 @@ def _get_node_to_country_provision(self):
node_to_country_provision[node]["all_names"].sort()
return node_to_country_provision

def _get_country_provision_graph(self, graph, output_dir, node_id):
def _get_country_provision_graph(
self, graph, output_dir, node_id
): # pragma: no cover
"""
Generate a graph representing country provisions for a node
:return: A dictionary representation of a graph
Expand Down Expand Up @@ -544,7 +546,9 @@ def _mk_pdf_for_node(
{"enable-local-file-access": None},
)

def mk_pdfs(self, nodes_fi: str, stages_fi: str, output_dir: str) -> None:
def mk_pdfs(
self, nodes_fi: str, stages_fi: str, output_dir: str
) -> None: # pragma: no cover
"""
Generate pdf version of the each node's description
:param nodes_fi: CSV file with node information
Expand Down Expand Up @@ -631,7 +635,7 @@ def write_provider_bq_table(self, provider_fi: str):
writer.writerow(line)
return provider_bq_fi

def write_to_bq(self, nodes_fi, provider_bq_fi):
def write_to_bq(self, nodes_fi, provider_bq_fi): # pragma: no cover
"""
Load CSVs to bigquery tables, overwriting the existing tables.
Also loads the CSVs to versioned backup tables.
Expand Down
3 changes: 2 additions & 1 deletion supply-chain/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
"globals": {
__PATH_PREFIX__: true,
"fetchMock": true,
},
"env": {
"browser": true,
Expand All @@ -12,6 +13,6 @@ module.exports = {
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
"sourceType": "module",
},
}
1 change: 1 addition & 0 deletions supply-chain/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
collectCoverage: true,
collectCoverageFrom: [
'src/**/*.{js,jsx}',
'!src/pages/*',
'!**/__tests__/**',
],
// TBD - we have not decided on these yet
Expand Down
31 changes: 31 additions & 0 deletions supply-chain/src/components/__tests__/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ describe("Gradient Legend", () => {
});

describe("Dashboard", () => {
beforeEach(() => {
window.HTMLElement.prototype.scrollIntoView = function() {};
const location = {
...window.location,
search: '',
};
Object.defineProperty(window, 'location', {
writable: true,
value: location,
});
})

it("renders correctly", () => {
const {asFragment} = render(<Dashboard/>);
expect(asFragment()).toMatchSnapshot();
Expand Down Expand Up @@ -64,6 +76,25 @@ describe("Dashboard", () => {
expect(screen.getAllByText("Crystal growing furnaces").length).toEqual(1);
});

it("opens a documentation node with variants and subvariants", () => {
render(<Dashboard/>);
// Click on a node with subvariants
fireEvent.click(screen.getByText("Deposition tools"));
fireEvent.click(screen.getAllByText("Chemical vapor deposition tools")[0]);

// Show subvariants list
expect(screen.getAllByText("Atomic layer deposition tools").length).toEqual(5);
});

it("opens a stage node", () => {
render(<Dashboard/>);
// Click on a stage node title
fireEvent.click(screen.getByText("Fabrication"));

// Show stage node text
expect(screen.getByText("at the 45 nm node or below", {exact: false})).not.toBeNull();
});

it("changes the highlighting shown", () => {
render(<Dashboard/>);
// Initially, the nodes are not highlighted
Expand Down
3 changes: 3 additions & 0 deletions tests/test_N1.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### Logic chip design: Advanced CPUs

Central processing units ("CPUs") are the dominant general purpose logic chips. Two U.S. firms, Intel and AMD, have long held a duopoly over CPUs used for laptops, desktops, and servers. (China has several ventures, though none are competitive with U.S. firms.) CPUs are often classified into "nodes," which represent technology generations: a chip at a new node (e.g., "5 nm‚" released in 2020) contains approximately double the transistor density as a previous node (e.g., "7 nm‚" released in 2018) and is also more cost-effective.
18 changes: 18 additions & 0 deletions tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_mk_metadata(self):
def test_mk_provider_to_meta(self):
self.maxDiff = None
provider_fi = "./tests/test_providers.csv"
provision_fi = "./tests/test_provision.csv"
pp = Preprocess(None, True)
pp.mk_provider_to_meta(provider_fi)
self.assertEqual(
Expand Down Expand Up @@ -92,6 +93,12 @@ def test_mk_provider_to_meta(self):
},
},
)
pp.write_provision(provision_fi, "tests/")

output_truth = open("tests/test_provision.js").read()
output_testing = open("tests/provision.js").read()

self.assertEqual(output_testing, output_truth)

def test_get_flag(self):
self.assertEqual("🇺🇸", Preprocess.get_flag("USA"))
Expand Down Expand Up @@ -319,3 +326,14 @@ def test_clean_md_link(self):
"Flickr user [FritzchensFritz](https://www.flickr.com/photos/130561288@N04/50914099198/)"
),
)

def test_write_descriptions(self):
pp = Preprocess(None, True)
pp.write_descriptions(
"./tests/test_input.csv", "./tests/test_stages.csv", "tests/"
)

output_truth = open("tests/test_N1.mdx").read().strip()
output_testing = open("tests/N1.mdx").read().strip()

self.assertEqual(output_testing, output_truth)
3 changes: 3 additions & 0 deletions tests/test_provision.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider_name,provider_id,provided_name,provided_id,share_provided,negligible_market_share
USA,P1,Design,S1,61%,
USA,P1,Fabrication,S2,27%,
8 changes: 8 additions & 0 deletions tests/test_provision.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const countryProvision={"United States": {"S1": 61, "S2": 27}};
const countryFlags={"United States": "\ud83c\uddfa\ud83c\uddf8"};
const countryProvisionConcentration={"S1": 1, "S2": 1};
const orgProvision={};
const processNodesWithOrgProvision=[];
const providerMeta={"P1": {"name": "USA", "type": "country"}, "P2": {"name": "CHN", "type": "country"}, "P4": {"name": "KOR", "type": "country"}, "P9": {"name": "Intel", "type": "organization", "hq_flag": "\ud83c\uddfa\ud83c\uddf8", "hq_country": "United States"}, "P10": {"name": "AMD", "type": "organization", "hq_flag": "\ud83c\uddfa\ud83c\uddf8", "hq_country": "United States"}, "P15": {"name": "Phytium", "type": "organization", "hq_flag": "\ud83c\udde8\ud83c\uddf3", "hq_country": "China (mainland)"}};

export {countryProvision, countryFlags, countryProvisionConcentration, orgProvision, processNodesWithOrgProvision, providerMeta};

0 comments on commit 93ddfa1

Please sign in to comment.